Skip to content

Commit 47d2bcc

Browse files
authored
Painless: Clean Up Whitelist Names (elastic#32791)
Renames variables in the whitelists to match the current naming scheme. Mechanical change.
1 parent cb1d467 commit 47d2bcc

File tree

8 files changed

+109
-109
lines changed

8 files changed

+109
-109
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* constructors, methods, and fields that can be used within a Painless script at both compile-time
2929
* and run-time.
3030
*
31-
* A whitelist consists of several pieces with {@link WhitelistClass}s as the top level. Each
31+
* A whitelist consists of several pieces with {@link WhitelistClass}s as the top level. Each
3232
* {@link WhitelistClass} will contain zero-to-many {@link WhitelistConstructor}s, {@link WhitelistMethod}s, and
3333
* {@link WhitelistField}s which are what will be available with a Painless script. See each individual
3434
* whitelist object for more detail.
@@ -56,14 +56,14 @@ public final class Whitelist {
5656
Collections.singletonList(WhitelistLoader.loadFromResourceFiles(Whitelist.class, BASE_WHITELIST_FILES));
5757

5858
/** The {@link ClassLoader} used to look up the whitelisted Java classes, constructors, methods, and fields. */
59-
public final ClassLoader javaClassLoader;
59+
public final ClassLoader classLoader;
6060

6161
/** The {@link List} of all the whitelisted Painless classes. */
62-
public final List<WhitelistClass> whitelistStructs;
62+
public final List<WhitelistClass> whitelistClasses;
6363

6464
/** Standard constructor. All values must be not {@code null}. */
65-
public Whitelist(ClassLoader javaClassLoader, List<WhitelistClass> whitelistStructs) {
66-
this.javaClassLoader = Objects.requireNonNull(javaClassLoader);
67-
this.whitelistStructs = Collections.unmodifiableList(Objects.requireNonNull(whitelistStructs));
65+
public Whitelist(ClassLoader classLoader, List<WhitelistClass> whitelistClasses) {
66+
this.classLoader = Objects.requireNonNull(classLoader);
67+
this.whitelistClasses = Collections.unmodifiableList(Objects.requireNonNull(whitelistClasses));
6868
}
6969
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* specific context, as long as multiple classes representing the same Java class have the same
3131
* class name and have legal constructor/method overloading they can be merged together.
3232
*
33-
* Classes in Painless allow for arity overloading for constructors and methods. Arity overloading
33+
* Classes in Painless allow for arity overloading for constructors and methods. Arity overloading
3434
* means that multiple constructors are allowed for a single class as long as they have a different
3535
* number of parameters, and multiples methods with the same name are allowed for a single class
3636
* as long as they have the same return type and a different number of parameters.
@@ -40,7 +40,7 @@
4040
*/
4141
public final class WhitelistClass {
4242

43-
/** Information about where this class was white-listed from. Can be used for error messages. */
43+
/** Information about where this class was white-listed from. */
4444
public final String origin;
4545

4646
/** The Java class name this class represents. */
@@ -49,7 +49,7 @@ public final class WhitelistClass {
4949
/**
5050
* Allow the Java class name to only be specified as the fully-qualified name.
5151
*/
52-
public final boolean onlyFQNJavaClassName;
52+
public final boolean noImport;
5353

5454
/** The {@link List} of whitelisted ({@link WhitelistConstructor}s) available to this class. */
5555
public final List<WhitelistConstructor> whitelistConstructors;
@@ -61,13 +61,14 @@ public final class WhitelistClass {
6161
public final List<WhitelistField> whitelistFields;
6262

6363
/** Standard constructor. All values must be not {@code null}. */
64-
public WhitelistClass(String origin, String javaClassName, boolean onlyFQNJavaClassName,
64+
public WhitelistClass(String origin, String javaClassName, boolean noImport,
6565
List<WhitelistConstructor> whitelistConstructors,
6666
List<WhitelistMethod> whitelistMethods,
6767
List<WhitelistField> whitelistFields) {
68+
6869
this.origin = Objects.requireNonNull(origin);
6970
this.javaClassName = Objects.requireNonNull(javaClassName);
70-
this.onlyFQNJavaClassName = onlyFQNJavaClassName;
71+
this.noImport = noImport;
7172

7273
this.whitelistConstructors = Collections.unmodifiableList(Objects.requireNonNull(whitelistConstructors));
7374
this.whitelistMethods = Collections.unmodifiableList(Objects.requireNonNull(whitelistMethods));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525

2626
/**
2727
* Constructor represents the equivalent of a Java constructor available as a whitelisted class
28-
* constructor within Painless. Constructors for Painless classes may be accessed exactly as
29-
* constructors for Java classes are using the 'new' keyword. Painless classes may have multiple
28+
* constructor within Painless. Constructors for Painless classes may be accessed exactly as
29+
* constructors for Java classes are using the 'new' keyword. Painless classes may have multiple
3030
* constructors as long as they comply with arity overloading described for {@link WhitelistClass}.
3131
*/
3232
public final class WhitelistConstructor {
3333

34-
/** Information about where this constructor was whitelisted from. Can be used for error messages. */
34+
/** Information about where this constructor was whitelisted from. */
3535
public final String origin;
3636

3737
/**
3838
* A {@link List} of {@link String}s that are the Painless type names for the parameters of the
3939
* constructor which can be used to look up the Java constructor through reflection.
4040
*/
41-
public final List<String> painlessParameterTypeNames;
41+
public final List<String> canonicalTypeNameParameters;
4242

4343
/** Standard constructor. All values must be not {@code null}. */
44-
public WhitelistConstructor(String origin, List<String> painlessParameterTypeNames) {
44+
public WhitelistConstructor(String origin, List<String> canonicalTypeNameParameters) {
4545
this.origin = Objects.requireNonNull(origin);
46-
this.painlessParameterTypeNames = Collections.unmodifiableList(Objects.requireNonNull(painlessParameterTypeNames));
46+
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
4747
}
4848
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323

2424
/**
2525
* Field represents the equivalent of a Java field available as a whitelisted class field
26-
* within Painless. Fields for Painless classes may be accessed exactly as fields for Java classes
26+
* within Painless. Fields for Painless classes may be accessed exactly as fields for Java classes
2727
* are using the '.' operator on an existing class variable/field.
2828
*/
2929
public class WhitelistField {
3030

31-
/** Information about where this method was whitelisted from. Can be used for error messages. */
31+
/** Information about where this method was whitelisted from. */
3232
public final String origin;
3333

34-
/** The Java field name used to look up the Java field through reflection. */
35-
public final String javaFieldName;
34+
/** The field name used to look up the field reflection object. */
35+
public final String fieldName;
3636

37-
/** The Painless type name for the field which can be used to look up the Java field through reflection. */
38-
public final String painlessFieldTypeName;
37+
/** The canonical type name for the field which can be used to look up the Java field through reflection. */
38+
public final String canonicalTypeNameParameter;
3939

4040
/** Standard constructor. All values must be not {@code null}. */
41-
public WhitelistField(String origin, String javaFieldName, String painlessFieldTypeName) {
41+
public WhitelistField(String origin, String fieldName, String canonicalTypeNameParameter) {
4242
this.origin = Objects.requireNonNull(origin);
43-
this.javaFieldName = Objects.requireNonNull(javaFieldName);
44-
this.painlessFieldTypeName = Objects.requireNonNull(painlessFieldTypeName);
43+
this.fieldName = Objects.requireNonNull(fieldName);
44+
this.canonicalTypeNameParameter = Objects.requireNonNull(canonicalTypeNameParameter);
4545
}
4646
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
public final class WhitelistLoader {
3636

3737
/**
38-
* Loads and creates a {@link Whitelist} from one to many text files. The file paths are passed in as an array of
38+
* Loads and creates a {@link Whitelist} from one to many text files. The file paths are passed in as an array of
3939
* {@link String}s with a single {@link Class} to be be used to load the resources where each {@link String}
40-
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
40+
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
4141
* reflection objects for each individual {@link Class}, {@link Constructor}, {@link Method}, and {@link Field}
4242
* specified as part of the whitelist in the text file.
4343
*
4444
* A single pass is made through each file to collect all the information about each class, constructor, method,
45-
* and field. Most validation will be done at a later point after all whitelists have been gathered and their
45+
* and field. Most validation will be done at a later point after all whitelists have been gathered and their
4646
* merging takes place.
4747
*
4848
* A painless type name is one of the following:
@@ -52,15 +52,15 @@ public final class WhitelistLoader {
5252
* <li> fully-qualified Java type name - Any whitelisted Java class will have the equivalent name as
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>
55-
* <li> short Java type name - The text after the final dot symbol of any specified Java class. A
55+
* <li> short Java type name - The text after the final dot symbol of any specified Java class. A
5656
* short type Java name may be excluded by using the 'only_fqn' token during Painless class parsing
5757
* as described later. </li>
5858
* </ul>
5959
*
6060
* The following can be parsed from each whitelist text file:
6161
* <ul>
6262
* <li> Blank lines will be ignored by the parser. </li>
63-
* <li> Comments may be created starting with a pound '#' symbol and end with a newline. These will
63+
* <li> Comments may be created starting with a pound '#' symbol and end with a newline. These will
6464
* be ignored by the parser. </li>
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>
@@ -93,10 +93,10 @@ public final class WhitelistLoader {
9393
*
9494
* Note there must be a one-to-one correspondence of Painless type names to Java type/class names.
9595
* If the same Painless type is defined across multiple files and the Java class is the same, all
96-
* specified constructors, methods, and fields will be merged into a single Painless type. The
96+
* specified constructors, methods, and fields will be merged into a single Painless type. The
9797
* Painless dynamic type, 'def', used as part of constructor, method, and field definitions will
98-
* be appropriately parsed and handled. Painless complex types must be specified with the
99-
* fully-qualified Java class name. Method argument types, method return types, and field types
98+
* be appropriately parsed and handled. Painless complex types must be specified with the
99+
* fully-qualified Java class name. Method argument types, method return types, and field types
100100
* must be specified with Painless type names (def, fully-qualified, or short) as described earlier.
101101
*
102102
* The following example is used to create a single whitelist text file:
@@ -132,7 +132,7 @@ public final class WhitelistLoader {
132132
* }
133133
*/
134134
public static Whitelist loadFromResourceFiles(Class<?> resource, String... filepaths) {
135-
List<WhitelistClass> whitelistStructs = new ArrayList<>();
135+
List<WhitelistClass> whitelistClasses = new ArrayList<>();
136136

137137
// Execute a single pass through the whitelist text files. This will gather all the
138138
// constructors, methods, augmented methods, and fields for each whitelisted class.
@@ -143,7 +143,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
143143
try (LineNumberReader reader = new LineNumberReader(
144144
new InputStreamReader(resource.getResourceAsStream(filepath), StandardCharsets.UTF_8))) {
145145

146-
String whitelistStructOrigin = null;
146+
String whitelistClassOrigin = null;
147147
String javaClassName = null;
148148
boolean onlyFQNJavaClassName = false;
149149
List<WhitelistConstructor> whitelistConstructors = null;
@@ -178,7 +178,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
178178
throw new IllegalArgumentException("invalid class definition: failed to parse class name [" + line + "]");
179179
}
180180

181-
whitelistStructOrigin = "[" + filepath + "]:[" + number + "]";
181+
whitelistClassOrigin = "[" + filepath + "]:[" + number + "]";
182182
javaClassName = tokens[0];
183183

184184
// Reset all the constructors, methods, and fields to support a new class.
@@ -194,11 +194,11 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
194194
throw new IllegalArgumentException("invalid class definition: extraneous closing bracket");
195195
}
196196

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

200200
// Set all the variables to null to ensure a new class definition is found before other parsable values.
201-
whitelistStructOrigin = null;
201+
whitelistClassOrigin = null;
202202
javaClassName = null;
203203
onlyFQNJavaClassName = false;
204204
whitelistConstructors = null;
@@ -300,7 +300,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
300300
}
301301
ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>)resource::getClassLoader);
302302

303-
return new Whitelist(loader, whitelistStructs);
303+
return new Whitelist(loader, whitelistClasses);
304304
}
305305

306306
private WhitelistLoader() {}

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,53 @@
2525

2626
/**
2727
* Method represents the equivalent of a Java method available as a whitelisted class method
28-
* within Painless. Methods for Painless classes may be accessed exactly as methods for Java classes
29-
* are using the '.' operator on an existing class variable/field. Painless classes may have multiple
30-
* methods with the same name as long as they comply with arity overloading described for {@link WhitelistMethod}.
28+
* within Painless. Methods for Painless classes may be accessed exactly as methods for Java classes
29+
* are using the '.' operator on an existing class variable/field. Painless classes may have multiple
30+
* methods with the same name as long as they comply with arity overloading described in
31+
* {@link WhitelistClass}.
3132
*
3233
* Classes may also have additional methods that are not part of the Java class the class represents -
33-
* these are known as augmented methods. An augmented method can be added to a class as a part of any
34+
* these are known as augmented methods. An augmented method can be added to a class as a part of any
3435
* Java class as long as the method is static and the first parameter of the method is the Java class
35-
* represented by the class. Note that the augmented method's parent Java class does not need to be
36+
* represented by the class. Note that the augmented method's parent Java class does not need to be
3637
* whitelisted.
3738
*/
3839
public class WhitelistMethod {
3940

40-
/** Information about where this method was whitelisted from. Can be used for error messages. */
41+
/** Information about where this method was whitelisted from. */
4142
public final String origin;
4243

4344
/**
44-
* The Java class name for the owner of an augmented method. If the method is not augmented
45+
* The class name for the owner of an augmented method. If the method is not augmented
4546
* this should be {@code null}.
4647
*/
47-
public final String javaAugmentedClassName;
48+
public final String augmentedCanonicalClassName;
4849

49-
/** The Java method name used to look up the Java method through reflection. */
50-
public final String javaMethodName;
50+
/** The method name used to look up the method reflection object. */
51+
public final String methodName;
5152

5253
/**
53-
* The Painless type name for the return type of the method which can be used to look up the Java
54-
* method through reflection.
54+
* The canonical type name for the return type.
5555
*/
56-
public final String painlessReturnTypeName;
56+
public final String returnCanonicalTypeName;
5757

5858
/**
59-
* A {@link List} of {@link String}s that are the Painless type names for the parameters of the
60-
* method which can be used to look up the Java method through reflection.
59+
* A {@link List} of {@link String}s that are the canonical type names for the parameters of the
60+
* method used to look up the method reflection object.
6161
*/
62-
public final List<String> painlessParameterTypeNames;
62+
public final List<String> canonicalTypeNameParameters;
6363

6464
/**
65-
* Standard constructor. All values must be not {@code null} with the exception of jAugmentedClass;
66-
* jAugmentedClass will be {@code null} unless the method is augmented as described in the class documentation.
65+
* Standard constructor. All values must be not {@code null} with the exception of
66+
* augmentedCanonicalClassName; augmentedCanonicalClassName will be {@code null} unless the method
67+
* is augmented as described in the class documentation.
6768
*/
68-
public WhitelistMethod(String origin, String javaAugmentedClassName, String javaMethodName,
69-
String painlessReturnTypeName, List<String> painlessParameterTypeNames) {
69+
public WhitelistMethod(String origin, String augmentedCanonicalClassName, String methodName,
70+
String returnCanonicalTypeName, List<String> canonicalTypeNameParameters) {
7071
this.origin = Objects.requireNonNull(origin);
71-
this.javaAugmentedClassName = javaAugmentedClassName;
72-
this.javaMethodName = javaMethodName;
73-
this.painlessReturnTypeName = Objects.requireNonNull(painlessReturnTypeName);
74-
this.painlessParameterTypeNames = Collections.unmodifiableList(Objects.requireNonNull(painlessParameterTypeNames));
72+
this.augmentedCanonicalClassName = augmentedCanonicalClassName;
73+
this.methodName = methodName;
74+
this.returnCanonicalTypeName = Objects.requireNonNull(returnCanonicalTypeName);
75+
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
7576
}
7677
}

0 commit comments

Comments
 (0)