NativeJavaMethod method = new NativeJavaMethod(enterMethod, "name"); idScriptableObject.setGetterOrSetter("name", 0, method, false); NativeJavaMethod nativeJavaMethod = new NativeJavaMethod(newTransformer, "message"); idScriptableObject.setGetterOrSetter("message", 0, nativeJavaMethod, false);
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { return nativeJavaMethod.call(cx, scope, thisObj, args); }
@Override public String toString() { return nativeJavaMethod.toString(); } }
String decompile(int indent, int flags) { StringBuffer sb = new StringBuffer(); boolean justbody = (0 != (flags & Decompiler.ONLY_BODY_FLAG)); if (!justbody) { sb.append("function "); sb.append(getFunctionName()); sb.append("() {"); } sb.append("/*\n"); sb.append(toString()); sb.append(justbody ? "*/\n" : "*/}\n"); return sb.toString(); }
private Object getExplicitFunction(Scriptable scope, String name, Object javaObject, boolean isStatic) { Map<String,Object> ht = isStatic ? staticMembers : members; Object member = null; MemberBox methodOrCtor = findExplicitFunction(name, isStatic); if (methodOrCtor != null) { Scriptable prototype = ScriptableObject.getFunctionPrototype(scope); if (methodOrCtor.isCtor()) { NativeJavaConstructor fun = new NativeJavaConstructor(methodOrCtor); fun.setPrototype(prototype); member = fun; ht.put(name, fun); } else { String trueName = methodOrCtor.getName(); member = ht.get(trueName); if (member instanceof NativeJavaMethod && ((NativeJavaMethod)member).methods.length > 1 ) { NativeJavaMethod fun = new NativeJavaMethod(methodOrCtor, name); fun.setPrototype(prototype); ht.put(name, fun); member = fun; } } } return member; }
int index = findCachedFunction(cx, args); if (index < 0) { Class<?> c = methods[0].method().getDeclaringClass(); String sig = c.getName() + '.' + getFunctionName() + '(' + scriptSignature(args) + ')'; throw Context.reportRuntimeError1("msg.java.no_such_method", sig); if (o == null) { throw Context.reportRuntimeError3( "msg.nonjava.method", getFunctionName(), ScriptRuntime.toString(thisObj), c.getName());
int preference = preferSignature(args, argTypes, member.vararg, bestFit.argTypes, throw Context.reportRuntimeError3( "msg.constructor.ambiguous", memberName, scriptSignature(args), buf.toString()); } else { throw Context.reportRuntimeError4( "msg.method.ambiguous", memberClass, memberName, scriptSignature(args), buf.toString());
int index = ctors.findCachedFunction(cx, args); if (index < 0) { String sig = NativeJavaMethod.scriptSignature(args); throw Context.reportRuntimeError2( "msg.no.java.ctor", classObject.getName(), sig);
int index = findFunction(cx, methods, args); if (index < 0) { Class<?> c = methods[0].method().getDeclaringClass(); String sig = c.getName() + '.' + getFunctionName() + '(' + scriptSignature(args) + ')'; throw Context.reportRuntimeError1("msg.java.no_such_method", sig); if (o == null) { throw Context.reportRuntimeError3( "msg.nonjava.method", getFunctionName(), ScriptRuntime.toString(thisObj), c.getName());
int index = NativeJavaMethod.findFunction(cx, ctors, args); if (index < 0) { String sig = NativeJavaMethod.scriptSignature(args); throw Context.reportRuntimeError2( "msg.no.java.ctor", classObject.getName(), sig);
int findCachedFunction(Context cx, Object[] args) { if (methods.length > 1) { if (overloadCache != null) { for (ResolvedOverload ovl : overloadCache) { if (ovl.matches(args)) { return ovl.index; } } } else { overloadCache = new CopyOnWriteArrayList<ResolvedOverload>(); } int index = findFunction(cx, methods, args); // As a sanity measure, don't let the lookup cache grow longer // than twice the number of overloaded methods if (overloadCache.size() < methods.length * 2) { synchronized (overloadCache) { ResolvedOverload ovl = new ResolvedOverload(args, index); if (!overloadCache.contains(ovl)) { overloadCache.add(0, ovl); } } } return index; } return findFunction(cx, methods, args); }
@Override String decompile(int indent, int flags) { String helpMessage = MessagesProvider.getHelp(getDeclaringClass(), nativeJavaMethod.getFunctionName()); if (helpMessage != null && helpMessage.trim().length() > 0) { return helpMessage; } return nativeJavaMethod.decompile(indent, flags); }
@Override String decompile(int indent, int flags) { StringBuilder sb = new StringBuilder(); boolean justbody = (0 != (flags & Decompiler.ONLY_BODY_FLAG)); if (!justbody) { sb.append("function "); sb.append(getFunctionName()); sb.append("() {"); } sb.append("/*\n"); sb.append(toString()); sb.append(justbody ? "*/\n" : "*/}\n"); return sb.toString(); }
private Object getExplicitFunction(Scriptable scope, String name, Object javaObject, boolean isStatic) { Map<String,Object> ht = isStatic ? staticMembers : members; Object member = null; MemberBox methodOrCtor = findExplicitFunction(name, isStatic); if (methodOrCtor != null) { Scriptable prototype = ScriptableObject.getFunctionPrototype(scope); if (methodOrCtor.isCtor()) { NativeJavaConstructor fun = new NativeJavaConstructor(methodOrCtor); fun.setPrototype(prototype); member = fun; ht.put(name, fun); } else { String trueName = methodOrCtor.getName(); member = ht.get(trueName); if (member instanceof NativeJavaMethod && ((NativeJavaMethod)member).methods.length > 1 ) { NativeJavaMethod fun = new NativeJavaMethod(methodOrCtor, name); fun.setPrototype(prototype); ht.put(name, fun); member = fun; } } } return member; }
int index = findCachedFunction(cx, args); if (index < 0) { Class<?> c = methods[0].method().getDeclaringClass(); String sig = c.getName() + '.' + getFunctionName() + '(' + scriptSignature(args) + ')'; throw Context.reportRuntimeError1("msg.java.no_such_method", sig); if (o == null) { throw Context.reportRuntimeError3( "msg.nonjava.method", getFunctionName(), ScriptRuntime.toString(thisObj), c.getName());
++worseCount; } else { int preference = preferSignature(args, argTypes, member.vararg, bestFit.argTypes, throw Context.reportRuntimeError3( "msg.constructor.ambiguous", memberName, scriptSignature(args), buf.toString()); } else { throw Context.reportRuntimeError4( "msg.method.ambiguous", memberClass, memberName, scriptSignature(args), buf.toString());
int index = ctors.findCachedFunction(cx, args); if (index < 0) { String sig = NativeJavaMethod.scriptSignature(args); throw Context.reportRuntimeError2( "msg.no.java.ctor", classObject.getName(), sig);
int index = findFunction(cx, methods, args); if (index < 0) { Class c = methods[0].method().getDeclaringClass(); String sig = c.getName() + '.' + getFunctionName() + '(' + scriptSignature(args) + ')'; throw Context.reportRuntimeError1("msg.java.no_such_method", sig); if (o == null) { throw Context.reportRuntimeError3( "msg.nonjava.method", getFunctionName(), ScriptRuntime.toString(thisObj), c.getName());
int index = NativeJavaMethod.findFunction(cx, ctors, args); if (index < 0) { String sig = NativeJavaMethod.scriptSignature(args); throw Context.reportRuntimeError2( "msg.no.java.ctor", classObject.getName(), sig);
int findCachedFunction(Context cx, Object[] args) { if (methods.length > 1) { if (overloadCache != null) { for (ResolvedOverload ovl : overloadCache) { if (ovl.matches(args)) { return ovl.index; } } } else { overloadCache = new CopyOnWriteArrayList<ResolvedOverload>(); } int index = findFunction(cx, methods, args); // As a sanity measure, don't let the lookup cache grow longer // than twice the number of overloaded methods if (overloadCache.size() < methods.length * 2) { synchronized (overloadCache) { ResolvedOverload ovl = new ResolvedOverload(args, index); if (!overloadCache.contains(ovl)) { overloadCache.add(0, ovl); } } } return index; } return findFunction(cx, methods, args); }