|
@@ -0,0 +1,71 @@
|
|
|
+/*
|
|
|
+ * 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.action;
|
|
|
+
|
|
|
+public class PainlessContextTypeInfo {
|
|
|
+ /**
|
|
|
+ * Translates array types from internal java Field Descriptors (JVM Spec 4.3.2) to readable names. Also translates
|
|
|
+ * the fully qualified name of the def type to "def".
|
|
|
+ */
|
|
|
+ public static String getType(String javaType) {
|
|
|
+ int arrayDimensions = 0;
|
|
|
+
|
|
|
+ while (javaType.charAt(arrayDimensions) == '[') {
|
|
|
+ ++arrayDimensions;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (arrayDimensions > 0) {
|
|
|
+ if (javaType.charAt(javaType.length() - 1) == ';') {
|
|
|
+ // Arrays of object types have the form [L<name>; where <name> is the class path, trimming the L & ;
|
|
|
+ javaType = javaType.substring(arrayDimensions + 1, javaType.length() - 1);
|
|
|
+ } else {
|
|
|
+ javaType = javaType.substring(arrayDimensions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("Z".equals(javaType) || "boolean".equals(javaType)) {
|
|
|
+ javaType = "boolean";
|
|
|
+ } else if ("V".equals(javaType) || "void".equals(javaType)) {
|
|
|
+ javaType = "void";
|
|
|
+ } else if ("B".equals(javaType) || "byte".equals(javaType)) {
|
|
|
+ javaType = "byte";
|
|
|
+ } else if ("S".equals(javaType) || "short".equals(javaType)) {
|
|
|
+ javaType = "short";
|
|
|
+ } else if ("C".equals(javaType) || "char".equals(javaType)) {
|
|
|
+ javaType = "char";
|
|
|
+ } else if ("I".equals(javaType) || "int".equals(javaType)) {
|
|
|
+ javaType = "int";
|
|
|
+ } else if ("J".equals(javaType) || "long".equals(javaType)) {
|
|
|
+ javaType = "long";
|
|
|
+ } else if ("F".equals(javaType) || "float".equals(javaType)) {
|
|
|
+ javaType = "float";
|
|
|
+ } else if ("D".equals(javaType) || "double".equals(javaType)) {
|
|
|
+ javaType = "double";
|
|
|
+ } else if ("org.elasticsearch.painless.lookup.def".equals(javaType)) {
|
|
|
+ javaType = "def";
|
|
|
+ }
|
|
|
+
|
|
|
+ while (arrayDimensions-- > 0) {
|
|
|
+ javaType += "[]";
|
|
|
+ }
|
|
|
+
|
|
|
+ return javaType;
|
|
|
+ }
|
|
|
+}
|