Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painless: Clean Up Whitelist Names #32791

Merged
merged 92 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
1419751
Parially added constructor.
jdconrad Jul 26, 2018
6469598
Add method type to method.
jdconrad Jul 27, 2018
54b8992
Merge branch 'master' into clean18
jdconrad Jul 27, 2018
8581deb
Merge branch 'clean16' into clean19
jdconrad Jul 27, 2018
641c383
Add PainlessConstructor.
jdconrad Jul 27, 2018
5b449d8
Clean up method.
jdconrad Jul 27, 2018
3c5db32
Merge branch 'master' into clean19
jdconrad Jul 27, 2018
c19b95d
Merge branch 'clean19' into clean20
jdconrad Jul 27, 2018
266a92d
Fixes.
jdconrad Jul 27, 2018
2875c48
Clean up fields.
jdconrad Jul 27, 2018
3f17455
Merge branch 'master' into clean19
jdconrad Jul 30, 2018
b9299d6
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
aa833d9
Merge branch 'clean20' into clean21
jdconrad Jul 30, 2018
0c9c174
Reponse to PR comments.
jdconrad Jul 30, 2018
683361a
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
6757987
Merge branch 'clean20' into clean21
jdconrad Jul 30, 2018
ccabb90
Merge branch 'master' into clean19
jdconrad Jul 30, 2018
55004f1
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
9ca9381
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
f379f2d
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
98995f2
Start to clean up PainlessLookup.
jdconrad Jul 31, 2018
8bd9a28
Complete method lookup.
jdconrad Jul 31, 2018
6eaca81
Add lookup constructor.
jdconrad Jul 31, 2018
aab122a
Add field lookup.
jdconrad Jul 31, 2018
509e607
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
aff5c3e
Reponse to PR comments.
jdconrad Jul 31, 2018
dbc3e27
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
43d5e49
Merge branch 'clean21' into clean22
jdconrad Jul 31, 2018
dfa6de1
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
36f41af
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
2265836
Merge branch 'clean21' into clean22
jdconrad Jul 31, 2018
57e2a46
Add local methods to def bootstrap for consistency in look ups.
jdconrad Aug 1, 2018
bd2d854
Merge branch 'master' into clean21
jdconrad Aug 1, 2018
7187e4f
Merge branch 'master' into clean21
jdconrad Aug 1, 2018
69da907
Merge branch 'clean21' into clean22
jdconrad Aug 1, 2018
eb3bb9f
Merge branch 'clean22' into clean24
jdconrad Aug 1, 2018
4da7113
Add FunctionReference.
jdconrad Aug 1, 2018
1d8b547
Progress.
jdconrad Aug 1, 2018
e51f3df
Progress.
jdconrad Aug 1, 2018
a082624
Progress.
jdconrad Aug 1, 2018
89e936e
Fix.
jdconrad Aug 1, 2018
cf430a9
Progress.
jdconrad Aug 1, 2018
c4e8357
Large clean up of function reference.
jdconrad Aug 1, 2018
bde26b4
A bit more clean up.
jdconrad Aug 1, 2018
b3ed1b7
Merge branch 'master' into clean22
jdconrad Aug 1, 2018
264f6a4
Merge branch 'clean22' into clean24
jdconrad Aug 1, 2018
2cf04ec
Merge branch 'clean24' into clean25
jdconrad Aug 1, 2018
02ab981
Move runtime method lookup to PainlessLookup.
jdconrad Aug 1, 2018
551dc4e
Add getter/setter lookup methods to PainlessLookup.
jdconrad Aug 1, 2018
c1d9d25
Rename.
jdconrad Aug 1, 2018
73bfbdf
Mechanical change to rename variables in PainlessCast.
jdconrad Aug 2, 2018
581f359
Clean up whitelist names.
jdconrad Aug 2, 2018
4255c3c
Merge branch 'master' into clean22
jdconrad Aug 2, 2018
9d5f02f
Remove unnecessary sorted classes list.
jdconrad Aug 2, 2018
a255273
Merge branch 'clean22' into clean24
jdconrad Aug 2, 2018
4dbb100
Merge branch 'clean24' into clean25
jdconrad Aug 2, 2018
9609b45
Merge branch 'clean25' into clean26
jdconrad Aug 2, 2018
f27f954
Merge branch 'clean26' into clean27
jdconrad Aug 2, 2018
172df36
Merge branch 'clean27' into clean28
jdconrad Aug 2, 2018
64933d1
Merge branch 'master' into clean22
jdconrad Aug 2, 2018
61737be
Merge branch 'clean22' into clean24
jdconrad Aug 2, 2018
67f4140
Merge branch 'clean24' into clean25
jdconrad Aug 2, 2018
8471f6b
Merge branch 'clean25' into clean26
jdconrad Aug 2, 2018
61946df
Merge branch 'clean26' into clean27
jdconrad Aug 2, 2018
ef3356a
Merge branch 'clean27' into clean28
jdconrad Aug 2, 2018
d7d0292
Remove extraneous line.
jdconrad Aug 2, 2018
aac6d88
Change Object to Map.
jdconrad Aug 2, 2018
4051638
Fix import.
jdconrad Aug 2, 2018
b65f459
Merge branch 'master' into clean24
jdconrad Aug 6, 2018
f071c78
Merge branch 'clean24' into clean25
jdconrad Aug 6, 2018
8e2a6af
Merge branch 'master' into clean25
jdconrad Aug 6, 2018
9921693
Merge branch 'clean25' into clean26
jdconrad Aug 6, 2018
c42e64e
Merge branch 'clean26' into clean27
jdconrad Aug 6, 2018
6e5e7ad
Merge branch 'clean27' into clean28
jdconrad Aug 6, 2018
af80f8e
Merge branch 'master' into clean25
jdconrad Aug 7, 2018
0b8ebdf
Fix formatting.
jdconrad Aug 7, 2018
b7812d6
Add FunctionRef back.
jdconrad Aug 7, 2018
c7ebe54
Remove extraneous character.
jdconrad Aug 7, 2018
28f6e60
Merge branch 'master' into clean25
jdconrad Aug 7, 2018
b98030a
Merge branch 'clean25' into clean26
jdconrad Aug 7, 2018
fc578ed
Merge branch 'master' into clean26
jdconrad Aug 7, 2018
ab9a805
Merge branch 'clean26' into clean27
jdconrad Aug 7, 2018
058c988
Merge branch 'clean27' into clean28
jdconrad Aug 7, 2018
1d3d2fc
Merge branch 'master' into clean26
jdconrad Aug 8, 2018
804f529
Return null instead of throwing exceptions for all methods in
jdconrad Aug 8, 2018
973c1b2
Merge branch 'master' into clean26
jdconrad Aug 8, 2018
f05f3d9
Merge branch 'clean26' into clean27
jdconrad Aug 8, 2018
a1a166b
Merge branch 'clean27' into clean28
jdconrad Aug 8, 2018
4240f75
Merge branch 'master' into clean27
jdconrad Aug 9, 2018
1939f16
Merge branch 'clean27' into clean28
jdconrad Aug 9, 2018
e617201
Merge branch 'master' into clean27
jdconrad Aug 10, 2018
0cbe7c5
Merge branch 'clean27' into clean28
jdconrad Aug 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* constructors, methods, and fields that can be used within a Painless script at both compile-time
* and run-time.
*
* A whitelist consists of several pieces with {@link WhitelistClass}s as the top level. Each
* A whitelist consists of several pieces with {@link WhitelistClass}s as the top level. Each
* {@link WhitelistClass} will contain zero-to-many {@link WhitelistConstructor}s, {@link WhitelistMethod}s, and
* {@link WhitelistField}s which are what will be available with a Painless script. See each individual
* whitelist object for more detail.
Expand Down Expand Up @@ -56,14 +56,14 @@ public final class Whitelist {
Collections.singletonList(WhitelistLoader.loadFromResourceFiles(Whitelist.class, BASE_WHITELIST_FILES));

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

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

/** Standard constructor. All values must be not {@code null}. */
public Whitelist(ClassLoader javaClassLoader, List<WhitelistClass> whitelistStructs) {
this.javaClassLoader = Objects.requireNonNull(javaClassLoader);
this.whitelistStructs = Collections.unmodifiableList(Objects.requireNonNull(whitelistStructs));
public Whitelist(ClassLoader classLoader, List<WhitelistClass> whitelistClasses) {
this.classLoader = Objects.requireNonNull(classLoader);
this.whitelistClasses = Collections.unmodifiableList(Objects.requireNonNull(whitelistClasses));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* specific context, as long as multiple classes representing the same Java class have the same
* class name and have legal constructor/method overloading they can be merged together.
*
* Classes in Painless allow for arity overloading for constructors and methods. Arity overloading
* Classes in Painless allow for arity overloading for constructors and methods. Arity overloading
* means that multiple constructors are allowed for a single class as long as they have a different
* number of parameters, and multiples methods with the same name are allowed for a single class
* as long as they have the same return type and a different number of parameters.
Expand All @@ -40,7 +40,7 @@
*/
public final class WhitelistClass {

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

/** The Java class name this class represents. */
Expand All @@ -49,7 +49,7 @@ public final class WhitelistClass {
/**
* Allow the Java class name to only be specified as the fully-qualified name.
*/
public final boolean onlyFQNJavaClassName;
public final boolean noImport;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we've discussed this rename, but I would keep this as is until that change is ready, to keep consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion here. Normally, I would agree, but I already have the next PR lined up, so I would prefer to just leave this for now, since I would rename it back and then rename it again. Will be more careful next time around.


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

/** Standard constructor. All values must be not {@code null}. */
public WhitelistClass(String origin, String javaClassName, boolean onlyFQNJavaClassName,
public WhitelistClass(String origin, String javaClassName, boolean noImport,
List<WhitelistConstructor> whitelistConstructors,
List<WhitelistMethod> whitelistMethods,
List<WhitelistField> whitelistFields) {

this.origin = Objects.requireNonNull(origin);
this.javaClassName = Objects.requireNonNull(javaClassName);
this.onlyFQNJavaClassName = onlyFQNJavaClassName;
this.noImport = noImport;

this.whitelistConstructors = Collections.unmodifiableList(Objects.requireNonNull(whitelistConstructors));
this.whitelistMethods = Collections.unmodifiableList(Objects.requireNonNull(whitelistMethods));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@

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

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

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

/** Standard constructor. All values must be not {@code null}. */
public WhitelistConstructor(String origin, List<String> painlessParameterTypeNames) {
public WhitelistConstructor(String origin, List<String> canonicalTypeNameParameters) {
this.origin = Objects.requireNonNull(origin);
this.painlessParameterTypeNames = Collections.unmodifiableList(Objects.requireNonNull(painlessParameterTypeNames));
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@

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

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

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

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

/** Standard constructor. All values must be not {@code null}. */
public WhitelistField(String origin, String javaFieldName, String painlessFieldTypeName) {
public WhitelistField(String origin, String fieldName, String canonicalTypeNameParameter) {
this.origin = Objects.requireNonNull(origin);
this.javaFieldName = Objects.requireNonNull(javaFieldName);
this.painlessFieldTypeName = Objects.requireNonNull(painlessFieldTypeName);
this.fieldName = Objects.requireNonNull(fieldName);
this.canonicalTypeNameParameter = Objects.requireNonNull(canonicalTypeNameParameter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
public final class WhitelistLoader {

/**
* Loads and creates a {@link Whitelist} from one to many text files. The file paths are passed in as an array of
* Loads and creates a {@link Whitelist} from one to many text files. The file paths are passed in as an array of
* {@link String}s with a single {@link Class} to be be used to load the resources where each {@link String}
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
* reflection objects for each individual {@link Class}, {@link Constructor}, {@link Method}, and {@link Field}
* specified as part of the whitelist in the text file.
*
* A single pass is made through each file to collect all the information about each class, constructor, method,
* and field. Most validation will be done at a later point after all whitelists have been gathered and their
* and field. Most validation will be done at a later point after all whitelists have been gathered and their
* merging takes place.
*
* A painless type name is one of the following:
Expand All @@ -52,15 +52,15 @@ public final class WhitelistLoader {
* <li> fully-qualified Java type name - Any whitelisted Java class will have the equivalent name as
* a Painless type name with the exception that any dollar symbols used as part of inner classes will
* 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
* as described later. </li>
* </ul>
*
* The following can be parsed from each whitelist text file:
* <ul>
* <li> Blank lines will be ignored by the parser. </li>
* <li> Comments may be created starting with a pound '#' symbol and end with a newline. These will
* <li> Comments may be created starting with a pound '#' symbol and end with a newline. These will
* be ignored by the parser. </li>
* <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>
Expand Down Expand Up @@ -93,10 +93,10 @@ public final class WhitelistLoader {
*
* Note there must be a one-to-one correspondence of Painless type names to Java type/class names.
* If the same Painless type is defined across multiple files and the Java class is the same, all
* specified constructors, methods, and fields will be merged into a single Painless type. The
* specified constructors, methods, and fields will be merged into a single Painless type. The
* Painless dynamic type, 'def', used as part of constructor, method, and field definitions will
* be appropriately parsed and handled. Painless complex types must be specified with the
* fully-qualified Java class name. Method argument types, method return types, and field types
* be appropriately parsed and handled. Painless complex types must be specified with the
* fully-qualified Java class name. Method argument types, method return types, and field types
* must be specified with Painless type names (def, fully-qualified, or short) as described earlier.
*
* The following example is used to create a single whitelist text file:
Expand Down Expand Up @@ -132,7 +132,7 @@ public final class WhitelistLoader {
* }
*/
public static Whitelist loadFromResourceFiles(Class<?> resource, String... filepaths) {
List<WhitelistClass> whitelistStructs = new ArrayList<>();
List<WhitelistClass> whitelistClasses = new ArrayList<>();

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

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

whitelistStructOrigin = "[" + filepath + "]:[" + number + "]";
whitelistClassOrigin = "[" + filepath + "]:[" + number + "]";
javaClassName = tokens[0];

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

whitelistStructs.add(new WhitelistClass(whitelistStructOrigin, javaClassName, onlyFQNJavaClassName,
whitelistClasses.add(new WhitelistClass(whitelistClassOrigin, javaClassName, onlyFQNJavaClassName,
whitelistConstructors, whitelistMethods, whitelistFields));

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

return new Whitelist(loader, whitelistStructs);
return new Whitelist(loader, whitelistClasses);
}

private WhitelistLoader() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,53 @@

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

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

/**
* The Java class name for the owner of an augmented method. If the method is not augmented
* The class name for the owner of an augmented method. If the method is not augmented
* this should be {@code null}.
*/
public final String javaAugmentedClassName;
public final String augmentedCanonicalClassName;

/** The Java method name used to look up the Java method through reflection. */
public final String javaMethodName;
/** The method name used to look up the method reflection object. */
public final String methodName;

/**
* The Painless type name for the return type of the method which can be used to look up the Java
* method through reflection.
* The canonical type name for the return type.
*/
public final String painlessReturnTypeName;
public final String returnCanonicalTypeName;

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

/**
* Standard constructor. All values must be not {@code null} with the exception of jAugmentedClass;
* jAugmentedClass will be {@code null} unless the method is augmented as described in the class documentation.
* Standard constructor. All values must be not {@code null} with the exception of
* augmentedCanonicalClassName; augmentedCanonicalClassName will be {@code null} unless the method
* is augmented as described in the class documentation.
*/
public WhitelistMethod(String origin, String javaAugmentedClassName, String javaMethodName,
String painlessReturnTypeName, List<String> painlessParameterTypeNames) {
public WhitelistMethod(String origin, String augmentedCanonicalClassName, String methodName,
String returnCanonicalTypeName, List<String> canonicalTypeNameParameters) {
this.origin = Objects.requireNonNull(origin);
this.javaAugmentedClassName = javaAugmentedClassName;
this.javaMethodName = javaMethodName;
this.painlessReturnTypeName = Objects.requireNonNull(painlessReturnTypeName);
this.painlessParameterTypeNames = Collections.unmodifiableList(Objects.requireNonNull(painlessParameterTypeNames));
this.augmentedCanonicalClassName = augmentedCanonicalClassName;
this.methodName = methodName;
this.returnCanonicalTypeName = Objects.requireNonNull(returnCanonicalTypeName);
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
}
}
Loading