LUCENE-5207: Add a unused test method to make sure that if we change the FunctionValues interface we get compile error. Also make the class format version a constant for easy maintenance (once we backport)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5207@1522925 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2013-09-13 13:40:56 +00:00
parent 115d5dd0e1
commit 9617a1ddaa
1 changed files with 14 additions and 1 deletions

View File

@ -116,6 +116,8 @@ public class JavascriptCompiler {
}
}
private static final int CLASSFILE_VERSION = V1_7;
// We use the same class name for all generated classes as they all have their own class loader.
// The source code is displayed as "source file name" in stack trace.
private static final String COMPILED_EXPRESSION_CLASS = JavascriptCompiler.class.getName() + "$CompiledExpression";
@ -152,6 +154,17 @@ public class JavascriptCompiler {
return new JavascriptCompiler().compileExpression(sourceText);
}
/**
* This method is unused, it is just here to make sure that the funcion signatures don't change.
* If this method fails to compile, you also have to change the byte code generator to correctly
* use the FunctionValues class.
*/
@SuppressWarnings("unused")
private static void unusedTestCompile() {
FunctionValues f = null;
double ret = f.doubleVal(2);
}
/**
* Constructs a compiler for expressions.
*/
@ -189,7 +202,7 @@ public class JavascriptCompiler {
private void beginCompile(String sourceText) {
classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classWriter.visit(V1_7, ACC_PUBLIC + ACC_SUPER + ACC_FINAL, COMPILED_EXPRESSION_INTERNAL,
classWriter.visit(CLASSFILE_VERSION, ACC_PUBLIC + ACC_SUPER + ACC_FINAL, COMPILED_EXPRESSION_INTERNAL,
null, EXPRESSION_INTERNAL, null);
String clippedSourceText = (sourceText.length() <= MAX_SOURCE_LENGTH) ? sourceText : (sourceText.substring(0, MAX_SOURCE_LENGTH - 3) + "...");
classWriter.visitSource(clippedSourceText, null);