private static Collection < JsiiOverride > discoverOverrides ( final Class < ? > classToInspect ) { Map < String , JsiiOverride > overrides = new HashMap <> ( ) ; Class < ? > klass = classToInspect ; // if we reached a generated jsii class or Object, we should stop collecting those overrides since // all the rest of the hierarchy is generated all the way up to JsiiObject and java.lang.Object. while ( klass != null && klass . getDeclaredAnnotationsByType ( Jsii . class ) . length == 0 && klass != Object . class ) { // add all the methods in the current class for ( Method method : klass . getDeclaredMethods ( ) ) { if ( Modifier . isPrivate ( method . getModifiers ( ) ) ) { continue ; } String methodName = method . getName ( ) ; // check if this is a property ("getXXX" or "setXXX", oh java!) if ( isJavaPropertyMethod ( methodName ) ) { String propertyName = javaPropertyToJSProperty ( methodName ) ; // skip if this property is already in the overrides list if ( overrides . containsKey ( propertyName ) ) { continue ; } JsiiOverride override = new JsiiOverride ( ) ; override . setProperty ( propertyName ) ; overrides . put ( propertyName , override ) ; } else { // if this method is already overridden, skip it if ( overrides . containsKey ( methodName ) ) { continue ; } // we use the method's .toString() as a cookie, which will later be used to identify the // method when it is called back. JsiiOverride override = new JsiiOverride ( ) ; override . setMethod ( methodName ) ; override . setCookie ( method . toString ( ) ) ; overrides . put ( methodName , override ) ; } } klass = klass . getSuperclass ( ) ; } return overrides . values ( ) ; }
Prepare a list of methods which are overridden by Java classes .