Skip to content

Commit

Permalink
Make JavaAdapter work with abstract base classes and protected constr…
Browse files Browse the repository at this point in the history
…uctors
  • Loading branch information
hns committed Jun 22, 2012
1 parent 6297a0a commit 69b177c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/org/mozilla/javascript/JavaAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,12 @@ public static byte[] createAdapterCode(ObjToIntMap functionNames,
}

String superName = superClass.getName().replace('.', '/');
Constructor<?>[] ctors = superClass.getConstructors();
Constructor<?>[] ctors = superClass.getDeclaredConstructors();
for (Constructor<?> ctor : ctors) {
generateCtor(cfw, adapterName, superName, ctor);
int mod = ctor.getModifiers();
if (Modifier.isPublic(mod) || Modifier.isProtected(mod)) {
generateCtor(cfw, adapterName, superName, ctor);
}
}
generateSerialCtor(cfw, adapterName, superName);
if (scriptClassName != null) {
Expand Down
18 changes: 18 additions & 0 deletions testsrc/doctests/javaadapter.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ js> x = JavaAdapter(java.util.Vector, {test: function() {return this.elementData
[]
js> x.test()
20
js> // test extending abstract base class
js> x = new java.util.AbstractList({get: function(i) { return i + 1; }})
[]
js> x.get(0)
1.0
js> x.get(1)
2.0
js> x.get(2)
3.0
js> // test implementing an interface
js> x = new java.util.List({get: function(i) { return i + 1; }, toString: function() { return "[]"; }})
[]
js> x.get(0)
1.0
js> x.get(1)
2.0
js> x.get(2)
3.0

0 comments on commit 69b177c

Please sign in to comment.