Skip to content

Commit

Permalink
FIX issue jOOQ#73
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmiguel.bonilla committed Nov 28, 2018
1 parent 330f98a commit 34f2379
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 49 deletions.
4 changes: 3 additions & 1 deletion jOOR-java-8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
<maxmem>512m</maxmem>
<meminitial>256m</meminitial>
<encoding>UTF-8</encoding>
<release>8</release>
<!--<release>8</release>-->
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
Expand Down
52 changes: 10 additions & 42 deletions jOOR-java-8/src/main/java/org/joor/Compile.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@
class Compile {

static Class<?> compile(String className, String content, CompileOptions compileOptions) {

Lookup lookup = MethodHandles.lookup();
ClassLoader cl = lookup.lookupClass().getClassLoader();
ClassLoader classLoader = lookup.lookupClass().getClassLoader();

return compile(className, content, compileOptions, classLoader);
}

static Class<?> compile(String className, String content, CompileOptions compileOptions, ClassLoader cl) {

try {
return cl.loadClass(className);
Expand Down Expand Up @@ -101,44 +107,6 @@ static Class<?> compile(String className, String content, CompileOptions compile
result = Reflect.on(cl).call("defineClass", className, b, 0, b.length).get();
}







































return result;
}
catch (ReflectException e) {
Expand All @@ -153,7 +121,7 @@ static Class<?> compile(String className, String content, CompileOptions compile
static final class JavaFileObject extends SimpleJavaFileObject {
final ByteArrayOutputStream os = new ByteArrayOutputStream();

JavaFileObject(String name, JavaFileObject.Kind kind) {
JavaFileObject(String name, Kind kind) {
super(URI.create("string:///" + name.replace('.', '/') + kind.extension), kind);
}

Expand All @@ -176,7 +144,7 @@ static final class ClassFileManager extends ForwardingJavaFileManager<StandardJa

@Override
public JavaFileObject getJavaFileForOutput(
JavaFileManager.Location location,
Location location,
String className,
JavaFileObject.Kind kind,
FileObject sibling
Expand All @@ -189,7 +157,7 @@ static final class CharSequenceJavaFileObject extends SimpleJavaFileObject {
final CharSequence content;

public CharSequenceJavaFileObject(String className, CharSequence content) {
super(URI.create("string:///" + className.replace('.', '/') + JavaFileObject.Kind.SOURCE.extension), JavaFileObject.Kind.SOURCE);
super(URI.create("string:///" + className.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
this.content = content;
}

Expand Down
37 changes: 31 additions & 6 deletions jOOR-java-8/src/main/java/org/joor/Reflect.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public static Reflect compile(String name, String content) throws ReflectExcepti
return compile(name, content, new CompileOptions());
}

/**
* Compile a class at runtime and reflect on it.
* <p>
*
* @param name The qualified class name
* @param content The source code for the class
* @param classLoader The classloader used to compile
* @return A wrapped {@link Class}
* @throws ReflectException if anything went wrong compiling the class.
*/
public static Reflect compile(String name, String content, ClassLoader classLoader) throws ReflectException {
return compile(name, content, new CompileOptions(), classLoader);
}

/**
* Compile a class at runtime and reflect on it.
* <p>
Expand All @@ -101,6 +115,22 @@ public static Reflect compile(String name, String content) throws ReflectExcepti
public static Reflect compile(String name, String content, CompileOptions options) throws ReflectException {
return on(Compile.compile(name, content, options));
}

/**
* Compile a class at runtime and reflect on it.
* <p>
*
* @param name The qualified class name
* @param content The source code for the class
* @param options compiler options
* @param classLoader The classloader used to compile
* @return A wrapped {@link Class}
* @throws ReflectException if anything went wrong compiling the class.
*/
public static Reflect compile(String name, String content, CompileOptions options, ClassLoader classLoader) throws ReflectException {
return on(Compile.compile(name, content, options, classLoader));
}

/* [/java-8] */

/**
Expand Down Expand Up @@ -238,11 +268,6 @@ public static <T extends AccessibleObject> T accessible(T accessible) {
static {
Constructor<MethodHandles.Lookup> result;






try {
result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);

Expand Down Expand Up @@ -557,7 +582,7 @@ private Method exactMethod(String name, Class<?>[] types) throws NoSuchMethodExc

/**
* Searches a method with a similar signature as desired using
* {@link #isSimilarSignature(java.lang.reflect.Method, String, Class[])}.
* {@link #isSimilarSignature(Method, String, Class[])}.
* <p>
* First public methods are searched in the class hierarchy, then private
* methods on the declaring class. If a method could be found, it is
Expand Down

0 comments on commit 34f2379

Please sign in to comment.