LUCENE-6964: String-based signatures in JavascriptCompiler replaced with better compile-time-checked MethodType; generated class files are no longer marked as synthetic

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1723636 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2016-01-07 22:24:06 +00:00
parent cc546f4e39
commit 5bfbcfdfc9
2 changed files with 13 additions and 9 deletions

View File

@ -230,6 +230,10 @@ Other
with bad function names or bad arity instead of IllegalArgumentException
(Tomás Fernández Löbbe)
* LUCENE-6964: String-based signatures in JavascriptCompiler replaced
with better compile-time-checked MethodType; generated class files
are no longer marked as synthetic. (Uwe Schindler)
======================= Lucene 5.4.0 =======================
New Features

View File

@ -96,14 +96,14 @@ public final class JavascriptCompiler {
static final Type FUNCTION_VALUES_TYPE = Type.getType(FunctionValues.class);
private static final org.objectweb.asm.commons.Method
EXPRESSION_CTOR = getMethod("void <init>(String, String[])"),
EVALUATE_METHOD = getMethod("double evaluate(int, " + FunctionValues.class.getName() + "[])");
EXPRESSION_CTOR = getAsmMethod(void.class, "<init>", String.class, String[].class),
EVALUATE_METHOD = getAsmMethod(double.class, "evaluate", int.class, FunctionValues[].class);
static final org.objectweb.asm.commons.Method DOUBLE_VAL_METHOD = getMethod("double doubleVal(int)");
static final org.objectweb.asm.commons.Method DOUBLE_VAL_METHOD = getAsmMethod(double.class, "doubleVal", int.class);
// to work around import clash:
private static org.objectweb.asm.commons.Method getMethod(String method) {
return org.objectweb.asm.commons.Method.getMethod(method);
/** create an ASM Method object from return type, method name, and parameters. */
private static org.objectweb.asm.commons.Method getAsmMethod(Class<?> rtype, String name, Class<?>... ptypes) {
return new org.objectweb.asm.commons.Method(name, MethodType.methodType(rtype, ptypes).toMethodDescriptorString());
}
// This maximum length is theoretically 65535 bytes, but as it's CESU-8 encoded we dont know how large it is in bytes, so be safe
@ -230,14 +230,14 @@ public final class JavascriptCompiler {
*/
private void generateClass(final ParseTree parseTree, final ClassWriter classWriter, final Map<String, Integer> externalsMap) throws ParseException {
classWriter.visit(CLASSFILE_VERSION,
Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL,
COMPILED_EXPRESSION_INTERNAL,
null, EXPRESSION_TYPE.getInternalName(), null);
final String clippedSourceText = (sourceText.length() <= MAX_SOURCE_LENGTH) ?
sourceText : (sourceText.substring(0, MAX_SOURCE_LENGTH - 3) + "...");
classWriter.visitSource(clippedSourceText, null);
final GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC,
final GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC,
EXPRESSION_CTOR, null, null, classWriter);
constructor.loadThis();
constructor.loadArgs();
@ -245,7 +245,7 @@ public final class JavascriptCompiler {
constructor.returnValue();
constructor.endMethod();
final GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC,
final GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC,
EVALUATE_METHOD, null, null, classWriter);
// to completely hide the ANTLR visitor we use an anonymous impl: