Skip to content

Commit f6aabae

Browse files
author
Mihail Slavchev
committed
fix issue #259
1 parent 0902380 commit f6aabae

3 files changed

Lines changed: 107 additions & 37 deletions

File tree

binding-generator/Generator/src/com/tns/bindings/Dump.java

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -389,65 +389,110 @@ private Method[] groupMethodsByName(Method[] methods)
389389

390390
return result.values().toArray(new Method[result.size()]);
391391
}
392+
393+
private String getMethodSignature(Method m)
394+
{
395+
String sig = m.toGenericString();
396+
397+
int nameIdx = sig.indexOf("(");
398+
int endSigIdx = sig.indexOf(")") + 1;
399+
400+
return m.getName() + sig.substring(nameIdx, endSigIdx);
401+
}
392402

393403
private Method[] getSupportedMethods(Class<?> clazz, HashSet<String> methodOverrides)
394404
{
395405
ArrayList<Method> result = new ArrayList<Method>();
396-
HashMap<String, Method> finalMethods = new HashMap<String, Method>();
397-
ArrayList<Class<?>> implementedInterfaces = new ArrayList<Class<?>>();
398-
while (clazz != null)
406+
407+
if (clazz.isInterface())
399408
{
400-
Method[] methods = clazz.getDeclaredMethods();
401-
402-
ArrayList<Method> methodz = new ArrayList<Method>();
403-
404-
for (int i = 0; i < methods.length; i++)
409+
Set<String> objectMethods = new HashSet<String>();
410+
for (Method objMethod: java.lang.Object.class.getDeclaredMethods())
405411
{
406-
Method candidateMethod = methods[i];
407-
if (methodOverrides != null && !methodOverrides.contains(candidateMethod.getName()))
412+
if (!Modifier.isStatic(objMethod.getModifiers()))
408413
{
409-
continue;
414+
String sig = getMethodSignature(objMethod);
415+
objectMethods.add(sig);
410416
}
411-
412-
methodz.add(methods[i]);
413417
}
414-
415-
416-
Class<?>[] interfaces = clazz.getInterfaces();
417-
for (int i = 0; i < interfaces.length; i++)
418+
Set<Method> notImplementedObjectMethods = new HashSet<Method>();
419+
Method[] ifaceMethods = clazz.getDeclaredMethods();
420+
for (Method ifaceMethod: ifaceMethods)
418421
{
419-
implementedInterfaces.add(interfaces[i]);
422+
if (!Modifier.isStatic(ifaceMethod.getModifiers()))
423+
{
424+
String sig = getMethodSignature(ifaceMethod);
425+
if (objectMethods.contains(sig) && !methodOverrides.contains(ifaceMethod.getName()))
426+
{
427+
notImplementedObjectMethods.add(ifaceMethod);
428+
}
429+
}
420430
}
421-
422-
for (int i = 0; i < methodz.size(); i++)
431+
for (Method ifaceMethod: ifaceMethods)
423432
{
424-
Method method = methodz.get(i);
425-
426-
if (isMethodSupported(method, finalMethods))
433+
if (!notImplementedObjectMethods.contains(ifaceMethod))
427434
{
428-
result.add(method);
435+
result.add(ifaceMethod);
429436
}
430437
}
431-
432-
clazz = clazz.getSuperclass();
433438
}
434-
435-
for (int i = 0; i < implementedInterfaces.size(); i++)
439+
else
436440
{
437-
Class<?> implementedInterface = implementedInterfaces.get(i);
438-
Method[] interfaceMethods = implementedInterface.getMethods();
439-
for (int j = 0; j < interfaceMethods.length; j++)
441+
HashMap<String, Method> finalMethods = new HashMap<String, Method>();
442+
ArrayList<Class<?>> implementedInterfaces = new ArrayList<Class<?>>();
443+
while (clazz != null)
440444
{
441-
Method method = interfaceMethods[j];
445+
Method[] methods = clazz.getDeclaredMethods();
446+
447+
ArrayList<Method> methodz = new ArrayList<Method>();
448+
449+
for (int i = 0; i < methods.length; i++)
450+
{
451+
Method candidateMethod = methods[i];
452+
if (methodOverrides != null && !methodOverrides.contains(candidateMethod.getName()))
453+
{
454+
continue;
455+
}
456+
457+
methodz.add(methods[i]);
458+
}
459+
460+
Class<?>[] interfaces = clazz.getInterfaces();
461+
for (int i = 0; i < interfaces.length; i++)
462+
{
463+
implementedInterfaces.add(interfaces[i]);
464+
}
442465

443-
if (methodOverrides != null && !methodOverrides.contains(method.getName()))
466+
for (int i = 0; i < methodz.size(); i++)
444467
{
445-
continue;
468+
Method method = methodz.get(i);
469+
470+
if (isMethodSupported(method, finalMethods))
471+
{
472+
result.add(method);
473+
}
446474
}
447475

448-
if (!isMethodMarkedAsFinalInClassHierarchy(method, finalMethods))
476+
clazz = clazz.getSuperclass();
477+
}
478+
479+
for (int i = 0; i < implementedInterfaces.size(); i++)
480+
{
481+
Class<?> implementedInterface = implementedInterfaces.get(i);
482+
Method[] interfaceMethods = implementedInterface.getMethods();
483+
for (int j = 0; j < interfaceMethods.length; j++)
449484
{
450-
result.add(method);
485+
Method method = interfaceMethods[j];
486+
487+
if (methodOverrides != null && !methodOverrides.contains(method.getName()))
488+
{
489+
continue;
490+
}
491+
492+
if (!isMethodMarkedAsFinalInClassHierarchy(method, finalMethods))
493+
{
494+
result.add(method);
495+
}
451496
}
452497
}
453498
}
@@ -1158,4 +1203,4 @@ private int getDexModifiers(int modifiers)
11581203

11591204
return org.ow2.asmdex.Opcodes.ACC_PROTECTED;
11601205
}
1161-
}
1206+
}

test-app/assets/app/mainpage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ require("./tests/testNativeModules");
4141
require("./tests/requireExceptionTests");
4242
require("./tests/java-array-test");
4343
require("./tests/field-access-test");
44+
require("./tests/dex-interface-implementation");
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
describe("Tests partial interface implementation", function () {
2+
it("should throw an exception when call unimplemented method of a partial implemented interface", function () {
3+
var exceptionCaught = false;
4+
var m = new java.util.Map({
5+
clear: function() {}
6+
});
7+
try {
8+
m.size()
9+
} catch (e) {
10+
exceptionCaught = true;
11+
}
12+
expect(exceptionCaught).toBe(true);
13+
});
14+
15+
it("should call implemented method of a partial implemented interface", function () {
16+
var m = new java.util.Map({
17+
hashCode: function() {
18+
return 123;
19+
}
20+
});
21+
var hash = m.hashCode();
22+
expect(hash).toBe(123);
23+
});
24+
});

0 commit comments

Comments
 (0)