private static LookupResult findByClassLoading ( String name , CompilationUnit compilationUnit , GroovyClassLoader loader ) { Class cls ; try { // NOTE: it's important to do no lookup against script files // here since the GroovyClassLoader would create a new CompilationUnit cls = loader . loadClass ( name , false , true ) ; } catch ( ClassNotFoundException cnfe ) { LookupResult lr = tryAsScript ( name , compilationUnit , null ) ; return lr ; } catch ( CompilationFailedException cfe ) { throw new GroovyBugError ( "The lookup for " + name + " caused a failed compilation. There should not have been any compilation from this call." , cfe ) ; } //TODO: the case of a NoClassDefFoundError needs a bit more research // a simple recompilation is not possible it seems. The current class // we are searching for is there, so we should mark that somehow. // Basically the missing class needs to be completely compiled before // we can again search for the current name. /*catch (NoClassDefFoundError ncdfe) { cachedClasses.put(name,SCRIPT); return false; }*/ if ( cls == null ) return null ; //NOTE: we might return false here even if we found a class, // because we want to give a possible script a chance to // recompile. This can only be done if the loader was not // the instance defining the class. ClassNode cn = ClassHelper . make ( cls ) ; if ( cls . getClassLoader ( ) != loader ) { return tryAsScript ( name , compilationUnit , cn ) ; } return new LookupResult ( null , cn ) ; }
Search for classes using class loading