if (!(var instanceof RubyArray)) {
throw runtime.newTypeError(
"invalid java_interfaces defined for proxy (or ancestor): " +
ancestor + ": " + var);
}
RubyArray ifcArray = (RubyArray)var;
int size = ifcArray.size();
for (int i = size; --i >= 0; ) {
IRubyObject ifc = ifcArray.eltInternal(i);
if (!(ifc instanceof JavaClass)) {
throw runtime.newTypeError(
"invalid java interface defined for proxy (or ancestor): " +
ancestor + ": " + ifc);
}
Class interfaceClass = ((JavaClass)ifc).javaClass();
if (!interfaceClass.isInterface()) {
throw runtime.newTypeError(
"invalid java interface defined for proxy (or ancestor): " +
ancestor + ": " + ifc + " (not an interface)");
}
if (!interfaceList.contains(interfaceClass)) {
interfaceList.add(interfaceClass);
}
}
}
// set this class's method names in var @__java_ovrd_methods if this
// is the new class; otherwise, get method names from there if this is
// a proxy superclass.
// FIXME: shouldn't need @__java_ovrd_methods, just query locally defined methods.
var = ancestor.getInstanceVariables().fastGetInstanceVariable("@__java_ovrd_methods");
if (var == null) {
// lock in the overridden methods for the new class, and any as-yet
// uninstantiated ancestor class.
Map<String, DynamicMethod> methods;
RubyArray methodNames;
synchronized(methods = ancestor.getMethods()) {
methodNames = RubyArray.newArrayLight(runtime,methods.size());
for (String methodName: methods.keySet()) {
if (!EXCLUDE_METHODS.contains(methodName)) {
names.add(methodName);
methodNames.append(runtime.newString(methodName));
}
}
}
ancestor.fastSetInstanceVariable("@__java_ovrd_methods",methodNames);
} else {
if (!(var instanceof RubyArray)) {
throw runtime.newTypeError(
"invalid @__java_ovrd_methods defined for proxy: " +
ancestor + ": " + var);
}
RubyArray methodNames = (RubyArray)var;
int size = methodNames.size();
for (int i = size; --i >= 0; ) {
IRubyObject methodName = methodNames.eltInternal(i);
if (!(methodName instanceof RubyString)) {
throw runtime.newTypeError(
"invalid method name defined for proxy (or ancestor): " +
ancestor + ": " + methodName);
}