String resolveMember ( ClassFile cf , String startClassName , String findName , String findDesc , boolean resolveMethod , boolean checkStartClass ) throws ConstantPoolException { ClassFile startClass ; if ( cf . getName ( ) . equals ( startClassName ) ) { startClass = cf ; } else { startClass = finder . find ( startClassName ) ; if ( startClass == null ) { errorNoClass ( startClassName ) ; return startClassName ; } } // follow super_class until it's 0, meaning we've reached Object // accumulate interfaces of superclasses as we go along ClassFile curClass = startClass ; Deque < String > intfs = new ArrayDeque <> ( ) ; while ( true ) { if ( ( checkStartClass || curClass != startClass ) && isMemberPresent ( curClass , findName , findDesc , resolveMethod ) ) { break ; } if ( curClass . super_class == 0 ) { // reached Object curClass = null ; break ; } String superName = curClass . getSuperclassName ( ) ; curClass = finder . find ( superName ) ; if ( curClass == null ) { errorNoClass ( superName ) ; break ; } addInterfaces ( intfs , curClass ) ; } // search interfaces: add all interfaces and superinterfaces to queue // search until it's empty if ( curClass == null ) { addInterfaces ( intfs , startClass ) ; while ( intfs . size ( ) > 0 ) { String intf = intfs . removeFirst ( ) ; curClass = finder . find ( intf ) ; if ( curClass == null ) { errorNoClass ( intf ) ; break ; } if ( isMemberPresent ( curClass , findName , findDesc , resolveMethod ) ) { break ; } addInterfaces ( intfs , curClass ) ; } } if ( curClass == null ) { if ( checkStartClass ) { errorNoMethod ( startClassName , findName , findDesc ) ; return startClassName ; } else { // TODO: refactor this // checkStartClass == false means we're checking for overrides // so not being able to resolve a method simply means there's // no overriding, which isn't an error return null ; } } else { String foundClassName = curClass . getName ( ) ; return foundClassName ; } }
Resolves a member by searching this class and all its superclasses and implemented interfaces .