Painless: Change fqn_only to no_import (#32817)
This changes the whitelist parameter fqn_only to no_import when specifying that a whitelisted class must have the fully-qualified-name instead of a shortcut name. This more closely correlates with Java imports, hence the rename.
This commit is contained in:
parent
84aa87f638
commit
ab7e7508f5
|
@ -53,7 +53,7 @@ public final class WhitelistLoader {
|
||||||
* a Painless type name with the exception that any dollar symbols used as part of inner classes will
|
* a Painless type name with the exception that any dollar symbols used as part of inner classes will
|
||||||
* be replaced with dot symbols. </li>
|
* be replaced with dot symbols. </li>
|
||||||
* <li> short Java type name - The text after the final dot symbol of any specified Java class. A
|
* <li> short Java type name - The text after the final dot symbol of any specified Java class. A
|
||||||
* short type Java name may be excluded by using the 'only_fqn' token during Painless class parsing
|
* short type Java name may be excluded by using the 'no_import' token during Painless class parsing
|
||||||
* as described later. </li>
|
* as described later. </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
@ -65,7 +65,7 @@ public final class WhitelistLoader {
|
||||||
* <li> Primitive types may be specified starting with 'class' and followed by the Java type name,
|
* <li> Primitive types may be specified starting with 'class' and followed by the Java type name,
|
||||||
* an opening bracket, a newline, a closing bracket, and a final newline. </li>
|
* an opening bracket, a newline, a closing bracket, and a final newline. </li>
|
||||||
* <li> Complex types may be specified starting with 'class' and followed the fully-qualified Java
|
* <li> Complex types may be specified starting with 'class' and followed the fully-qualified Java
|
||||||
* class name, optionally followed by an 'only_fqn' token, an opening bracket, a newline,
|
* class name, optionally followed by an 'no_import' token, an opening bracket, a newline,
|
||||||
* constructor/method/field specifications, a closing bracket, and a final newline. Within a complex
|
* constructor/method/field specifications, a closing bracket, and a final newline. Within a complex
|
||||||
* type the following may be parsed:
|
* type the following may be parsed:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
@ -109,7 +109,7 @@ public final class WhitelistLoader {
|
||||||
*
|
*
|
||||||
* # complex types
|
* # complex types
|
||||||
*
|
*
|
||||||
* class my.package.Example only_fqn {
|
* class my.package.Example no_import {
|
||||||
* # constructors
|
* # constructors
|
||||||
* ()
|
* ()
|
||||||
* (int)
|
* (int)
|
||||||
|
@ -145,7 +145,7 @@ public final class WhitelistLoader {
|
||||||
|
|
||||||
String whitelistClassOrigin = null;
|
String whitelistClassOrigin = null;
|
||||||
String javaClassName = null;
|
String javaClassName = null;
|
||||||
boolean onlyFQNJavaClassName = false;
|
boolean noImport = false;
|
||||||
List<WhitelistConstructor> whitelistConstructors = null;
|
List<WhitelistConstructor> whitelistConstructors = null;
|
||||||
List<WhitelistMethod> whitelistMethods = null;
|
List<WhitelistMethod> whitelistMethods = null;
|
||||||
List<WhitelistField> whitelistFields = null;
|
List<WhitelistField> whitelistFields = null;
|
||||||
|
@ -160,7 +160,7 @@ public final class WhitelistLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a new class by resetting all the variables necessary to construct a new WhitelistClass for the whitelist.
|
// Handle a new class by resetting all the variables necessary to construct a new WhitelistClass for the whitelist.
|
||||||
// Expects the following format: 'class' ID 'only_fqn'? '{' '\n'
|
// Expects the following format: 'class' ID 'no_import'? '{' '\n'
|
||||||
if (line.startsWith("class ")) {
|
if (line.startsWith("class ")) {
|
||||||
// Ensure the final token of the line is '{'.
|
// Ensure the final token of the line is '{'.
|
||||||
if (line.endsWith("{") == false) {
|
if (line.endsWith("{") == false) {
|
||||||
|
@ -172,8 +172,8 @@ public final class WhitelistLoader {
|
||||||
String[] tokens = line.substring(5, line.length() - 1).trim().split("\\s+");
|
String[] tokens = line.substring(5, line.length() - 1).trim().split("\\s+");
|
||||||
|
|
||||||
// Ensure the correct number of tokens.
|
// Ensure the correct number of tokens.
|
||||||
if (tokens.length == 2 && "only_fqn".equals(tokens[1])) {
|
if (tokens.length == 2 && "no_import".equals(tokens[1])) {
|
||||||
onlyFQNJavaClassName = true;
|
noImport = true;
|
||||||
} else if (tokens.length != 1) {
|
} else if (tokens.length != 1) {
|
||||||
throw new IllegalArgumentException("invalid class definition: failed to parse class name [" + line + "]");
|
throw new IllegalArgumentException("invalid class definition: failed to parse class name [" + line + "]");
|
||||||
}
|
}
|
||||||
|
@ -194,13 +194,13 @@ public final class WhitelistLoader {
|
||||||
throw new IllegalArgumentException("invalid class definition: extraneous closing bracket");
|
throw new IllegalArgumentException("invalid class definition: extraneous closing bracket");
|
||||||
}
|
}
|
||||||
|
|
||||||
whitelistClasses.add(new WhitelistClass(whitelistClassOrigin, javaClassName, onlyFQNJavaClassName,
|
whitelistClasses.add(new WhitelistClass(whitelistClassOrigin, javaClassName, noImport,
|
||||||
whitelistConstructors, whitelistMethods, whitelistFields));
|
whitelistConstructors, whitelistMethods, whitelistFields));
|
||||||
|
|
||||||
// Set all the variables to null to ensure a new class definition is found before other parsable values.
|
// Set all the variables to null to ensure a new class definition is found before other parsable values.
|
||||||
whitelistClassOrigin = null;
|
whitelistClassOrigin = null;
|
||||||
javaClassName = null;
|
javaClassName = null;
|
||||||
onlyFQNJavaClassName = false;
|
noImport = false;
|
||||||
whitelistConstructors = null;
|
whitelistConstructors = null;
|
||||||
whitelistMethods = null;
|
whitelistMethods = null;
|
||||||
whitelistFields = null;
|
whitelistFields = null;
|
||||||
|
|
|
@ -293,7 +293,7 @@ public final class PainlessLookupBuilder {
|
||||||
|
|
||||||
if (canonicalClassName.equals(importedCanonicalClassName)) {
|
if (canonicalClassName.equals(importedCanonicalClassName)) {
|
||||||
if (importClassName == true) {
|
if (importClassName == true) {
|
||||||
throw new IllegalArgumentException("must use only_fqn parameter on class [" + canonicalClassName + "] with no package");
|
throw new IllegalArgumentException("must use no_import parameter on class [" + canonicalClassName + "] with no package");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Class<?> importedPainlessClass = canonicalClassNamesToClasses.get(importedCanonicalClassName);
|
Class<?> importedPainlessClass = canonicalClassNamesToClasses.get(importedCanonicalClassName);
|
||||||
|
@ -301,7 +301,8 @@ public final class PainlessLookupBuilder {
|
||||||
if (importedPainlessClass == null) {
|
if (importedPainlessClass == null) {
|
||||||
if (importClassName) {
|
if (importClassName) {
|
||||||
if (existingPainlessClassBuilder != null) {
|
if (existingPainlessClassBuilder != null) {
|
||||||
throw new IllegalArgumentException("inconsistent only_fqn parameters found for class [" + canonicalClassName + "]");
|
throw new IllegalArgumentException(
|
||||||
|
"inconsistent no_import parameters found for class [" + canonicalClassName + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
canonicalClassNamesToClasses.put(importedCanonicalClassName, clazz);
|
canonicalClassNamesToClasses.put(importedCanonicalClassName, clazz);
|
||||||
|
@ -310,7 +311,7 @@ public final class PainlessLookupBuilder {
|
||||||
throw new IllegalArgumentException("imported class [" + importedCanonicalClassName + "] cannot represent multiple " +
|
throw new IllegalArgumentException("imported class [" + importedCanonicalClassName + "] cannot represent multiple " +
|
||||||
"classes [" + canonicalClassName + "] and [" + typeToCanonicalTypeName(importedPainlessClass) + "]");
|
"classes [" + canonicalClassName + "] and [" + typeToCanonicalTypeName(importedPainlessClass) + "]");
|
||||||
} else if (importClassName == false) {
|
} else if (importClassName == false) {
|
||||||
throw new IllegalArgumentException("inconsistent only_fqn parameters found for class [" + canonicalClassName + "]");
|
throw new IllegalArgumentException("inconsistent no_import parameters found for class [" + canonicalClassName + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,31 +24,31 @@
|
||||||
|
|
||||||
#### Primitive types
|
#### Primitive types
|
||||||
|
|
||||||
class void only_fqn {
|
class void no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class boolean only_fqn {
|
class boolean no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class byte only_fqn {
|
class byte no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class short only_fqn {
|
class short no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class char only_fqn {
|
class char no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class int only_fqn {
|
class int no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class long only_fqn {
|
class long no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class float only_fqn {
|
class float no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
class double only_fqn {
|
class double no_import {
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Painless debugging API
|
#### Painless debugging API
|
||||||
|
@ -134,7 +134,7 @@ class org.elasticsearch.index.mapper.IpFieldMapper$IpFieldType$IpScriptDocValues
|
||||||
|
|
||||||
# for testing.
|
# for testing.
|
||||||
# currently FeatureTest exposes overloaded constructor, field load store, and overloaded static methods
|
# currently FeatureTest exposes overloaded constructor, field load store, and overloaded static methods
|
||||||
class org.elasticsearch.painless.FeatureTest only_fqn {
|
class org.elasticsearch.painless.FeatureTest no_import {
|
||||||
int z
|
int z
|
||||||
()
|
()
|
||||||
(int,int)
|
(int,int)
|
||||||
|
|
Loading…
Reference in New Issue