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 PainlessClass Variables #32380

Merged
merged 2 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -19,11 +19,11 @@

package org.elasticsearch.painless.spi;

import org.elasticsearch.script.ScriptContext;

import java.util.List;
import java.util.Map;

import org.elasticsearch.script.ScriptContext;

public interface PainlessExtension {

Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static MethodHandle lookupGetter(PainlessLookup painlessLookup, Class<?> receive
PainlessClass struct = painlessLookup.getPainlessStructFromJavaClass(clazz);

if (struct != null) {
MethodHandle handle = struct.getters.get(name);
MethodHandle handle = struct.getterMethodHandles.get(name);
if (handle != null) {
return handle;
}
Expand All @@ -431,7 +431,7 @@ static MethodHandle lookupGetter(PainlessLookup painlessLookup, Class<?> receive
struct = painlessLookup.getPainlessStructFromJavaClass(iface);

if (struct != null) {
MethodHandle handle = struct.getters.get(name);
MethodHandle handle = struct.getterMethodHandles.get(name);
if (handle != null) {
return handle;
}
Expand Down Expand Up @@ -492,7 +492,7 @@ static MethodHandle lookupSetter(PainlessLookup painlessLookup, Class<?> receive
PainlessClass struct = painlessLookup.getPainlessStructFromJavaClass(clazz);

if (struct != null) {
MethodHandle handle = struct.setters.get(name);
MethodHandle handle = struct.setterMethodHandles.get(name);
if (handle != null) {
return handle;
}
Expand All @@ -502,7 +502,7 @@ static MethodHandle lookupSetter(PainlessLookup painlessLookup, Class<?> receive
struct = painlessLookup.getPainlessStructFromJavaClass(iface);

if (struct != null) {
MethodHandle handle = struct.setters.get(name);
MethodHandle handle = struct.setterMethodHandles.get(name);
if (handle != null) {
return handle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.painless.api.Debug;
import org.elasticsearch.painless.lookup.PainlessClass;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
import org.elasticsearch.script.ScriptException;

import java.util.List;
Expand Down Expand Up @@ -58,7 +59,7 @@ public Map<String, List<String>> getHeaders(PainlessLookup painlessLookup) {
javaClassName = objectToExplain.getClass().getName();
PainlessClass struct = painlessLookup.getPainlessStructFromJavaClass(objectToExplain.getClass());
if (struct != null) {
painlessClassName = struct.name;
painlessClassName = PainlessLookupUtility.typeToCanonicalTypeName(objectToExplain.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,38 @@

package org.elasticsearch.painless.lookup;

import org.objectweb.asm.Type;

import java.lang.invoke.MethodHandle;
import java.util.Collections;
import java.util.Map;

public final class PainlessClass {
public final String name;
public final Class<?> clazz;
public final Type type;

public final Map<String, PainlessMethod> constructors;
public final Map<String, PainlessMethod> staticMethods;
public final Map<String, PainlessMethod> methods;

public final Map<String, PainlessField> staticMembers;
public final Map<String, PainlessField> members;
public final Map<String, PainlessField> staticFields;
public final Map<String, PainlessField> fields;

public final Map<String, MethodHandle> getters;
public final Map<String, MethodHandle> setters;
public final Map<String, MethodHandle> getterMethodHandles;
public final Map<String, MethodHandle> setterMethodHandles;

public final PainlessMethod functionalMethod;

PainlessClass(String name, Class<?> clazz, Type type,
Map<String, PainlessMethod> constructors, Map<String, PainlessMethod> staticMethods, Map<String, PainlessMethod> methods,
Map<String, PainlessField> staticMembers, Map<String, PainlessField> members,
Map<String, MethodHandle> getters, Map<String, MethodHandle> setters,
PainlessMethod functionalMethod) {
this.name = name;
this.clazz = clazz;
this.type = type;
PainlessClass(Map<String, PainlessMethod> constructors,
Map<String, PainlessMethod> staticMethods, Map<String, PainlessMethod> methods,
Map<String, PainlessField> staticFields, Map<String, PainlessField> fields,
Map<String, MethodHandle> getterMethodHandles, Map<String, MethodHandle> setterMethodHandles,
PainlessMethod functionalMethod) {

this.constructors = Collections.unmodifiableMap(constructors);
this.staticMethods = Collections.unmodifiableMap(staticMethods);
this.methods = Collections.unmodifiableMap(methods);

this.staticMembers = Collections.unmodifiableMap(staticMembers);
this.members = Collections.unmodifiableMap(members);
this.staticFields = Collections.unmodifiableMap(staticFields);
this.fields = Collections.unmodifiableMap(fields);

this.getters = Collections.unmodifiableMap(getters);
this.setters = Collections.unmodifiableMap(setters);
this.getterMethodHandles = Collections.unmodifiableMap(getterMethodHandles);
this.setterMethodHandles = Collections.unmodifiableMap(setterMethodHandles);

this.functionalMethod = functionalMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,39 @@

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, PainlessField> staticFields;
final Map<String, PainlessField> fields;

final Map<String, MethodHandle> getters;
final Map<String, MethodHandle> setters;
final Map<String, MethodHandle> getterMethodHandles;
final Map<String, MethodHandle> setterMethodHandles;

PainlessMethod functionalMethod;

PainlessClassBuilder(String name, Class<?> clazz, Type type) {
this.name = name;
this.clazz = clazz;
this.type = type;

PainlessClassBuilder() {
constructors = new HashMap<>();
staticMethods = new HashMap<>();
methods = new HashMap<>();

staticMembers = new HashMap<>();
members = new HashMap<>();
staticFields = new HashMap<>();
fields = new HashMap<>();

getters = new HashMap<>();
setters = new HashMap<>();
getterMethodHandles = new HashMap<>();
setterMethodHandles = new HashMap<>();

functionalMethod = null;
}

PainlessClass build() {
return new PainlessClass(name, clazz, type,
constructors, staticMethods, methods,
staticMembers, members,
getters, setters,
functionalMethod);
return new PainlessClass(constructors, staticMethods, methods, staticFields, fields,
getterMethodHandles, setterMethodHandles, functionalMethod);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
public final class PainlessLookup {

public Collection<PainlessClass> getStructs() {
return classesToPainlessClasses.values();
public Collection<Class<?>> getStructs() {
return classesToPainlessClasses.keySet();
}

private final Map<String, Class<?>> canonicalClassNamesToClasses;
Expand Down
Loading