Skip to content

Commit 3f46cbc

Browse files
committed
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.
1 parent 516fdba commit 3f46cbc

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/WhitelistLoader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class WhitelistLoader {
5353
* a Painless type name with the exception that any dollar symbols used as part of inner classes will
5454
* be replaced with dot symbols. </li>
5555
* <li> short Java type name - The text after the final dot symbol of any specified Java class. A
56-
* short type Java name may be excluded by using the 'only_fqn' token during Painless class parsing
56+
* short type Java name may be excluded by using the 'no_import' token during Painless class parsing
5757
* as described later. </li>
5858
* </ul>
5959
*
@@ -65,7 +65,7 @@ public final class WhitelistLoader {
6565
* <li> Primitive types may be specified starting with 'class' and followed by the Java type name,
6666
* an opening bracket, a newline, a closing bracket, and a final newline. </li>
6767
* <li> Complex types may be specified starting with 'class' and followed the fully-qualified Java
68-
* class name, optionally followed by an 'only_fqn' token, an opening bracket, a newline,
68+
* class name, optionally followed by an 'no_import' token, an opening bracket, a newline,
6969
* constructor/method/field specifications, a closing bracket, and a final newline. Within a complex
7070
* type the following may be parsed:
7171
* <ul>
@@ -109,7 +109,7 @@ public final class WhitelistLoader {
109109
*
110110
* # complex types
111111
*
112-
* class my.package.Example only_fqn {
112+
* class my.package.Example no_import {
113113
* # constructors
114114
* ()
115115
* (int)
@@ -145,7 +145,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
145145

146146
String whitelistClassOrigin = null;
147147
String javaClassName = null;
148-
boolean onlyFQNJavaClassName = false;
148+
boolean noImport = false;
149149
List<WhitelistConstructor> whitelistConstructors = null;
150150
List<WhitelistMethod> whitelistMethods = null;
151151
List<WhitelistField> whitelistFields = null;
@@ -160,7 +160,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
160160
}
161161

162162
// Handle a new class by resetting all the variables necessary to construct a new WhitelistClass for the whitelist.
163-
// Expects the following format: 'class' ID 'only_fqn'? '{' '\n'
163+
// Expects the following format: 'class' ID 'no_import'? '{' '\n'
164164
if (line.startsWith("class ")) {
165165
// Ensure the final token of the line is '{'.
166166
if (line.endsWith("{") == false) {
@@ -172,8 +172,8 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
172172
String[] tokens = line.substring(5, line.length() - 1).trim().split("\\s+");
173173

174174
// Ensure the correct number of tokens.
175-
if (tokens.length == 2 && "only_fqn".equals(tokens[1])) {
176-
onlyFQNJavaClassName = true;
175+
if (tokens.length == 2 && "no_import".equals(tokens[1])) {
176+
noImport = true;
177177
} else if (tokens.length != 1) {
178178
throw new IllegalArgumentException("invalid class definition: failed to parse class name [" + line + "]");
179179
}
@@ -194,13 +194,13 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
194194
throw new IllegalArgumentException("invalid class definition: extraneous closing bracket");
195195
}
196196

197-
whitelistClasses.add(new WhitelistClass(whitelistClassOrigin, javaClassName, onlyFQNJavaClassName,
197+
whitelistClasses.add(new WhitelistClass(whitelistClassOrigin, javaClassName, noImport,
198198
whitelistConstructors, whitelistMethods, whitelistFields));
199199

200200
// Set all the variables to null to ensure a new class definition is found before other parsable values.
201201
whitelistClassOrigin = null;
202202
javaClassName = null;
203-
onlyFQNJavaClassName = false;
203+
noImport = false;
204204
whitelistConstructors = null;
205205
whitelistMethods = null;
206206
whitelistFields = null;

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,16 @@ public void addPainlessClass(Class<?> clazz, boolean importClassName) {
293293

294294
if (canonicalClassName.equals(importedCanonicalClassName)) {
295295
if (importClassName == true) {
296-
throw new IllegalArgumentException("must use only_fqn parameter on class [" + canonicalClassName + "] with no package");
296+
throw new IllegalArgumentException("must use no_import parameter on class [" + canonicalClassName + "] with no package");
297297
}
298298
} else {
299299
Class<?> importedPainlessClass = canonicalClassNamesToClasses.get(importedCanonicalClassName);
300300

301301
if (importedPainlessClass == null) {
302302
if (importClassName) {
303303
if (existingPainlessClassBuilder != null) {
304-
throw new IllegalArgumentException("inconsistent only_fqn parameters found for class [" + canonicalClassName + "]");
304+
throw new IllegalArgumentException(
305+
"inconsistent no_import parameters found for class [" + canonicalClassName + "]");
305306
}
306307

307308
canonicalClassNamesToClasses.put(importedCanonicalClassName, clazz);
@@ -310,7 +311,7 @@ public void addPainlessClass(Class<?> clazz, boolean importClassName) {
310311
throw new IllegalArgumentException("imported class [" + importedCanonicalClassName + "] cannot represent multiple " +
311312
"classes [" + canonicalClassName + "] and [" + typeToCanonicalTypeName(importedPainlessClass) + "]");
312313
} else if (importClassName == false) {
313-
throw new IllegalArgumentException("inconsistent only_fqn parameters found for class [" + canonicalClassName + "]");
314+
throw new IllegalArgumentException("inconsistent no_import parameters found for class [" + canonicalClassName + "]");
314315
}
315316
}
316317
}

modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@
2424

2525
#### Primitive types
2626

27-
class void only_fqn {
27+
class void no_import {
2828
}
2929

30-
class boolean only_fqn {
30+
class boolean no_import {
3131
}
3232

33-
class byte only_fqn {
33+
class byte no_import {
3434
}
3535

36-
class short only_fqn {
36+
class short no_import {
3737
}
3838

39-
class char only_fqn {
39+
class char no_import {
4040
}
4141

42-
class int only_fqn {
42+
class int no_import {
4343
}
4444

45-
class long only_fqn {
45+
class long no_import {
4646
}
4747

48-
class float only_fqn {
48+
class float no_import {
4949
}
5050

51-
class double only_fqn {
51+
class double no_import {
5252
}
5353

5454
#### Painless debugging API
@@ -138,7 +138,7 @@ class org.elasticsearch.index.mapper.IpFieldMapper$IpFieldType$IpScriptDocValues
138138

139139
# for testing.
140140
# currently FeatureTest exposes overloaded constructor, field load store, and overloaded static methods
141-
class org.elasticsearch.painless.FeatureTest only_fqn {
141+
class org.elasticsearch.painless.FeatureTest no_import {
142142
int z
143143
()
144144
(int,int)

0 commit comments

Comments
 (0)