Commit 9d866252 authored by Vít Kabele's avatar Vít Kabele
Browse files

ContextKind discovery using specified classloader.

parent 47493e80
......@@ -81,4 +81,46 @@ public enum ContextKind {
return null;
}
/**
* This (UGLY) method does the same as the single parameter one, but resolves the superclasses
* using provided class loader.
*
* TODO: Definitely needs refactoring.
*
* @param type
* @param classLoader
* @return
*/
public static ContextKind forType(final Type type, final java.lang.ClassLoader classLoader){
if( ContextKind.CLASS.matches (type) ){
return ContextKind.CLASS;
}
else if( ContextKind.ARGUMENT.matches (type) ){
return ContextKind.ARGUMENT;
}
else if( ContextKind.ARGUMENT_PROCESSOR.matches (type)){
return ContextKind.ARGUMENT_PROCESSOR;
}
else if( ContextKind.DYNAMIC.matches (type) ){
return ContextKind.DYNAMIC;
}
else {
Class <?> typeClass = null;
try{
typeClass = Class.forName (type.getClassName (), true, classLoader);
} catch (ClassNotFoundException e){
return null;
}
if (typeClass != null) {
return ReflectionHelper.implementsInterface (typeClass, StaticContext.class) ? ContextKind.STATIC : null;
} else {
return null;
}
}
}
}
......@@ -49,6 +49,11 @@ final class ContextUsage {
//
static ContextUsage forMethod (final MethodNode method) {
return forMethod (method, java.lang.ClassLoader.getSystemClassLoader ());
}
static ContextUsage forMethod(final MethodNode method, final java.lang.ClassLoader classLoader){
//
// Collect the kinds of contexts appearing in the arguments as well as
// the types of static contexts.
......@@ -57,7 +62,7 @@ final class ContextUsage {
final Set <Type> staticContextTypes = new HashSet <Type> ();
for (final Type argType : Type.getArgumentTypes (method.desc)) {
final ContextKind contextKind = ContextKind.forType (argType);
final ContextKind contextKind = ContextKind.forType (argType, classLoader);
if (contextKind != null) {
usedContexts.add (contextKind);
if (contextKind == ContextKind.STATIC) {
......@@ -67,6 +72,7 @@ final class ContextUsage {
}
return new ContextUsage (usedContexts, staticContextTypes);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment