Painless: Move and Rename Several Methods in the lookup package (#32105)
This commit is contained in:
parent
f699cb9f55
commit
15740d6229
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.painless;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -465,8 +465,9 @@ public final class AnalyzerCaster {
|
|||
(actual.isAssignableFrom(expected) && explicit)) {
|
||||
return PainlessCast.standard(actual, expected, explicit);
|
||||
} else {
|
||||
throw location.createError(new ClassCastException(
|
||||
"Cannot cast from [" + PainlessLookup.ClassToName(actual) + "] to [" + PainlessLookup.ClassToName(expected) + "]."));
|
||||
throw location.createError(new ClassCastException("Cannot cast from " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(actual) + "] to " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "]."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
|
||||
package org.elasticsearch.painless;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
|
@ -302,7 +303,7 @@ public final class Def {
|
|||
nestedType,
|
||||
0,
|
||||
DefBootstrap.REFERENCE,
|
||||
PainlessLookup.ClassToName(interfaceType));
|
||||
PainlessLookupUtility.anyTypeToPainlessTypeName(interfaceType));
|
||||
filter = nested.dynamicInvoker();
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
|
@ -347,7 +348,7 @@ public final class Def {
|
|||
PainlessMethod interfaceMethod = painlessLookup.getPainlessStructFromJavaClass(clazz).functionalMethod;
|
||||
if (interfaceMethod == null) {
|
||||
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
|
||||
"to [" + PainlessLookup.ClassToName(clazz) + "], not a functional interface");
|
||||
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(clazz) + "], not a functional interface");
|
||||
}
|
||||
int arity = interfaceMethod.arguments.size() + captures.length;
|
||||
final MethodHandle handle;
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.painless;
|
|||
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.objectweb.asm.Type;
|
||||
|
@ -168,7 +169,7 @@ public class FunctionRef {
|
|||
PainlessMethod method = painlessLookup.getPainlessStructFromJavaClass(expected).functionalMethod;
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
|
||||
"to [" + PainlessLookup.ClassToName(expected) + "], not a functional interface");
|
||||
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "], not a functional interface");
|
||||
}
|
||||
|
||||
// lookup requested method
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
|
||||
package org.elasticsearch.painless;
|
||||
|
||||
import org.elasticsearch.painless.ScriptClassInfo.MethodArgument;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.ScriptClassInfo.MethodArgument;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -292,7 +293,7 @@ public final class Locals {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("Variable[type=").append(PainlessLookup.ClassToName(clazz));
|
||||
b.append("Variable[type=").append(PainlessLookupUtility.anyTypeToPainlessTypeName(clazz));
|
||||
b.append(",name=").append(name);
|
||||
b.append(",slot=").append(slot);
|
||||
if (readonly) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.painless;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -182,7 +183,7 @@ public class ScriptClassInfo {
|
|||
|
||||
private static Class<?> definitionTypeForClass(PainlessLookup painlessLookup, Class<?> type,
|
||||
Function<Class<?>, String> unknownErrorMessageSource) {
|
||||
type = PainlessLookup.ObjectClassTodefClass(type);
|
||||
type = PainlessLookupUtility.javaObjectTypeToPainlessDefType(type);
|
||||
Class<?> componentType = type;
|
||||
|
||||
while (componentType.isArray()) {
|
||||
|
|
|
@ -23,8 +23,8 @@ import org.antlr.v4.runtime.CharStream;
|
|||
import org.antlr.v4.runtime.LexerNoViableAltException;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
|
||||
/**
|
||||
* A lexer that is customized for painless. It:
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.painless.lookup;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
@ -30,154 +29,6 @@ import java.util.Map;
|
|||
*/
|
||||
public final class PainlessLookup {
|
||||
|
||||
public static Class<?> getBoxedType(Class<?> clazz) {
|
||||
if (clazz == boolean.class) {
|
||||
return Boolean.class;
|
||||
} else if (clazz == byte.class) {
|
||||
return Byte.class;
|
||||
} else if (clazz == short.class) {
|
||||
return Short.class;
|
||||
} else if (clazz == char.class) {
|
||||
return Character.class;
|
||||
} else if (clazz == int.class) {
|
||||
return Integer.class;
|
||||
} else if (clazz == long.class) {
|
||||
return Long.class;
|
||||
} else if (clazz == float.class) {
|
||||
return Float.class;
|
||||
} else if (clazz == double.class) {
|
||||
return Double.class;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class<?> getUnboxedype(Class<?> clazz) {
|
||||
if (clazz == Boolean.class) {
|
||||
return boolean.class;
|
||||
} else if (clazz == Byte.class) {
|
||||
return byte.class;
|
||||
} else if (clazz == Short.class) {
|
||||
return short.class;
|
||||
} else if (clazz == Character.class) {
|
||||
return char.class;
|
||||
} else if (clazz == Integer.class) {
|
||||
return int.class;
|
||||
} else if (clazz == Long.class) {
|
||||
return long.class;
|
||||
} else if (clazz == Float.class) {
|
||||
return float.class;
|
||||
} else if (clazz == Double.class) {
|
||||
return double.class;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static boolean isConstantType(Class<?> clazz) {
|
||||
return clazz == boolean.class ||
|
||||
clazz == byte.class ||
|
||||
clazz == short.class ||
|
||||
clazz == char.class ||
|
||||
clazz == int.class ||
|
||||
clazz == long.class ||
|
||||
clazz == float.class ||
|
||||
clazz == double.class ||
|
||||
clazz == String.class;
|
||||
}
|
||||
|
||||
public Class<?> getClassFromBinaryName(String painlessType) {
|
||||
return painlessTypesToJavaClasses.get(painlessType.replace('$', '.'));
|
||||
}
|
||||
|
||||
public static Class<?> ObjectClassTodefClass(Class<?> clazz) {
|
||||
if (clazz.isArray()) {
|
||||
Class<?> component = clazz.getComponentType();
|
||||
int dimensions = 1;
|
||||
|
||||
while (component.isArray()) {
|
||||
component = component.getComponentType();
|
||||
++dimensions;
|
||||
}
|
||||
|
||||
if (component == Object.class) {
|
||||
char[] braces = new char[dimensions];
|
||||
Arrays.fill(braces, '[');
|
||||
|
||||
String descriptor = new String(braces) + org.objectweb.asm.Type.getType(def.class).getDescriptor();
|
||||
org.objectweb.asm.Type type = org.objectweb.asm.Type.getType(descriptor);
|
||||
|
||||
try {
|
||||
return Class.forName(type.getInternalName().replace('/', '.'));
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new IllegalStateException("internal error", exception);
|
||||
}
|
||||
}
|
||||
} else if (clazz == Object.class) {
|
||||
return def.class;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class<?> defClassToObjectClass(Class<?> clazz) {
|
||||
if (clazz.isArray()) {
|
||||
Class<?> component = clazz.getComponentType();
|
||||
int dimensions = 1;
|
||||
|
||||
while (component.isArray()) {
|
||||
component = component.getComponentType();
|
||||
++dimensions;
|
||||
}
|
||||
|
||||
if (component == def.class) {
|
||||
char[] braces = new char[dimensions];
|
||||
Arrays.fill(braces, '[');
|
||||
|
||||
String descriptor = new String(braces) + org.objectweb.asm.Type.getType(Object.class).getDescriptor();
|
||||
org.objectweb.asm.Type type = org.objectweb.asm.Type.getType(descriptor);
|
||||
|
||||
try {
|
||||
return Class.forName(type.getInternalName().replace('/', '.'));
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new IllegalStateException("internal error", exception);
|
||||
}
|
||||
}
|
||||
} else if (clazz == def.class) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static String ClassToName(Class<?> clazz) {
|
||||
if (clazz.isLocalClass() || clazz.isAnonymousClass()) {
|
||||
return null;
|
||||
} else if (clazz.isArray()) {
|
||||
Class<?> component = clazz.getComponentType();
|
||||
int dimensions = 1;
|
||||
|
||||
while (component.isArray()) {
|
||||
component = component.getComponentType();
|
||||
++dimensions;
|
||||
}
|
||||
|
||||
if (component == def.class) {
|
||||
StringBuilder builder = new StringBuilder(def.class.getSimpleName());
|
||||
|
||||
for (int dimension = 0; dimension < dimensions; dimension++) {
|
||||
builder.append("[]");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
} else if (clazz == def.class) {
|
||||
return def.class.getSimpleName();
|
||||
}
|
||||
|
||||
return clazz.getCanonicalName().replace('$', '.');
|
||||
}
|
||||
|
||||
public Collection<PainlessClass> getStructs() {
|
||||
return javaClassesToPainlessStructs.values();
|
||||
}
|
||||
|
@ -190,6 +41,10 @@ public final class PainlessLookup {
|
|||
this.javaClassesToPainlessStructs = Collections.unmodifiableMap(javaClassesToPainlessStructs);
|
||||
}
|
||||
|
||||
public Class<?> getClassFromBinaryName(String painlessType) {
|
||||
return painlessTypesToJavaClasses.get(painlessType.replace('$', '.'));
|
||||
}
|
||||
|
||||
public boolean isSimplePainlessType(String painlessType) {
|
||||
return painlessTypesToJavaClasses.containsKey(painlessType);
|
||||
}
|
||||
|
@ -199,59 +54,6 @@ public final class PainlessLookup {
|
|||
}
|
||||
|
||||
public Class<?> getJavaClassFromPainlessType(String painlessType) {
|
||||
Class<?> javaClass = painlessTypesToJavaClasses.get(painlessType);
|
||||
|
||||
if (javaClass != null) {
|
||||
return javaClass;
|
||||
}
|
||||
int arrayDimensions = 0;
|
||||
int arrayIndex = painlessType.indexOf('[');
|
||||
|
||||
if (arrayIndex != -1) {
|
||||
int length = painlessType.length();
|
||||
|
||||
while (arrayIndex < length) {
|
||||
if (painlessType.charAt(arrayIndex) == '[' && ++arrayIndex < length && painlessType.charAt(arrayIndex++) == ']') {
|
||||
++arrayDimensions;
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid painless type [" + painlessType + "].");
|
||||
}
|
||||
}
|
||||
|
||||
painlessType = painlessType.substring(0, painlessType.indexOf('['));
|
||||
javaClass = painlessTypesToJavaClasses.get(painlessType);
|
||||
|
||||
char braces[] = new char[arrayDimensions];
|
||||
Arrays.fill(braces, '[');
|
||||
String descriptor = new String(braces);
|
||||
|
||||
if (javaClass == boolean.class) {
|
||||
descriptor += "Z";
|
||||
} else if (javaClass == byte.class) {
|
||||
descriptor += "B";
|
||||
} else if (javaClass == short.class) {
|
||||
descriptor += "S";
|
||||
} else if (javaClass == char.class) {
|
||||
descriptor += "C";
|
||||
} else if (javaClass == int.class) {
|
||||
descriptor += "I";
|
||||
} else if (javaClass == long.class) {
|
||||
descriptor += "J";
|
||||
} else if (javaClass == float.class) {
|
||||
descriptor += "F";
|
||||
} else if (javaClass == double.class) {
|
||||
descriptor += "D";
|
||||
} else {
|
||||
descriptor += "L" + javaClass.getName() + ";";
|
||||
}
|
||||
|
||||
try {
|
||||
return Class.forName(descriptor);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new IllegalStateException("invalid painless type [" + painlessType + "]", cnfe);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("invalid painless type [" + painlessType + "]");
|
||||
return PainlessLookupUtility.painlessTypeNameToPainlessType(painlessType, painlessTypesToJavaClasses);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.lang.invoke.MethodHandle;
|
|||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -279,7 +278,7 @@ public class PainlessLookupBuilder {
|
|||
Class<?> painlessParameterClass = getJavaClassFromPainlessType(painlessParameterTypeName);
|
||||
|
||||
painlessParametersTypes.add(painlessParameterClass);
|
||||
javaClassParameters[parameterCount] = PainlessLookup.defClassToObjectClass(painlessParameterClass);
|
||||
javaClassParameters[parameterCount] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(painlessParameterClass);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new IllegalArgumentException("struct not defined for constructor parameter [" + painlessParameterTypeName + "] " +
|
||||
"with owner struct [" + ownerStructName + "] and constructor parameters " +
|
||||
|
@ -364,7 +363,8 @@ public class PainlessLookupBuilder {
|
|||
Class<?> painlessParameterClass = getJavaClassFromPainlessType(painlessParameterTypeName);
|
||||
|
||||
painlessParametersTypes.add(painlessParameterClass);
|
||||
javaClassParameters[parameterCount + augmentedOffset] = PainlessLookup.defClassToObjectClass(painlessParameterClass);
|
||||
javaClassParameters[parameterCount + augmentedOffset] =
|
||||
PainlessLookupUtility.painlessDefTypeToJavaObjectType(painlessParameterClass);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new IllegalArgumentException("struct not defined for method parameter [" + painlessParameterTypeName + "] " +
|
||||
"with owner struct [" + ownerStructName + "] and method with name [" + whitelistMethod.javaMethodName + "] " +
|
||||
|
@ -393,7 +393,7 @@ public class PainlessLookupBuilder {
|
|||
"and parameters " + whitelistMethod.painlessParameterTypeNames, iae);
|
||||
}
|
||||
|
||||
if (javaMethod.getReturnType() != PainlessLookup.defClassToObjectClass(painlessReturnClass)) {
|
||||
if (javaMethod.getReturnType() != PainlessLookupUtility.painlessDefTypeToJavaObjectType(painlessReturnClass)) {
|
||||
throw new IllegalArgumentException("specified return type class [" + painlessReturnClass + "] " +
|
||||
"does not match the return type class [" + javaMethod.getReturnType() + "] for the " +
|
||||
"method with name [" + whitelistMethod.javaMethodName + "] " +
|
||||
|
@ -711,64 +711,11 @@ public class PainlessLookupBuilder {
|
|||
return painless;
|
||||
}
|
||||
|
||||
public Class<?> getJavaClassFromPainlessType(String painlessType) {
|
||||
Class<?> javaClass = painlessTypesToJavaClasses.get(painlessType);
|
||||
|
||||
if (javaClass != null) {
|
||||
return javaClass;
|
||||
}
|
||||
int arrayDimensions = 0;
|
||||
int arrayIndex = painlessType.indexOf('[');
|
||||
|
||||
if (arrayIndex != -1) {
|
||||
int length = painlessType.length();
|
||||
|
||||
while (arrayIndex < length) {
|
||||
if (painlessType.charAt(arrayIndex) == '[' && ++arrayIndex < length && painlessType.charAt(arrayIndex++) == ']') {
|
||||
++arrayDimensions;
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid painless type [" + painlessType + "].");
|
||||
}
|
||||
}
|
||||
|
||||
painlessType = painlessType.substring(0, painlessType.indexOf('['));
|
||||
javaClass = painlessTypesToJavaClasses.get(painlessType);
|
||||
|
||||
char braces[] = new char[arrayDimensions];
|
||||
Arrays.fill(braces, '[');
|
||||
String descriptor = new String(braces);
|
||||
|
||||
if (javaClass == boolean.class) {
|
||||
descriptor += "Z";
|
||||
} else if (javaClass == byte.class) {
|
||||
descriptor += "B";
|
||||
} else if (javaClass == short.class) {
|
||||
descriptor += "S";
|
||||
} else if (javaClass == char.class) {
|
||||
descriptor += "C";
|
||||
} else if (javaClass == int.class) {
|
||||
descriptor += "I";
|
||||
} else if (javaClass == long.class) {
|
||||
descriptor += "J";
|
||||
} else if (javaClass == float.class) {
|
||||
descriptor += "F";
|
||||
} else if (javaClass == double.class) {
|
||||
descriptor += "D";
|
||||
} else {
|
||||
descriptor += "L" + javaClass.getName() + ";";
|
||||
}
|
||||
|
||||
try {
|
||||
return Class.forName(descriptor);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new IllegalStateException("invalid painless type [" + painlessType + "]", cnfe);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("invalid painless type [" + painlessType + "]");
|
||||
}
|
||||
|
||||
public PainlessLookup build() {
|
||||
return new PainlessLookup(painlessTypesToJavaClasses, javaClassesToPainlessStructs);
|
||||
}
|
||||
|
||||
public Class<?> getJavaClassFromPainlessType(String painlessType) {
|
||||
return PainlessLookupUtility.painlessTypeNameToPainlessType(painlessType, painlessTypesToJavaClasses);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,284 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.painless.lookup;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class contains methods shared by {@link PainlessLookupBuilder}, {@link PainlessLookup}, and other classes within
|
||||
* Painless for conversion between type names and types along with some other various utility methods.
|
||||
*
|
||||
* The following terminology is used for variable names throughout the lookup package:
|
||||
*
|
||||
* - javaClass (Class) - a java class including def and excluding array type java classes
|
||||
* - javaClassName (String) - the fully qualified java class name for a javaClass
|
||||
* - painlessClassName (String) - the fully qualified painless name or imported painless name for a painlessClass
|
||||
* - anyClassName (String) - either a javaClassName or a painlessClassName
|
||||
* - javaType (Class) - a java class excluding def and array type java classes
|
||||
* - painlessType (Class) - a java class including def and array type java classes
|
||||
* - javaTypeName (String) - the fully qualified java Type name for a javaType
|
||||
* - painlessTypeName (String) - the fully qualified painless name or imported painless name for a painlessType
|
||||
* - anyTypeName (String) - either a javaTypeName or a painlessTypeName
|
||||
* - painlessClass (PainlessClass) - a painless class object
|
||||
*
|
||||
* Under ambiguous circumstances most variable names are prefixed with asm, java, or painless.
|
||||
* If the variable name is the same for asm, java, and painless, no prefix is used.
|
||||
*/
|
||||
public final class PainlessLookupUtility {
|
||||
|
||||
public static Class<?> javaObjectTypeToPainlessDefType(Class<?> javaType) {
|
||||
if (javaType.isArray()) {
|
||||
Class<?> javaTypeComponent = javaType.getComponentType();
|
||||
int arrayDimensions = 1;
|
||||
|
||||
while (javaTypeComponent.isArray()) {
|
||||
javaTypeComponent = javaTypeComponent.getComponentType();
|
||||
++arrayDimensions;
|
||||
}
|
||||
|
||||
if (javaTypeComponent == Object.class) {
|
||||
char[] asmDescriptorBraces = new char[arrayDimensions];
|
||||
Arrays.fill(asmDescriptorBraces, '[');
|
||||
|
||||
String asmDescriptor = new String(asmDescriptorBraces) + Type.getType(def.class).getDescriptor();
|
||||
Type asmType = Type.getType(asmDescriptor);
|
||||
|
||||
try {
|
||||
return Class.forName(asmType.getInternalName().replace('/', '.'));
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new IllegalStateException("internal error", cnfe);
|
||||
}
|
||||
}
|
||||
} else if (javaType == Object.class) {
|
||||
return def.class;
|
||||
}
|
||||
|
||||
return javaType;
|
||||
}
|
||||
|
||||
public static Class<?> painlessDefTypeToJavaObjectType(Class<?> painlessType) {
|
||||
if (painlessType.isArray()) {
|
||||
Class<?> painlessTypeComponent = painlessType.getComponentType();
|
||||
int arrayDimensions = 1;
|
||||
|
||||
while (painlessTypeComponent.isArray()) {
|
||||
painlessTypeComponent = painlessTypeComponent.getComponentType();
|
||||
++arrayDimensions;
|
||||
}
|
||||
|
||||
if (painlessTypeComponent == def.class) {
|
||||
char[] asmDescriptorBraces = new char[arrayDimensions];
|
||||
Arrays.fill(asmDescriptorBraces, '[');
|
||||
|
||||
String asmDescriptor = new String(asmDescriptorBraces) + Type.getType(Object.class).getDescriptor();
|
||||
Type asmType = Type.getType(asmDescriptor);
|
||||
|
||||
try {
|
||||
return Class.forName(asmType.getInternalName().replace('/', '.'));
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new IllegalStateException("internal error", exception);
|
||||
}
|
||||
}
|
||||
} else if (painlessType == def.class) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
return painlessType;
|
||||
}
|
||||
|
||||
public static String anyTypeNameToPainlessTypeName(String anyTypeName) {
|
||||
return anyTypeName.replace(def.class.getName(), DEF_PAINLESS_CLASS_NAME).replace('$', '.');
|
||||
}
|
||||
|
||||
public static String anyTypeToPainlessTypeName(Class<?> anyType) {
|
||||
if (anyType.isLocalClass() || anyType.isAnonymousClass()) {
|
||||
return null;
|
||||
} else if (anyType.isArray()) {
|
||||
Class<?> anyTypeComponent = anyType.getComponentType();
|
||||
int arrayDimensions = 1;
|
||||
|
||||
while (anyTypeComponent.isArray()) {
|
||||
anyTypeComponent = anyTypeComponent.getComponentType();
|
||||
++arrayDimensions;
|
||||
}
|
||||
|
||||
if (anyTypeComponent == def.class) {
|
||||
StringBuilder painlessDefTypeNameArrayBuilder = new StringBuilder(DEF_PAINLESS_CLASS_NAME);
|
||||
|
||||
for (int dimension = 0; dimension < arrayDimensions; dimension++) {
|
||||
painlessDefTypeNameArrayBuilder.append("[]");
|
||||
}
|
||||
|
||||
return painlessDefTypeNameArrayBuilder.toString();
|
||||
}
|
||||
} else if (anyType == def.class) {
|
||||
return DEF_PAINLESS_CLASS_NAME;
|
||||
}
|
||||
|
||||
return anyType.getCanonicalName().replace('$', '.');
|
||||
}
|
||||
|
||||
public static Class<?> painlessTypeNameToPainlessType(String painlessTypeName, Map<String, Class<?>> painlessClassNamesToJavaClasses) {
|
||||
Class<?> javaClass = painlessClassNamesToJavaClasses.get(painlessTypeName);
|
||||
|
||||
if (javaClass != null) {
|
||||
return javaClass;
|
||||
}
|
||||
|
||||
int arrayDimensions = 0;
|
||||
int arrayIndex = painlessTypeName.indexOf('[');
|
||||
|
||||
if (arrayIndex != -1) {
|
||||
int painlessTypeNameLength = painlessTypeName.length();
|
||||
|
||||
while (arrayIndex < painlessTypeNameLength) {
|
||||
if (painlessTypeName.charAt(arrayIndex) == '[' &&
|
||||
++arrayIndex < painlessTypeNameLength &&
|
||||
painlessTypeName.charAt(arrayIndex++) == ']') {
|
||||
++arrayDimensions;
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid painless type [" + painlessTypeName + "].");
|
||||
}
|
||||
}
|
||||
|
||||
painlessTypeName = painlessTypeName.substring(0, painlessTypeName.indexOf('['));
|
||||
javaClass = painlessClassNamesToJavaClasses.get(painlessTypeName);
|
||||
|
||||
char javaDescriptorBraces[] = new char[arrayDimensions];
|
||||
Arrays.fill(javaDescriptorBraces, '[');
|
||||
String javaDescriptor = new String(javaDescriptorBraces);
|
||||
|
||||
if (javaClass == boolean.class) {
|
||||
javaDescriptor += "Z";
|
||||
} else if (javaClass == byte.class) {
|
||||
javaDescriptor += "B";
|
||||
} else if (javaClass == short.class) {
|
||||
javaDescriptor += "S";
|
||||
} else if (javaClass == char.class) {
|
||||
javaDescriptor += "C";
|
||||
} else if (javaClass == int.class) {
|
||||
javaDescriptor += "I";
|
||||
} else if (javaClass == long.class) {
|
||||
javaDescriptor += "J";
|
||||
} else if (javaClass == float.class) {
|
||||
javaDescriptor += "F";
|
||||
} else if (javaClass == double.class) {
|
||||
javaDescriptor += "D";
|
||||
} else {
|
||||
javaDescriptor += "L" + javaClass.getName() + ";";
|
||||
}
|
||||
|
||||
try {
|
||||
return Class.forName(javaDescriptor);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new IllegalStateException("painless type [" + painlessTypeName + "] not found", cnfe);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("painless type [" + painlessTypeName + "] not found");
|
||||
}
|
||||
|
||||
public static void validatePainlessType(Class<?> painlessType, Collection<Class<?>> javaClasses) {
|
||||
String painlessTypeName = anyTypeNameToPainlessTypeName(painlessType.getName());
|
||||
|
||||
while (painlessType.getComponentType() != null) {
|
||||
painlessType = painlessType.getComponentType();
|
||||
}
|
||||
|
||||
if (javaClasses.contains(painlessType) == false) {
|
||||
throw new IllegalStateException("painless type [" + painlessTypeName + "] not found");
|
||||
}
|
||||
}
|
||||
|
||||
public static String buildPainlessMethodKey(String methodName, int methodArity) {
|
||||
return methodName + "/" + methodArity;
|
||||
}
|
||||
|
||||
public static String buildPainlessFieldKey(String fieldName) {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public static Class<?> getBoxedAnyType(Class<?> anyType) {
|
||||
if (anyType == boolean.class) {
|
||||
return Boolean.class;
|
||||
} else if (anyType == byte.class) {
|
||||
return Byte.class;
|
||||
} else if (anyType == short.class) {
|
||||
return Short.class;
|
||||
} else if (anyType == char.class) {
|
||||
return Character.class;
|
||||
} else if (anyType == int.class) {
|
||||
return Integer.class;
|
||||
} else if (anyType == long.class) {
|
||||
return Long.class;
|
||||
} else if (anyType == float.class) {
|
||||
return Float.class;
|
||||
} else if (anyType == double.class) {
|
||||
return Double.class;
|
||||
}
|
||||
|
||||
return anyType;
|
||||
}
|
||||
|
||||
public static Class<?> getUnboxedAnyType(Class<?> anyType) {
|
||||
if (anyType == Boolean.class) {
|
||||
return boolean.class;
|
||||
} else if (anyType == Byte.class) {
|
||||
return byte.class;
|
||||
} else if (anyType == Short.class) {
|
||||
return short.class;
|
||||
} else if (anyType == Character.class) {
|
||||
return char.class;
|
||||
} else if (anyType == Integer.class) {
|
||||
return int.class;
|
||||
} else if (anyType == Long.class) {
|
||||
return long.class;
|
||||
} else if (anyType == Float.class) {
|
||||
return float.class;
|
||||
} else if (anyType == Double.class) {
|
||||
return double.class;
|
||||
}
|
||||
|
||||
return anyType;
|
||||
}
|
||||
|
||||
public static boolean isAnyTypeConstant(Class<?> anyType) {
|
||||
return anyType == boolean.class ||
|
||||
anyType == byte.class ||
|
||||
anyType == short.class ||
|
||||
anyType == char.class ||
|
||||
anyType == int.class ||
|
||||
anyType == long.class ||
|
||||
anyType == float.class ||
|
||||
anyType == double.class ||
|
||||
anyType == String.class;
|
||||
}
|
||||
|
||||
public static final String DEF_PAINLESS_CLASS_NAME = def.class.getSimpleName();
|
||||
public static final String CONSTRUCTOR_ANY_NAME = "<init>";
|
||||
|
||||
private PainlessLookupUtility() {
|
||||
|
||||
}
|
||||
}
|
|
@ -69,21 +69,21 @@ public class PainlessMethod {
|
|||
params = new Class<?>[1 + arguments.size()];
|
||||
params[0] = augmentation;
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
params[i + 1] = PainlessLookup.defClassToObjectClass(arguments.get(i));
|
||||
params[i + 1] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(arguments.get(i));
|
||||
}
|
||||
returnValue = PainlessLookup.defClassToObjectClass(rtn);
|
||||
returnValue = PainlessLookupUtility.painlessDefTypeToJavaObjectType(rtn);
|
||||
} else if (Modifier.isStatic(modifiers)) {
|
||||
// static method: straightforward copy
|
||||
params = new Class<?>[arguments.size()];
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
params[i] = PainlessLookup.defClassToObjectClass(arguments.get(i));
|
||||
params[i] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(arguments.get(i));
|
||||
}
|
||||
returnValue = PainlessLookup.defClassToObjectClass(rtn);
|
||||
returnValue = PainlessLookupUtility.painlessDefTypeToJavaObjectType(rtn);
|
||||
} else if ("<init>".equals(name)) {
|
||||
// constructor: returns the owner class
|
||||
params = new Class<?>[arguments.size()];
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
params[i] = PainlessLookup.defClassToObjectClass(arguments.get(i));
|
||||
params[i] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(arguments.get(i));
|
||||
}
|
||||
returnValue = owner.clazz;
|
||||
} else {
|
||||
|
@ -91,9 +91,9 @@ public class PainlessMethod {
|
|||
params = new Class<?>[1 + arguments.size()];
|
||||
params[0] = owner.clazz;
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
params[i + 1] = PainlessLookup.defClassToObjectClass(arguments.get(i));
|
||||
params[i + 1] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(arguments.get(i));
|
||||
}
|
||||
returnValue = PainlessLookup.defClassToObjectClass(rtn);
|
||||
returnValue = PainlessLookupUtility.painlessDefTypeToJavaObjectType(rtn);
|
||||
}
|
||||
return MethodType.methodType(returnValue, params);
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -157,7 +157,7 @@ public abstract class AExpression extends ANode {
|
|||
|
||||
return ecast;
|
||||
} else {
|
||||
if (PainlessLookup.isConstantType(expected)) {
|
||||
if (PainlessLookupUtility.isAnyTypeConstant(expected)) {
|
||||
// For the case where a cast is required, a constant is set,
|
||||
// and the constant can be immediately cast to the expected type.
|
||||
// An EConstant replaces this node with the constant cast appropriately
|
||||
|
|
|
@ -22,13 +22,13 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.Operation;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -21,14 +21,14 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.Operation;
|
||||
import org.elasticsearch.painless.WriterConstants;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -106,7 +106,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply multiply [*] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -148,7 +149,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply divide [/] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -195,7 +197,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply remainder [%] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -242,7 +245,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply add [+] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -300,7 +304,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply subtract [-] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -358,7 +363,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (lhspromote == null || rhspromote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply left shift [<<] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote = lhspromote;
|
||||
|
@ -405,7 +411,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (lhspromote == null || rhspromote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply right shift [>>] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote = lhspromote;
|
||||
|
@ -455,7 +462,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (lhspromote == null || rhspromote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply unsigned shift [>>>] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (lhspromote == def.class || rhspromote == def.class) {
|
||||
|
@ -498,7 +506,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply and [&] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -537,7 +546,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply xor [^] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
@ -577,7 +587,8 @@ public final class EBinary extends AExpression {
|
|||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply or [|] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
actual = promote;
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -21,14 +21,14 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.FunctionRef;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Variable;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
|
@ -69,7 +69,7 @@ public final class ECapturingFunctionRef extends AExpression implements ILambda
|
|||
defPointer = "D" + variable + "." + call + ",1";
|
||||
} else {
|
||||
// typed implementation
|
||||
defPointer = "S" + PainlessLookup.ClassToName(captured.clazz) + "." + call + ",1";
|
||||
defPointer = "S" + PainlessLookupUtility.anyTypeToPainlessTypeName(captured.clazz) + "." + call + ",1";
|
||||
}
|
||||
actual = String.class;
|
||||
} else {
|
||||
|
@ -77,7 +77,8 @@ public final class ECapturingFunctionRef extends AExpression implements ILambda
|
|||
// static case
|
||||
if (captured.clazz != def.class) {
|
||||
try {
|
||||
ref = new FunctionRef(locals.getPainlessLookup(), expected, PainlessLookup.ClassToName(captured.clazz), call, 1);
|
||||
ref = new FunctionRef(
|
||||
locals.getPainlessLookup(), expected, PainlessLookupUtility.anyTypeToPainlessTypeName(captured.clazz), call, 1);
|
||||
|
||||
// check casts between the interface method and the delegate method are legal
|
||||
for (int i = 0; i < ref.interfaceMethod.arguments.size(); ++i) {
|
||||
|
@ -109,7 +110,7 @@ public final class ECapturingFunctionRef extends AExpression implements ILambda
|
|||
// typed interface, dynamic implementation
|
||||
writer.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot());
|
||||
Type methodType = Type.getMethodType(MethodWriter.getType(expected), MethodWriter.getType(captured.clazz));
|
||||
writer.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, PainlessLookup.ClassToName(expected));
|
||||
writer.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, PainlessLookupUtility.anyTypeToPainlessTypeName(expected));
|
||||
} else {
|
||||
// typed interface, typed implementation
|
||||
writer.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot());
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -63,6 +63,6 @@ final class ECast extends AExpression {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return singleLineToString(PainlessLookup.ClassToName(cast.to), child);
|
||||
return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(cast.to), child);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.Operation;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
|
@ -93,7 +93,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply equals [==] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
@ -142,7 +143,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply reference equals [===] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
left.expected = promotedType;
|
||||
|
@ -182,7 +184,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply not equals [!=] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
@ -231,7 +234,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply reference not equals [!==] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
left.expected = promotedType;
|
||||
|
@ -271,7 +275,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply greater than or equals [>=] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
@ -310,7 +315,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply greater than [>] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
@ -349,7 +355,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply less than or equals [<=] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
@ -388,7 +395,8 @@ public final class EComp extends AExpression {
|
|||
|
||||
if (promotedType == null) {
|
||||
throw createError(new ClassCastException("Cannot apply less than [>=] to types " +
|
||||
"[" + PainlessLookup.ClassToName(left.actual) + "] and [" + PainlessLookup.ClassToName(right.actual) + "]."));
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(left.actual) + "] and " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(right.actual) + "]."));
|
||||
}
|
||||
|
||||
if (promotedType == def.class) {
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.FunctionRef;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -69,12 +69,12 @@ public final class EFunctionRef extends AExpression implements ILambda {
|
|||
PainlessMethod interfaceMethod = locals.getPainlessLookup().getPainlessStructFromJavaClass(expected).functionalMethod;
|
||||
if (interfaceMethod == null) {
|
||||
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
|
||||
"to [" + PainlessLookup.ClassToName(expected) + "], not a functional interface");
|
||||
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "], not a functional interface");
|
||||
}
|
||||
PainlessMethod delegateMethod = locals.getMethod(new PainlessMethodKey(call, interfaceMethod.arguments.size()));
|
||||
if (delegateMethod == null) {
|
||||
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
|
||||
"to [" + PainlessLookup.ClassToName(expected) + "], function not found");
|
||||
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "], function not found");
|
||||
}
|
||||
ref = new FunctionRef(expected, interfaceMethod, delegateMethod, 0);
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -64,7 +64,8 @@ public final class EInstanceof extends AExpression {
|
|||
}
|
||||
|
||||
// map to wrapped type for primitive types
|
||||
resolvedType = clazz.isPrimitive() ? PainlessLookup.getBoxedType(clazz) : PainlessLookup.defClassToObjectClass(clazz);
|
||||
resolvedType = clazz.isPrimitive() ? PainlessLookupUtility.getBoxedAnyType(clazz) :
|
||||
PainlessLookupUtility.painlessDefTypeToJavaObjectType(clazz);
|
||||
|
||||
// analyze and cast the expression
|
||||
expression.analyze(locals);
|
||||
|
@ -75,7 +76,7 @@ public final class EInstanceof extends AExpression {
|
|||
primitiveExpression = expression.actual.isPrimitive();
|
||||
// map to wrapped type for primitive types
|
||||
expressionType = expression.actual.isPrimitive() ?
|
||||
PainlessLookup.getBoxedType(expression.actual) : PainlessLookup.defClassToObjectClass(clazz);
|
||||
PainlessLookupUtility.getBoxedAnyType(expression.actual) : PainlessLookupUtility.painlessDefTypeToJavaObjectType(clazz);
|
||||
|
||||
actual = boolean.class;
|
||||
}
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.FunctionRef;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Variable;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.node.SFunction.FunctionReserved;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
|
@ -122,13 +122,13 @@ public final class ELambda extends AExpression implements ILambda {
|
|||
// we know the method statically, infer return type and any unknown/def types
|
||||
interfaceMethod = locals.getPainlessLookup().getPainlessStructFromJavaClass(expected).functionalMethod;
|
||||
if (interfaceMethod == null) {
|
||||
throw createError(new IllegalArgumentException("Cannot pass lambda to [" + PainlessLookup.ClassToName(expected) +
|
||||
"], not a functional interface"));
|
||||
throw createError(new IllegalArgumentException("Cannot pass lambda to " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "], not a functional interface"));
|
||||
}
|
||||
// check arity before we manipulate parameters
|
||||
if (interfaceMethod.arguments.size() != paramTypeStrs.size())
|
||||
throw new IllegalArgumentException("Incorrect number of parameters for [" + interfaceMethod.name +
|
||||
"] in [" + PainlessLookup.ClassToName(expected) + "]");
|
||||
"] in [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "]");
|
||||
// for method invocation, its allowed to ignore the return value
|
||||
if (interfaceMethod.rtn == void.class) {
|
||||
returnType = def.class;
|
||||
|
@ -140,7 +140,7 @@ public final class ELambda extends AExpression implements ILambda {
|
|||
for (int i = 0; i < paramTypeStrs.size(); i++) {
|
||||
String paramType = paramTypeStrs.get(i);
|
||||
if (paramType == null) {
|
||||
actualParamTypeStrs.add(PainlessLookup.ClassToName(interfaceMethod.arguments.get(i)));
|
||||
actualParamTypeStrs.add(PainlessLookupUtility.anyTypeToPainlessTypeName(interfaceMethod.arguments.get(i)));
|
||||
} else {
|
||||
actualParamTypeStrs.add(paramType);
|
||||
}
|
||||
|
@ -162,15 +162,15 @@ public final class ELambda extends AExpression implements ILambda {
|
|||
List<String> paramTypes = new ArrayList<>(captures.size() + actualParamTypeStrs.size());
|
||||
List<String> paramNames = new ArrayList<>(captures.size() + paramNameStrs.size());
|
||||
for (Variable var : captures) {
|
||||
paramTypes.add(PainlessLookup.ClassToName(var.clazz));
|
||||
paramTypes.add(PainlessLookupUtility.anyTypeToPainlessTypeName(var.clazz));
|
||||
paramNames.add(var.name);
|
||||
}
|
||||
paramTypes.addAll(actualParamTypeStrs);
|
||||
paramNames.addAll(paramNameStrs);
|
||||
|
||||
// desugar lambda body into a synthetic method
|
||||
desugared = new SFunction(reserved, location, PainlessLookup.ClassToName(returnType), name,
|
||||
paramTypes, paramNames, statements, true);
|
||||
desugared = new SFunction(reserved, location, PainlessLookupUtility.anyTypeToPainlessTypeName(returnType), name,
|
||||
paramTypes, paramNames, statements, true);
|
||||
desugared.generateSignature(locals.getPainlessLookup());
|
||||
desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), returnType,
|
||||
desugared.parameters, captures.size(), reserved.getMaxLoopCounter()));
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -53,7 +53,7 @@ public final class ENull extends AExpression {
|
|||
if (expected != null) {
|
||||
if (expected.isPrimitive()) {
|
||||
throw createError(new IllegalArgumentException(
|
||||
"Cannot cast null to a primitive type [" + PainlessLookup.ClassToName(expected) + "]."));
|
||||
"Cannot cast null to a primitive type [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "]."));
|
||||
}
|
||||
|
||||
actual = expected;
|
||||
|
|
|
@ -21,13 +21,13 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.Operation;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
@ -93,7 +93,8 @@ public final class EUnary extends AExpression {
|
|||
promote = AnalyzerCaster.promoteNumeric(child.actual, false);
|
||||
|
||||
if (promote == null) {
|
||||
throw createError(new ClassCastException("Cannot apply not [~] to type [" + PainlessLookup.ClassToName(child.actual) + "]."));
|
||||
throw createError(new ClassCastException("Cannot apply not [~] to type " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(child.actual) + "]."));
|
||||
}
|
||||
|
||||
child.expected = promote;
|
||||
|
@ -122,8 +123,8 @@ public final class EUnary extends AExpression {
|
|||
promote = AnalyzerCaster.promoteNumeric(child.actual, true);
|
||||
|
||||
if (promote == null) {
|
||||
throw createError(
|
||||
new ClassCastException("Cannot apply positive [+] to type [" + PainlessLookup.ClassToName(child.actual) + "]."));
|
||||
throw createError(new ClassCastException("Cannot apply positive [+] to type " +
|
||||
"[" + PainlessLookupUtility.painlessDefTypeToJavaObjectType(child.actual) + "]."));
|
||||
}
|
||||
|
||||
child.expected = promote;
|
||||
|
@ -156,8 +157,8 @@ public final class EUnary extends AExpression {
|
|||
promote = AnalyzerCaster.promoteNumeric(child.actual, true);
|
||||
|
||||
if (promote == null) {
|
||||
throw createError(
|
||||
new ClassCastException("Cannot apply negative [-] to type [" + PainlessLookup.ClassToName(child.actual) + "]."));
|
||||
throw createError(new ClassCastException("Cannot apply negative [-] to type " +
|
||||
"[" + PainlessLookupUtility.painlessDefTypeToJavaObjectType(child.actual) + "]."));
|
||||
}
|
||||
|
||||
child.expected = promote;
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -67,8 +67,8 @@ public final class PBrace extends AStoreable {
|
|||
} else if (List.class.isAssignableFrom(prefix.actual)) {
|
||||
sub = new PSubListShortcut(location, locals.getPainlessLookup().getPainlessStructFromJavaClass(prefix.actual), index);
|
||||
} else {
|
||||
throw createError(
|
||||
new IllegalArgumentException("Illegal array access on type [" + PainlessLookup.ClassToName(prefix.actual) + "]."));
|
||||
throw createError(new IllegalArgumentException("Illegal array access on type " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(prefix.actual) + "]."));
|
||||
}
|
||||
|
||||
sub.write = write;
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -74,7 +74,7 @@ public final class PCallInvoke extends AExpression {
|
|||
PainlessClass struct = locals.getPainlessLookup().getPainlessStructFromJavaClass(prefix.actual);
|
||||
|
||||
if (prefix.actual.isPrimitive()) {
|
||||
struct = locals.getPainlessLookup().getPainlessStructFromJavaClass(PainlessLookup.getBoxedType(prefix.actual));
|
||||
struct = locals.getPainlessLookup().getPainlessStructFromJavaClass(PainlessLookupUtility.getBoxedAnyType(prefix.actual));
|
||||
}
|
||||
|
||||
PainlessMethodKey methodKey = new PainlessMethodKey(name, arguments.size());
|
||||
|
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessField;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessField;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -64,7 +64,7 @@ public final class PField extends AStoreable {
|
|||
prefix = prefix.cast(locals);
|
||||
|
||||
if (prefix.actual.isArray()) {
|
||||
sub = new PSubArrayLength(location, PainlessLookup.ClassToName(prefix.actual), value);
|
||||
sub = new PSubArrayLength(location, PainlessLookupUtility.anyTypeToPainlessTypeName(prefix.actual), value);
|
||||
} else if (prefix.actual == def.class) {
|
||||
sub = new PSubDefField(location, value);
|
||||
} else {
|
||||
|
@ -86,7 +86,7 @@ public final class PField extends AStoreable {
|
|||
new PainlessMethodKey("set" + Character.toUpperCase(value.charAt(0)) + value.substring(1), 1));
|
||||
|
||||
if (getter != null || setter != null) {
|
||||
sub = new PSubShortcut(location, value, PainlessLookup.ClassToName(prefix.actual), getter, setter);
|
||||
sub = new PSubShortcut(location, value, PainlessLookupUtility.anyTypeToPainlessTypeName(prefix.actual), getter, setter);
|
||||
} else {
|
||||
EConstant index = new EConstant(location, value);
|
||||
index.analyze(locals);
|
||||
|
@ -104,7 +104,7 @@ public final class PField extends AStoreable {
|
|||
|
||||
if (sub == null) {
|
||||
throw createError(new IllegalArgumentException(
|
||||
"Unknown field [" + value + "] for type [" + PainlessLookup.ClassToName(prefix.actual) + "]."));
|
||||
"Unknown field [" + value + "] for type [" + PainlessLookupUtility.anyTypeToPainlessTypeName(prefix.actual) + "]."));
|
||||
}
|
||||
|
||||
if (nullSafe) {
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessField;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessField;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Objects;
|
||||
|
@ -51,8 +51,8 @@ final class PSubField extends AStoreable {
|
|||
@Override
|
||||
void analyze(Locals locals) {
|
||||
if (write && Modifier.isFinal(field.modifiers)) {
|
||||
throw createError(new IllegalArgumentException(
|
||||
"Cannot write to read-only field [" + field.name + "] for type [" + PainlessLookup.ClassToName(field.clazz) + "]."));
|
||||
throw createError(new IllegalArgumentException("Cannot write to read-only field [" + field.name + "] for type " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(field.clazz) + "]."));
|
||||
}
|
||||
|
||||
actual = field.clazz;
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.WriterConstants;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessClass;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Variable;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -84,8 +84,8 @@ public class SEach extends AStatement {
|
|||
} else if (expression.actual == def.class || Iterable.class.isAssignableFrom(expression.actual)) {
|
||||
sub = new SSubEachIterable(location, variable, expression, block);
|
||||
} else {
|
||||
throw createError(
|
||||
new IllegalArgumentException("Illegal for each type [" + PainlessLookup.ClassToName(expression.actual) + "]."));
|
||||
throw createError(new IllegalArgumentException("Illegal for each type " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(expression.actual) + "]."));
|
||||
}
|
||||
|
||||
sub.analyze(locals);
|
||||
|
|
|
@ -22,8 +22,6 @@ package org.elasticsearch.painless.node;
|
|||
import org.elasticsearch.painless.CompilerSettings;
|
||||
import org.elasticsearch.painless.Constant;
|
||||
import org.elasticsearch.painless.Def;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Parameter;
|
||||
|
@ -31,6 +29,9 @@ import org.elasticsearch.painless.Locals.Variable;
|
|||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.WriterConstants;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.node.SSource.Reserved;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Handle;
|
||||
|
@ -135,7 +136,7 @@ public final class SFunction extends AStatement {
|
|||
try {
|
||||
Class<?> paramType = painlessLookup.getJavaClassFromPainlessType(this.paramTypeStrs.get(param));
|
||||
|
||||
paramClasses[param] = PainlessLookup.defClassToObjectClass(paramType);
|
||||
paramClasses[param] = PainlessLookupUtility.painlessDefTypeToJavaObjectType(paramType);
|
||||
paramTypes.add(paramType);
|
||||
parameters.add(new Parameter(location, paramNameStrs.get(param), paramType));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
|
@ -144,8 +145,8 @@ public final class SFunction extends AStatement {
|
|||
}
|
||||
}
|
||||
|
||||
org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(
|
||||
name, MethodType.methodType(PainlessLookup.defClassToObjectClass(rtnType), paramClasses).toMethodDescriptorString());
|
||||
org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(name, MethodType.methodType(
|
||||
PainlessLookupUtility.painlessDefTypeToJavaObjectType(rtnType), paramClasses).toMethodDescriptorString());
|
||||
this.method = new PainlessMethod(name, null, null, rtnType, paramTypes, method, Modifier.STATIC | Modifier.PRIVATE, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
package org.elasticsearch.painless.node;
|
||||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Variable;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
|
@ -109,6 +109,6 @@ final class SSubEachArray extends AStatement {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return singleLineToString(PainlessLookup.ClassToName(variable.clazz), variable.name, expression, block);
|
||||
return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(variable.clazz), variable.name, expression, block);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,16 +21,16 @@ package org.elasticsearch.painless.node;
|
|||
|
||||
import org.elasticsearch.painless.AnalyzerCaster;
|
||||
import org.elasticsearch.painless.DefBootstrap;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookup;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.elasticsearch.painless.Globals;
|
||||
import org.elasticsearch.painless.Locals;
|
||||
import org.elasticsearch.painless.Locals.Variable;
|
||||
import org.elasticsearch.painless.Location;
|
||||
import org.elasticsearch.painless.MethodWriter;
|
||||
import org.elasticsearch.painless.lookup.PainlessCast;
|
||||
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethod;
|
||||
import org.elasticsearch.painless.lookup.PainlessMethodKey;
|
||||
import org.elasticsearch.painless.lookup.def;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
|
@ -81,8 +81,8 @@ final class SSubEachIterable extends AStatement {
|
|||
getPainlessStructFromJavaClass(expression.actual).methods.get(new PainlessMethodKey("iterator", 0));
|
||||
|
||||
if (method == null) {
|
||||
throw createError(new IllegalArgumentException(
|
||||
"Unable to create iterator for the type [" + PainlessLookup.ClassToName(expression.actual) + "]."));
|
||||
throw createError(new IllegalArgumentException("Unable to create iterator for the type " +
|
||||
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(expression.actual) + "]."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,6 @@ final class SSubEachIterable extends AStatement {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return singleLineToString(PainlessLookup.ClassToName(variable.clazz), variable.name, expression, block);
|
||||
return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(variable.clazz), variable.name, expression, block);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue