Skip to content

Commit

Permalink
Fix regression from e48ca1e7
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidi Mohamed EL AATIFI committed Feb 23, 2019
1 parent fdb728e commit c1feed9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/ma/glasnost/orika/MappingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class MappingContext {
* @param globalProperties
*/
public MappingContext(Map<Object, Object> globalProperties) {
this.mapping = new HashMap<Type<?>, Type<?>>();
this.mapping = new HashMap<>();
this.typeCache = new OpenIntObjectHashMap();
this.globalProperties = globalProperties;
Boolean capture =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,24 +314,24 @@ public boolean put(int key, Object value) {
* mark or falls below the low water mark.
*/
protected void rehash(int newCapacity) {

int oldCapacity = table.length;
// if (oldCapacity == newCapacity) return;
this.highWaterMark = chooseHighWaterMark(newCapacity, this.maxLoadFactor);
int[] oldTable = table;
Object[] oldValues = values;
byte[] oldState = state;

int[] newTable = new int[newCapacity];
Object[] newValues = new Object[newCapacity];
byte[] newState = new byte[newCapacity];
int oldTable[] = table;
Object oldValues[] = values;
byte oldState[] = state;

int newTable[] = new int[newCapacity];
Object newValues[] = new Object[newCapacity];
byte newState[] = new byte[newCapacity];

this.highWaterMark = chooseHighWaterMark(newCapacity, this.maxLoadFactor);

this.table = newTable;
this.values = newValues;
this.state = newState;
this.freeEntries = newCapacity - this.distinct; // delta

int oldCapacity = table.length;

for (int i = oldCapacity; i-- > 0; ) {
if (oldState[i] == FULL) {
int element = oldTable[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package ma.glasnost.orika.impl.generator;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -88,6 +90,8 @@ public static Class<?> toClass(Class<?> neighbor, byte[] bcode) {
public Class<?> compileClass(SourceCodeContext sourceCode) throws SourceCodeGenerationException {
Scanner scanner;
try {
writeSourceFile(sourceCode);

scanner = new Scanner(sourceCode.getClassName(), new StringReader(sourceCode.toSourceFile()));
Java.CompilationUnit localCompilationUnit = new Parser(scanner).parseCompilationUnit();
UnitCompiler unitCompile = new UnitCompiler(localCompilationUnit, iClassLoader);
Expand Down Expand Up @@ -153,6 +157,26 @@ public void assureTypeIsAccessible(Class<?> type) throws SourceCodeGenerationExc
}
}

/**
* Produces the requested source file for debugging purposes.
*
* @throws IOException
*/
protected void writeSourceFile(SourceCodeContext sourceCode) throws IOException {
if (writeSourceFiles) {
File parentDir = preparePackageOutputPath(this.pathToWriteSourceFiles, sourceCode.getPackageName());
File sourceFile = new File(parentDir, sourceCode.getClassSimpleName() + ".java");
if (!sourceFile.exists() && !sourceFile.createNewFile()) {
throw new IOException("Could not write source file for " + sourceCode.getClassName());
}

try (FileWriter fw = new FileWriter(sourceFile)) {
fw.append(sourceCode.toSourceFile());
LOG.debug("Source file written to {}", sourceFile);
}
}
}

private static class AggregatedClassLoader extends ClassLoader {

private final SafeClassLoaderSet individualClassLoaders;
Expand Down Expand Up @@ -274,4 +298,6 @@ public void remove() {
}
}
}


}

0 comments on commit c1feed9

Please sign in to comment.