@@ -40,14 +40,14 @@ public class Generator {
4040 private static final String LINE_SEPARATOR = System .getProperty ("line.separator" );
4141
4242 private static final String AUTO_GENERATED_FILE_PROLOGUE =
43- "/* AUTO-GENERATED FILE. DO NOT MODIFY." + LINE_SEPARATOR +
44- " * This class was automatically generated by the" + LINE_SEPARATOR +
45- " * static binding generator from the resources it found." + LINE_SEPARATOR +
46- " * Please do not modify by hand." + LINE_SEPARATOR +
47- " */" + LINE_SEPARATOR ;
43+ "/* AUTO-GENERATED FILE. DO NOT MODIFY." + LINE_SEPARATOR +
44+ " * This class was automatically generated by the" + LINE_SEPARATOR +
45+ " * static binding generator from the resources it found." + LINE_SEPARATOR +
46+ " * Please do not modify by hand." + LINE_SEPARATOR +
47+ " */" + LINE_SEPARATOR ;
4848
4949 private final File outputDir ;
50- private final List <DataRow > libs ;
50+ private final List <DataRow > libs ;
5151 private final Map <String , JavaClass > classes ;
5252 private final boolean suppressCallJSMethodExceptions ;
5353
@@ -213,7 +213,7 @@ private String getNormalizedName(String filename) {
213213 return sb .toString ();
214214 }
215215
216- private Map <String , MethodGroup > getPublicApi (JavaClass clazz ) throws ClassNotFoundException {
216+ private Map <String , MethodGroup > getPublicApi (JavaClass clazz , List < String > userImplementedInterfacesNames ) throws ClassNotFoundException {
217217 Map <String , MethodGroup > api = new HashMap <String , MethodGroup >();
218218 JavaClass currentClass = clazz ;
219219 String clazzName = clazz .getClassName ();
@@ -225,7 +225,7 @@ private Map<String, MethodGroup> getPublicApi(JavaClass clazz) throws ClassNotFo
225225 methods .add (m );
226226 }
227227
228- collectInterfaceMethods (clazz , methods );
228+ collectInterfaceMethods (clazz , userImplementedInterfacesNames , methods );
229229 for (Method m : methods ) {
230230 if (!m .isSynthetic () && (m .isPublic () || m .isProtected ()) && !m .isStatic ()) {
231231 String name = m .getName ();
@@ -303,7 +303,7 @@ private Map<String, JavaClass> readDir(String path, boolean throwOnError) throws
303303 while (!d .isEmpty ()) {
304304 File cur = d .pollFirst ();
305305 File [] files = cur .listFiles ();
306- for (File f : files ) {
306+ for (File f : files ) {
307307 if (f .isFile () && f .getName ().endsWith (CLASS_EXT )) {
308308 ClassParser cp = new ClassParser (f .getAbsolutePath ());
309309 JavaClass clazz = cp .parse ();
@@ -338,9 +338,8 @@ private String getFullMethodSignature(Method m) {
338338
339339 private void writeBinding (Writer w , DataRow dataRow , JavaClass clazz , String packageName , String name ) throws ClassNotFoundException {
340340 String [] implInterfaces = dataRow .getInterfaces ();
341- collectImplementedInterfaces (implInterfaces , clazz );
342341
343- Map <String , MethodGroup > api = getPublicApi (clazz );
342+ Map <String , MethodGroup > api = getPublicApi (clazz , Arrays . asList ( dataRow . getInterfaces ()) );
344343
345344 w .writeln ("package " + packageName + ";" );
346345 w .writeln ();
@@ -404,7 +403,7 @@ private void writeBinding(Writer w, DataRow dataRow, JavaClass clazz, String pac
404403 }
405404 Set <Method > notImplementedObjectMethods = new HashSet <Method >();
406405 Method [] currentIfaceMethods = clazz .getMethods ();
407- ArrayList <Method > ifaceMethods = new ArrayList < Method >();
406+ Set <Method > ifaceMethods = new HashSet < >();
408407 for (Method m : currentIfaceMethods ) {
409408 if (!m .getName ().equals ("<clinit>" )) {
410409 ifaceMethods .add (m );
@@ -446,7 +445,7 @@ private void writeBinding(Writer w, DataRow dataRow, JavaClass clazz, String pac
446445 }
447446 } else {
448447 List <Method > interfaceMethods = new ArrayList <Method >();
449- collectInterfaceMethods (clazz , interfaceMethods );
448+ collectInterfaceMethods (clazz , Arrays . asList ( dataRow . getInterfaces ()), interfaceMethods );
450449 for (String methodName : dataRow .getMethods ()) {
451450 if (api .containsKey (methodName )) {
452451 List <Method > methodGroup = api .get (methodName ).getList ();
@@ -481,8 +480,8 @@ private void writeBinding(Writer w, DataRow dataRow, JavaClass clazz, String pac
481480 private boolean isClassApplication (JavaClass clazz ) {
482481 String className = clazz .getClassName ();
483482 return className .equals ("android.app.Application" ) ||
484- className .equals ("android.support.multidex.MultiDexApplication" ) ||
485- className .equals ("android.test.mock.MockApplication" );
483+ className .equals ("android.support.multidex.MultiDexApplication" ) ||
484+ className .equals ("android.test.mock.MockApplication" );
486485 }
487486
488487 private void writeMethodBody (Method m , Writer w , boolean isApplicationClass , boolean isActivityClass , boolean isInterfaceMethod ) {
@@ -643,7 +642,7 @@ private void writeMethodBody(Method m, boolean isConstructor, boolean isApplicat
643642 w .write ("\t \t " );
644643 Type ret = m .getReturnType ();
645644
646- if (this .suppressCallJSMethodExceptions ) {
645+ if (this .suppressCallJSMethodExceptions ) {
647646 w .writeln ("try {" );
648647 w .write ("\t \t \t " );
649648 }
@@ -659,7 +658,7 @@ private void writeMethodBody(Method m, boolean isConstructor, boolean isApplicat
659658 writeType (ret , w );
660659 w .writeln (".class, args);" );
661660
662- if (this .suppressCallJSMethodExceptions ) {
661+ if (this .suppressCallJSMethodExceptions ) {
663662 w .writeln ("\t \t } catch (Throwable t) {" );
664663 w .writeln ("\t \t \t android.util.Log.w(\" Error\" , t);" );
665664 if (!ret .equals (Type .VOID )) {
@@ -688,7 +687,7 @@ private void writeType(Type t, Writer w) {
688687 w .write (type );
689688 }
690689
691- private void collectInterfaceMethods (JavaClass clazz , List <Method > methods ) throws ClassNotFoundException {
690+ private void collectInterfaceMethods (JavaClass clazz , List <String > userImplementedInterfacesNames , List < Method > methods ) throws ClassNotFoundException {
692691 JavaClass currentClass = clazz ;
693692
694693 while (true ) {
@@ -699,6 +698,12 @@ private void collectInterfaceMethods(JavaClass clazz, List<Method> methods) thro
699698 queue .add (name );
700699 }
701700
701+ for (String userImplementedInterfaceName : userImplementedInterfacesNames ) {
702+ if (userImplementedInterfaceName != null && !userImplementedInterfaceName .equals ("" )) {
703+ queue .add (userImplementedInterfaceName );
704+ }
705+ }
706+
702707 while (!queue .isEmpty ()) {
703708 String ifaceName = queue .poll ();
704709 JavaClass currentInterface = getClass (ifaceName );
@@ -754,7 +759,7 @@ private boolean isActivityClass(JavaClass clazz, Map<String, JavaClass> classes)
754759 while (true ) {
755760 String currentClassname = currentClass .getClassName ();
756761
757- for (String activityClassName : activityClassNames ) {
762+ for (String activityClassName : activityClassNames ) {
758763 isActivityClass = currentClassname .equals (activityClassName );
759764 if (isActivityClass ) {
760765 return true ;
@@ -825,7 +830,7 @@ private void cleanPreviouslyAutoGeneratedFiles(File folder) {
825830 // some javascript files containing native extends are removed,
826831 // their corresponding java classes will also be removed.
827832 File [] files = folder .listFiles ();
828- for (File file : files ) {
833+ for (File file : files ) {
829834 if (file .isDirectory ()) {
830835 this .cleanPreviouslyAutoGeneratedFiles (file );
831836 } else if ("java" .equalsIgnoreCase (this .getFileExtension (file .toString ()))) {
@@ -868,4 +873,4 @@ private String readFile(File file) {
868873 }
869874 }
870875 }
871- }
876+ }
0 commit comments