@@ -199,34 +199,36 @@ public void generateProxy(ApplicationWriter aw, String proxyName, ClassDescripto
199
199
String methodOverride = methodOverrides [i ];
200
200
methodOverridesSet .add (methodOverride );
201
201
}
202
- generateProxy (aw , proxyName , classTo , methodOverridesSet );
203
- }
204
202
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
+
208
210
for (int i = 0 ; i < methodOverrides .length ; i ++)
209
211
{
210
212
String methodOverride = methodOverrides [i ];
211
213
methodOverridesSet .add (methodOverride );
212
214
}
213
- generateProxy (aw , "0" , classTo , methodOverridesSet );
215
+
216
+ generateProxy (aw , "0" , classTo , methodOverridesSet , null );
214
217
}
215
218
216
219
public void generateProxy (ApplicationWriter aw , String proxyName , ClassDescriptor classTo )
217
220
{
218
- generateProxy (aw , proxyName , classTo , null );
221
+ generateProxy (aw , proxyName , classTo , null , null );
219
222
}
220
223
221
224
public void generateProxy (ApplicationWriter aw , ClassDescriptor classTo )
222
225
{
223
- generateProxy (aw , "0" , classTo , null );
224
- }
226
+ generateProxy (aw , "0" , classTo , null , null );
227
+ }
225
228
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 )
227
230
{
228
231
String classSignature = getAsmDescriptor (classTo );
229
- //String methodSignature = org.objectweb.asm.Type.getMethodDescriptor(Object.class.getMethods()[0]);
230
232
231
233
String tnsClassSignature = LCOM_TNS +
232
234
classSignature .substring (1 , classSignature .length () - 1 ).replace ("$" , "_" );
@@ -237,8 +239,8 @@ public void generateProxy(ApplicationWriter aw, String proxyName, ClassDescripto
237
239
238
240
tnsClassSignature += ";" ;
239
241
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 );
242
244
243
245
methods = groupMethodsByNameAndSignature (methods );
244
246
@@ -332,12 +334,17 @@ private void collectInterfaceMethods(ClassDescriptor clazz, HashSet<String> meth
332
334
}
333
335
}
334
336
335
- private MethodDescriptor [] getSupportedMethods (ClassDescriptor clazz , HashSet <String > methodOverrides )
337
+ private MethodDescriptor [] getSupportedMethods (ClassDescriptor clazz , HashSet <String > methodOverrides , HashSet < ClassDescriptor > interfacesToImplement )
336
338
{
337
339
ArrayList <MethodDescriptor > result = new ArrayList <MethodDescriptor >();
338
340
339
341
collectInterfaceMethods (clazz , methodOverrides , result );
340
342
343
+ for (ClassDescriptor iface : interfacesToImplement )
344
+ {
345
+ collectInterfaceMethods (iface , methodOverrides , result );
346
+ }
347
+
341
348
if (!clazz .isInterface ())
342
349
{
343
350
HashMap <String , MethodDescriptor > finalMethods = new HashMap <String , MethodDescriptor >();
@@ -601,13 +608,13 @@ private void generateHashCodeSuper(ClassVisitor cv)
601
608
602
609
private void generateMethod (ClassVisitor cv , ClassDescriptor classTo , MethodDescriptor method , int methodNumber , String classSignature , String tnsClassSignature , int fieldBit )
603
610
{
604
- if (ProxyGenerator .IsLogEnabled ) Log .d ("Generator" , "generatingMethod " + method .getName ());
611
+ if (ProxyGenerator .IsLogEnabled ) {
612
+ Log .d ("Generator" , "generatingMethod " + method .getName ());
613
+ }
605
614
606
615
//TODO: handle checked exceptions
607
616
String methodDexSignature = getDexMethodDescriptor (method );
608
617
String [] exceptions = new String [0 ];
609
-
610
-
611
618
MethodVisitor mv ;
612
619
int methodModifiers = getDexModifiers (method );
613
620
@@ -620,6 +627,7 @@ private void generateMethod(ClassVisitor cv, ClassDescriptor classTo, MethodDesc
620
627
{
621
628
generateInitializedBlock (mv , thisRegister , classSignature , tnsClassSignature );
622
629
}
630
+
623
631
generateCallOverrideBlock (mv , method , thisRegister , classSignature , tnsClassSignature , methodDexSignature , fieldBit );
624
632
625
633
mv .visitEnd ();
@@ -919,25 +927,39 @@ private void generateInitializedField(ClassVisitor cv)
919
927
920
928
static final String [] classImplentedInterfaces = new String [] { "Lcom/tns/NativeScriptHashCodeProvider;" };
921
929
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 )
923
932
{
924
933
ClassVisitor cv ;
925
934
926
935
int classModifiers = getDexModifiers (classTo );
927
- String [] implentedInterfaces = classImplentedInterfaces ;
936
+ ArrayList <String > interfacesToImplement = new ArrayList (Arrays .asList (classImplentedInterfaces ));
937
+
928
938
if (classTo .isInterface ())
929
939
{
930
940
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
+
932
947
classSignature = objectClass ;
933
948
}
934
949
else
935
950
{
936
- implentedInterfaces = classImplentedInterfaces ;
951
+ if (implementedInterfaces != null ) {
952
+ for (ClassDescriptor interfaceToImpl : implementedInterfaces ) {
953
+ interfacesToImplement .add (getAsmDescriptor (interfaceToImpl ));
954
+ }
955
+ }
937
956
}
938
957
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 );
941
963
cv .visitSource (classTo .getName () + ".java" , null );
942
964
return cv ;
943
965
}
0 commit comments