use of org.elasticsearch.painless.Definition.Type in project elasticsearch by elastic.
the class ENewObj method analyze.
@Override
void analyze(Locals locals) {
final Type type;
try {
type = Definition.getType(this.type);
} catch (IllegalArgumentException exception) {
throw createError(new IllegalArgumentException("Not a type [" + this.type + "]."));
}
Struct struct = type.struct;
constructor = struct.constructors.get(new Definition.MethodKey("<init>", arguments.size()));
if (constructor != null) {
Type[] types = new Type[constructor.arguments.size()];
constructor.arguments.toArray(types);
if (constructor.arguments.size() != arguments.size()) {
throw createError(new IllegalArgumentException("When calling constructor on type [" + struct.name + "]" + " expected [" + constructor.arguments.size() + "] arguments, but found [" + arguments.size() + "]."));
}
for (int argument = 0; argument < arguments.size(); ++argument) {
AExpression expression = arguments.get(argument);
expression.expected = types[argument];
expression.internal = true;
expression.analyze(locals);
arguments.set(argument, expression.cast(locals));
}
statement = true;
actual = type;
} else {
throw createError(new IllegalArgumentException("Unknown new call on type [" + struct.name + "]."));
}
}
use of org.elasticsearch.painless.Definition.Type in project elasticsearch by elastic.
the class SCatch method analyze.
@Override
void analyze(Locals locals) {
final Type type;
try {
type = Definition.getType(this.type);
} catch (IllegalArgumentException exception) {
throw createError(new IllegalArgumentException("Not a type [" + this.type + "]."));
}
if (!Exception.class.isAssignableFrom(type.clazz)) {
throw createError(new ClassCastException("Not an exception type [" + this.type + "]."));
}
variable = locals.addVariable(location, type, name, true);
if (block != null) {
block.lastSource = lastSource;
block.inLoop = inLoop;
block.lastLoop = lastLoop;
block.analyze(locals);
methodEscape = block.methodEscape;
loopEscape = block.loopEscape;
allEscape = block.allEscape;
anyContinue = block.anyContinue;
anyBreak = block.anyBreak;
statementCount = block.statementCount;
}
}
use of org.elasticsearch.painless.Definition.Type in project elasticsearch by elastic.
the class SExpression method analyze.
@Override
void analyze(Locals locals) {
Type rtnType = locals.getReturnType();
boolean isVoid = rtnType.sort == Sort.VOID;
expression.read = lastSource && !isVoid;
expression.analyze(locals);
if (!lastSource && !expression.statement) {
throw createError(new IllegalArgumentException("Not a statement."));
}
boolean rtn = lastSource && !isVoid && expression.actual.sort != Sort.VOID;
expression.expected = rtn ? rtnType : expression.actual;
expression.internal = rtn;
expression = expression.cast(locals);
methodEscape = rtn;
loopEscape = rtn;
allEscape = rtn;
statementCount = 1;
}
use of org.elasticsearch.painless.Definition.Type in project elasticsearch by elastic.
the class PainlessDocGenerator method emitJavadocLink.
/**
* Emit an external link to Javadoc for a {@link Method}.
*
* @param root name of the root uri variable
*/
private static void emitJavadocLink(PrintStream stream, String root, Method method) {
stream.print("link:{");
stream.print(root);
stream.print("-javadoc}/");
stream.print((method.augmentation ? Augmentation.class : method.owner.clazz).getName().replace('.', '/'));
stream.print(".html#");
stream.print(methodName(method));
stream.print("%2D");
boolean first = true;
if (method.augmentation) {
first = false;
stream.print(method.owner.clazz.getName());
}
for (Type arg : method.arguments) {
if (first) {
first = false;
} else {
stream.print("%2D");
}
stream.print(arg.struct.clazz.getName());
if (arg.dimensions > 0) {
stream.print(":A");
}
}
stream.print("%2D");
}
use of org.elasticsearch.painless.Definition.Type in project elasticsearch by elastic.
the class SEach method analyze.
@Override
void analyze(Locals locals) {
expression.analyze(locals);
expression.expected = expression.actual;
expression = expression.cast(locals);
final Type type;
try {
type = Definition.getType(this.type);
} catch (IllegalArgumentException exception) {
throw createError(new IllegalArgumentException("Not a type [" + this.type + "]."));
}
locals = Locals.newLocalScope(locals);
Variable variable = locals.addVariable(location, type, name, true);
if (expression.actual.sort == Sort.ARRAY) {
sub = new SSubEachArray(location, variable, expression, block);
} else if (expression.actual.sort == Sort.DEF || Iterable.class.isAssignableFrom(expression.actual.clazz)) {
sub = new SSubEachIterable(location, variable, expression, block);
} else {
throw createError(new IllegalArgumentException("Illegal for each type [" + expression.actual.name + "]."));
}
sub.analyze(locals);
if (block == null) {
throw createError(new IllegalArgumentException("Extraneous for each loop."));
}
block.beginLoop = true;
block.inLoop = true;
block.analyze(locals);
block.statementCount = Math.max(1, block.statementCount);
if (block.loopEscape && !block.anyContinue) {
throw createError(new IllegalArgumentException("Extraneous for loop."));
}
statementCount = 1;
if (locals.hasVariable(Locals.LOOP)) {
sub.loopCounter = locals.getVariable(location, Locals.LOOP);
}
}
Aggregations