-
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: Add PainlessClassBuilder (#32141)
Several pieces of data in PainlessClass cannot be passed in at the time the PainlessClass is created so it must be "frozen" after all the data is collected. This means PainlessClass is currently serving two functions as both a builder and a set of data. This separates the two pieces into clearly distinct values. This change also removes the PainlessMethodKey in favor of a simple String. The goal is to have the painless method key be completely internal to the PainlessLookup eventually and this simplifies the way there. Note that this was added since PainlessClass and PainlessClassBuilder were already being changed instead of a follow up PR.
- Loading branch information
Showing
19 changed files
with
180 additions
and
217 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
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
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
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
70 changes: 70 additions & 0 deletions
70
...s/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessClassBuilder.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,70 @@ | ||
/* | ||
* 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.lookup; | ||
|
||
import org.objectweb.asm.Type; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
final class PainlessClassBuilder { | ||
final String name; | ||
final Class<?> clazz; | ||
final Type type; | ||
|
||
final Map<String, PainlessMethod> constructors; | ||
final Map<String, PainlessMethod> staticMethods; | ||
final Map<String, PainlessMethod> methods; | ||
|
||
final Map<String, PainlessField> staticMembers; | ||
final Map<String, PainlessField> members; | ||
|
||
final Map<String, MethodHandle> getters; | ||
final Map<String, MethodHandle> setters; | ||
|
||
PainlessMethod functionalMethod; | ||
|
||
PainlessClassBuilder(String name, Class<?> clazz, Type type) { | ||
this.name = name; | ||
this.clazz = clazz; | ||
this.type = type; | ||
|
||
constructors = new HashMap<>(); | ||
staticMethods = new HashMap<>(); | ||
methods = new HashMap<>(); | ||
|
||
staticMembers = new HashMap<>(); | ||
members = new HashMap<>(); | ||
|
||
getters = new HashMap<>(); | ||
setters = new HashMap<>(); | ||
|
||
functionalMethod = null; | ||
} | ||
|
||
PainlessClass build() { | ||
return new PainlessClass(name, clazz, type, | ||
constructors, staticMethods, methods, | ||
staticMembers, members, | ||
getters, setters, | ||
functionalMethod); | ||
} | ||
} |
Oops, something went wrong.