From 15740d622971551e6595017be21dc6dc58a6ea84 Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Mon, 16 Jul 2018 16:13:48 -0700 Subject: [PATCH] Painless: Move and Rename Several Methods in the lookup package (#32105) --- .../painless/AnalyzerCaster.java | 7 +- .../java/org/elasticsearch/painless/Def.java | 7 +- .../elasticsearch/painless/FunctionRef.java | 3 +- .../org/elasticsearch/painless/Locals.java | 5 +- .../painless/ScriptClassInfo.java | 3 +- .../painless/antlr/EnhancedPainlessLexer.java | 2 +- .../painless/lookup/PainlessLookup.java | 208 +------------ .../lookup/PainlessLookupBuilder.java | 69 +---- .../lookup/PainlessLookupUtility.java | 284 ++++++++++++++++++ .../painless/lookup/PainlessMethod.java | 14 +- .../painless/node/AExpression.java | 6 +- .../painless/node/EAssignment.java | 4 +- .../elasticsearch/painless/node/EBinary.java | 37 ++- .../painless/node/ECallLocal.java | 4 +- .../painless/node/ECapturingFunctionRef.java | 11 +- .../elasticsearch/painless/node/ECast.java | 6 +- .../elasticsearch/painless/node/EComp.java | 28 +- .../painless/node/EFunctionRef.java | 10 +- .../painless/node/EInstanceof.java | 7 +- .../elasticsearch/painless/node/ELambda.java | 20 +- .../painless/node/EListInit.java | 6 +- .../elasticsearch/painless/node/EMapInit.java | 6 +- .../elasticsearch/painless/node/ENewObj.java | 4 +- .../elasticsearch/painless/node/ENull.java | 4 +- .../elasticsearch/painless/node/EUnary.java | 15 +- .../elasticsearch/painless/node/PBrace.java | 8 +- .../painless/node/PCallInvoke.java | 12 +- .../elasticsearch/painless/node/PField.java | 16 +- .../painless/node/PSubCallInvoke.java | 2 +- .../painless/node/PSubDefArray.java | 2 +- .../painless/node/PSubDefCall.java | 2 +- .../painless/node/PSubDefField.java | 2 +- .../painless/node/PSubField.java | 8 +- .../painless/node/PSubListShortcut.java | 4 +- .../painless/node/PSubMapShortcut.java | 4 +- .../painless/node/PSubShortcut.java | 2 +- .../elasticsearch/painless/node/SEach.java | 8 +- .../painless/node/SFunction.java | 11 +- .../painless/node/SSubEachArray.java | 6 +- .../painless/node/SSubEachIterable.java | 16 +- 40 files changed, 467 insertions(+), 406 deletions(-) create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupUtility.java diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java index 457ec82a5e429..6cfc7ff6ebfd2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java @@ -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 static PainlessCast getLegalCast(Location location, Class actual, Clas (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) + "].")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index f006b57f46bad..78db712d183d2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -19,9 +19,10 @@ 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.PainlessClass; import org.elasticsearch.painless.lookup.PainlessMethodKey; import java.lang.invoke.CallSite; @@ -302,7 +303,7 @@ static MethodHandle lookupMethod(PainlessLookup painlessLookup, MethodHandles.Lo nestedType, 0, DefBootstrap.REFERENCE, - PainlessLookup.ClassToName(interfaceType)); + PainlessLookupUtility.anyTypeToPainlessTypeName(interfaceType)); filter = nested.dynamicInvoker(); } else { throw new AssertionError(); @@ -347,7 +348,7 @@ private static MethodHandle lookupReferenceInternal(PainlessLookup painlessLooku 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java index 6ab7292c7f65b..9e72dc2c83576 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java @@ -21,6 +21,7 @@ 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 @@ private static PainlessMethod lookup(PainlessLookup painlessLookup, Class exp 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 diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java index bab1b7942d657..e797740fed185 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java @@ -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 int getSlot() { @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) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java index df43dba7b3476..ff2061a9a4b92 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java @@ -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 @@ private MethodArgument methodArgument(PainlessLookup painlessLookup, Class cl private static Class definitionTypeForClass(PainlessLookup painlessLookup, Class type, Function, String> unknownErrorMessageSource) { - type = PainlessLookup.ObjectClassTodefClass(type); + type = PainlessLookupUtility.javaObjectTypeToPainlessDefType(type); Class componentType = type; while (componentType.isArray()) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java index e6c5da057980f..f1db35636b41c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java @@ -23,8 +23,8 @@ 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: diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookup.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookup.java index feeaf4d34bcdd..6111d12317b18 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookup.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookup.java @@ -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 @@ */ 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 getStructs() { return javaClassesToPainlessStructs.values(); } @@ -190,6 +41,10 @@ public Collection getStructs() { 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 PainlessClass getPainlessStructFromJavaClass(Class clazz) { } 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); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java index 1dadce318d672..9a5e08d65a754 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java @@ -30,7 +30,6 @@ 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 @@ private void addConstructor(String ownerStructName, WhitelistConstructor whiteli 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 @@ private void addMethod(ClassLoader whitelistClassLoader, String ownerStructName, 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 @@ private void addMethod(ClassLoader whitelistClassLoader, String ownerStructName, "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 @@ private PainlessMethod computeFunctionalInterfaceMethod(PainlessClass clazz) { 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); + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupUtility.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupUtility.java new file mode 100644 index 0000000000000..d1f3ee4ece3e0 --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupUtility.java @@ -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> 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> 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 = ""; + + private PainlessLookupUtility() { + + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessMethod.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessMethod.java index e87e1d4bf38fc..8d8a7f691fecd 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessMethod.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessMethod.java @@ -69,21 +69,21 @@ public MethodType getMethodType() { 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 ("".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 MethodType getMethodType() { 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); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java index 0dfcf4d409335..dd813f73c3dfc 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java @@ -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 @@ AExpression cast(Locals locals) { 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 diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java index a0a29ed59ddde..584e5df6342ab 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java @@ -22,13 +22,13 @@ 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index 422300072dc2f..65776ca76f117 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -21,14 +21,14 @@ 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 @@ private void analyzeMul(Locals variables) { 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 @@ private void analyzeDiv(Locals variables) { 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 @@ private void analyzeRem(Locals variables) { 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 @@ private void analyzeAdd(Locals variables) { 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 @@ private void analyzeSub(Locals variables) { 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 @@ private void analyzeLSH(Locals variables) { 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 @@ private void analyzeRSH(Locals variables) { 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 @@ private void analyzeUSH(Locals variables) { 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 @@ private void analyzeBWAnd(Locals variables) { 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 @@ private void analyzeXor(Locals variables) { 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 @@ private void analyzeBWOr(Locals variables) { 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java index ede1a2a6b9c36..dfed0ca47b482 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index c0345b6308c3e..e8ad9d85ed698 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -21,14 +21,14 @@ 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 @@ void analyze(Locals locals) { 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 @@ void analyze(Locals locals) { // 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 @@ void write(MethodWriter writer, Globals globals) { // 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()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java index 55a9dbf71c891..b0451b685b57d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java @@ -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 @@ void write(MethodWriter writer, Globals globals) { @Override public String toString() { - return singleLineToString(PainlessLookup.ClassToName(cast.to), child); + return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(cast.to), child); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java index 806204d051ae0..edf18f501bc77 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java @@ -21,13 +21,13 @@ 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 @@ private void analyzeEq(Locals variables) { 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 @@ private void analyzeEqR(Locals variables) { 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 @@ private void analyzeNE(Locals variables) { 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 @@ private void analyzeNER(Locals variables) { 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 @@ private void analyzeGTE(Locals variables) { 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 @@ private void analyzeGT(Locals variables) { 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 @@ private void analyzeLTE(Locals variables) { 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 @@ private void analyzeLT(Locals variables) { 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) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java index 82c24e27c5d16..d4eddb059a847 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java @@ -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 @@ void analyze(Locals locals) { 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); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java index a3835cbc21372..05564a2952e6f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java @@ -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 @@ void analyze(Locals locals) { } // 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 @@ void analyze(Locals locals) { 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; } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index 8977f4f0ef329..8e8d164b03d62 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -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 @@ void analyze(Locals locals) { // 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 @@ void analyze(Locals locals) { 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 @@ void analyze(Locals locals) { List paramTypes = new ArrayList<>(captures.size() + actualParamTypeStrs.size()); List 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())); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java index 820cce685edcd..90475419b3260 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java index b6c7fb80af95f..c6474846d4c7a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java index 197e2fcb7fd42..a780ea3e05be8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java index 983819b6b2bf9..6bc5331cb1d84 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java @@ -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 @@ void analyze(Locals locals) { 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java index 3a5102ebdc99c..d34399db779df 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java @@ -21,13 +21,13 @@ 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 @@ void analyzeBWNot(Locals variables) { 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 @@ void analyzerAdd(Locals variables) { 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 @@ void analyzerSub(Locals variables) { 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java index 5b282abdce9fa..c45107a37ac21 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java @@ -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 @@ void analyze(Locals locals) { } 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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java index f23ae9f188704..445c053347ec3 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java @@ -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 @@ void analyze(Locals locals) { 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()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java index 78a18b91ab2c6..3f2f887956491 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java @@ -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 @@ void analyze(Locals locals) { 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 @@ void analyze(Locals locals) { 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 @@ void analyze(Locals locals) { 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) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java index 66ad0ecff1b89..237efa61ffa7d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java index ccbc25db4f25e..afad497dec7d9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java index a9021000e2dad..7f4e253b4090d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java index 1c081c9422ecb..bf00d8d859988 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java index d6c367cfeabec..8eb154e745bf7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java @@ -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 @@ void extractVariables(Set variables) { @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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java index 5d881b30db22d..0a3ab142ddc7c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java index 4875d55cbeb58..f71e2ac5d1fa0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java index 4b2910dbc010e..eb5668c554c20 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java @@ -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; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index c402d8982d89e..de1a7062a24f2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -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 @@ void analyze(Locals locals) { } 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); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 628bb1d32d59e..1c801d509b581 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -22,8 +22,6 @@ 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.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 @@ void generateSignature(PainlessLookup painlessLookup) { 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 @@ void generateSignature(PainlessLookup painlessLookup) { } } - 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); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java index 5db161b8002a4..fea8c8953b67f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java @@ -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 @@ void write(MethodWriter writer, Globals globals) { @Override public String toString() { - return singleLineToString(PainlessLookup.ClassToName(variable.clazz), variable.name, expression, block); + return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(variable.clazz), variable.name, expression, block); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java index cfc87536b6b7b..cec1297a4c41c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java @@ -21,16 +21,16 @@ 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 @@ void analyze(Locals locals) { 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 @@ void write(MethodWriter writer, Globals globals) { @Override public String toString() { - return singleLineToString(PainlessLookup.ClassToName(variable.clazz), variable.name, expression, block); + return singleLineToString(PainlessLookupUtility.anyTypeToPainlessTypeName(variable.clazz), variable.name, expression, block); } }