This commit is contained in:
Robert Muir 2016-05-10 11:23:24 -04:00
parent 02cf429e53
commit 546aed8390
3 changed files with 15 additions and 1 deletions

View File

@ -0,0 +1,5 @@
package org.elasticsearch.painless;
/** Marker interface that a generated {@link Executable} uses the {@code _score} value */
public interface NeedsScore {
}

View File

@ -135,7 +135,14 @@ class Writer extends PainlessParserBaseVisitor<Void> {
final String base = BASE_CLASS_TYPE.getInternalName();
final String name = CLASS_TYPE.getInternalName();
writer.visit(version, access, name, null, base, null);
// apply marker interface NeedsScore if we use the score!
final String interfaces[];
if (metadata.scoreValueUsed) {
interfaces = new String[] { WriterConstants.NEEDS_SCORE_TYPE.getInternalName() };
} else {
interfaces = null;
}
writer.visit(version, access, name, null, base, interfaces);
writer.visitSource(source, null);
}

View File

@ -44,6 +44,8 @@ class WriterConstants {
final static Type DEFINITION_TYPE = Type.getType(Definition.class);
final static Type NEEDS_SCORE_TYPE = Type.getType(NeedsScore.class);
final static Type OBJECT_TYPE = Type.getType(Object.class);
final static Type MAP_TYPE = Type.getType(Map.class);