@@ -199,34 +199,36 @@ public void generateProxy(ApplicationWriter aw, String proxyName, ClassDescripto
199199 String methodOverride = methodOverrides [i ];
200200 methodOverridesSet .add (methodOverride );
201201 }
202- generateProxy (aw , proxyName , classTo , methodOverridesSet );
203- }
204202
205- public void generateProxy (ApplicationWriter aw , ClassDescriptor classTo , String [] methodOverrides , int ignored )
206- {
207- HashSet <String > methodOverridesSet = new HashSet <String >();
203+ generateProxy (aw , proxyName , classTo , methodOverridesSet , null );
204+ }
205+
206+ public void generateProxy (ApplicationWriter aw , ClassDescriptor classTo , String [] methodOverrides , int ignored )
207+ {
208+ HashSet <String > methodOverridesSet = new HashSet <String >();
209+
208210 for (int i = 0 ; i < methodOverrides .length ; i ++)
209211 {
210212 String methodOverride = methodOverrides [i ];
211213 methodOverridesSet .add (methodOverride );
212214 }
213- generateProxy (aw , "0" , classTo , methodOverridesSet );
215+
216+ generateProxy (aw , "0" , classTo , methodOverridesSet , null );
214217 }
215218
216219 public void generateProxy (ApplicationWriter aw , String proxyName , ClassDescriptor classTo )
217220 {
218- generateProxy (aw , proxyName , classTo , null );
221+ generateProxy (aw , proxyName , classTo , null , null );
219222 }
220223
221224 public void generateProxy (ApplicationWriter aw , ClassDescriptor classTo )
222225 {
223- generateProxy (aw , "0" , classTo , null );
224- }
226+ generateProxy (aw , "0" , classTo , null , null );
227+ }
225228
226- public void generateProxy (ApplicationWriter aw , String proxyName , ClassDescriptor classTo , HashSet <String > methodOverrides )
229+ public void generateProxy (ApplicationWriter aw , String proxyName , ClassDescriptor classTo , HashSet <String > methodOverrides , HashSet < ClassDescriptor > implementedInterfaces )
227230 {
228231 String classSignature = getAsmDescriptor (classTo );
229- //String methodSignature = org.objectweb.asm.Type.getMethodDescriptor(Object.class.getMethods()[0]);
230232
231233 String tnsClassSignature = LCOM_TNS +
232234 classSignature .substring (1 , classSignature .length () - 1 ).replace ("$" , "_" );
@@ -237,8 +239,8 @@ public void generateProxy(ApplicationWriter aw, String proxyName, ClassDescripto
237239
238240 tnsClassSignature += ";" ;
239241
240- ClassVisitor cv = generateClass (aw , classTo , classSignature , tnsClassSignature );
241- MethodDescriptor [] methods = getSupportedMethods (classTo , methodOverrides );
242+ ClassVisitor cv = generateClass (aw , classTo , classSignature , tnsClassSignature , implementedInterfaces );
243+ MethodDescriptor [] methods = getSupportedMethods (classTo , methodOverrides , implementedInterfaces );
242244
243245 methods = groupMethodsByNameAndSignature (methods );
244246
@@ -332,12 +334,17 @@ private void collectInterfaceMethods(ClassDescriptor clazz, HashSet<String> meth
332334 }
333335 }
334336
335- private MethodDescriptor [] getSupportedMethods (ClassDescriptor clazz , HashSet <String > methodOverrides )
337+ private MethodDescriptor [] getSupportedMethods (ClassDescriptor clazz , HashSet <String > methodOverrides , HashSet < ClassDescriptor > interfacesToImplement )
336338 {
337339 ArrayList <MethodDescriptor > result = new ArrayList <MethodDescriptor >();
338340
339341 collectInterfaceMethods (clazz , methodOverrides , result );
340342
343+ for (ClassDescriptor iface : interfacesToImplement )
344+ {
345+ collectInterfaceMethods (iface , methodOverrides , result );
346+ }
347+
341348 if (!clazz .isInterface ())
342349 {
343350 HashMap <String , MethodDescriptor > finalMethods = new HashMap <String , MethodDescriptor >();
@@ -601,13 +608,13 @@ private void generateHashCodeSuper(ClassVisitor cv)
601608
602609 private void generateMethod (ClassVisitor cv , ClassDescriptor classTo , MethodDescriptor method , int methodNumber , String classSignature , String tnsClassSignature , int fieldBit )
603610 {
604- if (ProxyGenerator .IsLogEnabled ) Log .d ("Generator" , "generatingMethod " + method .getName ());
611+ if (ProxyGenerator .IsLogEnabled ) {
612+ Log .d ("Generator" , "generatingMethod " + method .getName ());
613+ }
605614
606615 //TODO: handle checked exceptions
607616 String methodDexSignature = getDexMethodDescriptor (method );
608617 String [] exceptions = new String [0 ];
609-
610-
611618 MethodVisitor mv ;
612619 int methodModifiers = getDexModifiers (method );
613620
@@ -620,6 +627,7 @@ private void generateMethod(ClassVisitor cv, ClassDescriptor classTo, MethodDesc
620627 {
621628 generateInitializedBlock (mv , thisRegister , classSignature , tnsClassSignature );
622629 }
630+
623631 generateCallOverrideBlock (mv , method , thisRegister , classSignature , tnsClassSignature , methodDexSignature , fieldBit );
624632
625633 mv .visitEnd ();
@@ -919,25 +927,39 @@ private void generateInitializedField(ClassVisitor cv)
919927
920928 static final String [] classImplentedInterfaces = new String [] { "Lcom/tns/NativeScriptHashCodeProvider;" };
921929 static final String [] interfaceImplementedInterfaces = new String [] { "Lcom/tns/NativeScriptHashCodeProvider;" , "" };
922- private ClassVisitor generateClass (ApplicationWriter aw , ClassDescriptor classTo , String classSignature , String tnsClassSignature )
930+
931+ private ClassVisitor generateClass (ApplicationWriter aw , ClassDescriptor classTo , String classSignature , String tnsClassSignature , HashSet <ClassDescriptor > implementedInterfaces )
923932 {
924933 ClassVisitor cv ;
925934
926935 int classModifiers = getDexModifiers (classTo );
927- String [] implentedInterfaces = classImplentedInterfaces ;
936+ ArrayList <String > interfacesToImplement = new ArrayList (Arrays .asList (classImplentedInterfaces ));
937+
928938 if (classTo .isInterface ())
929939 {
930940 interfaceImplementedInterfaces [1 ] = classSignature ; //new String[] { "Lcom/tns/NativeScriptHashCodeProvider;", classSignature };
931- implentedInterfaces = interfaceImplementedInterfaces ;
941+ for (String interfaceToImpl : interfaceImplementedInterfaces ) {
942+ if (!interfacesToImplement .contains (interfaceToImpl )) {
943+ interfacesToImplement .add (interfaceToImpl );
944+ }
945+ }
946+
932947 classSignature = objectClass ;
933948 }
934949 else
935950 {
936- implentedInterfaces = classImplentedInterfaces ;
951+ if (implementedInterfaces != null ) {
952+ for (ClassDescriptor interfaceToImpl : implementedInterfaces ) {
953+ interfacesToImplement .add (getAsmDescriptor (interfaceToImpl ));
954+ }
955+ }
937956 }
938957
939- cv = aw .visitClass (classModifiers , tnsClassSignature , null , classSignature , implentedInterfaces );
940- cv .visit (0 , classModifiers , tnsClassSignature , null , classSignature , implentedInterfaces );
958+ String [] interfacesToImplementArr = new String [interfacesToImplement .size ()];
959+ interfacesToImplementArr = interfacesToImplement .toArray (interfacesToImplementArr );
960+
961+ cv = aw .visitClass (classModifiers , tnsClassSignature , null , classSignature , interfacesToImplementArr );
962+ cv .visit (0 , classModifiers , tnsClassSignature , null , classSignature , interfacesToImplementArr );
941963 cv .visitSource (classTo .getName () + ".java" , null );
942964 return cv ;
943965 }
0 commit comments