|
28 | 28 | import org.elasticsearch.script.ScriptContext;
|
29 | 29 | import org.elasticsearch.script.ScriptEngine;
|
30 | 30 | import org.elasticsearch.script.ScriptException;
|
| 31 | +import org.elasticsearch.script.ScriptFactory; |
31 | 32 | import org.objectweb.asm.ClassWriter;
|
32 | 33 | import org.objectweb.asm.Opcodes;
|
33 | 34 | import org.objectweb.asm.Type;
|
@@ -66,7 +67,7 @@ public final class PainlessScriptEngine implements ScriptEngine {
|
66 | 67 | */
|
67 | 68 | private static final AccessControlContext COMPILATION_CONTEXT;
|
68 | 69 |
|
69 |
| - /** |
| 70 | + /* |
70 | 71 | * Setup the allowed permissions.
|
71 | 72 | */
|
72 | 73 | static {
|
@@ -122,7 +123,12 @@ public String getType() {
|
122 | 123 | }
|
123 | 124 |
|
124 | 125 | @Override
|
125 |
| - public <T> T compile(String scriptName, String scriptSource, ScriptContext<T> context, Map<String, String> params) { |
| 126 | + public <T extends ScriptFactory> T compile( |
| 127 | + String scriptName, |
| 128 | + String scriptSource, |
| 129 | + ScriptContext<T> context, |
| 130 | + Map<String, String> params |
| 131 | + ) { |
126 | 132 | Compiler compiler = contextsToCompilers.get(context);
|
127 | 133 |
|
128 | 134 | // Check we ourselves are not being called by unprivileged code.
|
@@ -162,12 +168,16 @@ public Set<ScriptContext<?>> getSupportedContexts() {
|
162 | 168 | * @param <T> The factory class.
|
163 | 169 | * @return A factory class that will return script instances.
|
164 | 170 | */
|
165 |
| - private <T> Type generateStatefulFactory(Loader loader, ScriptContext<T> context, Set<String> extractedVariables) { |
| 171 | + private <T extends ScriptFactory> Type generateStatefulFactory( |
| 172 | + Loader loader, |
| 173 | + ScriptContext<T> context, |
| 174 | + Set<String> extractedVariables |
| 175 | + ) { |
166 | 176 | int classFrames = ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS;
|
167 | 177 | int classAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL;
|
168 | 178 | String interfaceBase = Type.getType(context.statefulFactoryClazz).getInternalName();
|
169 | 179 | String className = interfaceBase + "$StatefulFactory";
|
170 |
| - String classInterfaces[] = new String[] { interfaceBase }; |
| 180 | + String[] classInterfaces = new String[] { interfaceBase }; |
171 | 181 |
|
172 | 182 | ClassWriter writer = new ClassWriter(classFrames);
|
173 | 183 | writer.visit(WriterConstants.CLASS_VERSION, classAccess, className, null, OBJECT_TYPE.getInternalName(), classInterfaces);
|
@@ -263,12 +273,17 @@ private <T> Type generateStatefulFactory(Loader loader, ScriptContext<T> context
|
263 | 273 | * @param <T> The factory class.
|
264 | 274 | * @return A factory class that will return script instances.
|
265 | 275 | */
|
266 |
| - private <T> T generateFactory(Loader loader, ScriptContext<T> context, Set<String> extractedVariables, Type classType) { |
| 276 | + private <T extends ScriptFactory> T generateFactory( |
| 277 | + Loader loader, |
| 278 | + ScriptContext<T> context, |
| 279 | + Set<String> extractedVariables, |
| 280 | + Type classType |
| 281 | + ) { |
267 | 282 | int classFrames = ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS;
|
268 | 283 | int classAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER| Opcodes.ACC_FINAL;
|
269 | 284 | String interfaceBase = Type.getType(context.factoryClazz).getInternalName();
|
270 | 285 | String className = interfaceBase + "$Factory";
|
271 |
| - String classInterfaces[] = new String[] { interfaceBase }; |
| 286 | + String[] classInterfaces = new String[] { interfaceBase }; |
272 | 287 |
|
273 | 288 | ClassWriter writer = new ClassWriter(classFrames);
|
274 | 289 | writer.visit(WriterConstants.CLASS_VERSION, classAccess, className, null, OBJECT_TYPE.getInternalName(), classInterfaces);
|
|
0 commit comments