-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Painless: Restructure Definition/Whitelist (#31879)
Create lookup package rename Definition to PainlessLookup and move to lookup package rename Definition.Method to PainlessMethod rename Definition.MethodKey to PainlessMethod rename Definition.Field to PainlessField rename Definition.Struct to PainlessClass rename Definition.Cast to PainlessCast rename Whitelist.Struct to WhitelistClass rename Whitelist.Constructor to WhitelistConstructor rename Whitelist.Method to WhitelistMethod rename Whitelist.Field to WhitelistField
- Loading branch information
Showing
70 changed files
with
1,510 additions
and
1,266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/WhitelistClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.spi; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class represents the equivalent of a Java class in Painless complete with super classes, | ||
* constructors, methods, and fields. There must be a one-to-one mapping of class names to Java | ||
* classes. Though, since multiple whitelists may be combined into a single whitelist for a | ||
* 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 | ||
* 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. | ||
* | ||
* Classes will automatically extend other whitelisted classes if the Java class they represent is a | ||
* subclass of other classes including Java interfaces. | ||
*/ | ||
public final class WhitelistClass { | ||
|
||
/** Information about where this class was white-listed from. Can be used for error messages. */ | ||
public final String origin; | ||
|
||
/** The Java class name this class represents. */ | ||
public final String javaClassName; | ||
|
||
/** | ||
* Allow the Java class name to only be specified as the fully-qualified name. | ||
*/ | ||
public final boolean onlyFQNJavaClassName; | ||
|
||
/** The {@link List} of whitelisted ({@link WhitelistConstructor}s) available to this class. */ | ||
public final List<WhitelistConstructor> whitelistConstructors; | ||
|
||
/** The {@link List} of whitelisted ({@link WhitelistMethod}s) available to this class. */ | ||
public final List<WhitelistMethod> whitelistMethods; | ||
|
||
/** The {@link List} of whitelisted ({@link WhitelistField}s) available to this class. */ | ||
public final List<WhitelistField> whitelistFields; | ||
|
||
/** Standard constructor. All values must be not {@code null}. */ | ||
public WhitelistClass(String origin, String javaClassName, boolean onlyFQNJavaClassName, | ||
List<WhitelistConstructor> whitelistConstructors, | ||
List<WhitelistMethod> whitelistMethods, | ||
List<WhitelistField> whitelistFields) { | ||
this.origin = Objects.requireNonNull(origin); | ||
this.javaClassName = Objects.requireNonNull(javaClassName); | ||
this.onlyFQNJavaClassName = onlyFQNJavaClassName; | ||
|
||
this.whitelistConstructors = Collections.unmodifiableList(Objects.requireNonNull(whitelistConstructors)); | ||
this.whitelistMethods = Collections.unmodifiableList(Objects.requireNonNull(whitelistMethods)); | ||
this.whitelistFields = Collections.unmodifiableList(Objects.requireNonNull(whitelistFields)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/WhitelistConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.spi; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* 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 | ||
* 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. */ | ||
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; | ||
|
||
/** Standard constructor. All values must be not {@code null}. */ | ||
public WhitelistConstructor(String origin, List<String> painlessParameterTypeNames) { | ||
this.origin = Objects.requireNonNull(origin); | ||
this.painlessParameterTypeNames = Collections.unmodifiableList(Objects.requireNonNull(painlessParameterTypeNames)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/WhitelistField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.spi; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* 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 | ||
* 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. */ | ||
public final String origin; | ||
|
||
/** The Java field name used to look up the Java field through reflection. */ | ||
public final String javaFieldName; | ||
|
||
/** The Painless type name for the field which can be used to look up the Java field through reflection. */ | ||
public final String painlessFieldTypeName; | ||
|
||
/** Standard constructor. All values must be not {@code null}. */ | ||
public WhitelistField(String origin, String javaFieldName, String painlessFieldTypeName) { | ||
this.origin = Objects.requireNonNull(origin); | ||
this.javaFieldName = Objects.requireNonNull(javaFieldName); | ||
this.painlessFieldTypeName = Objects.requireNonNull(painlessFieldTypeName); | ||
} | ||
} |
Oops, something went wrong.