22
22
import org .elasticsearch .painless .AnalyzerCaster ;
23
23
import org .elasticsearch .painless .Definition ;
24
24
import org .elasticsearch .painless .Definition .Method ;
25
- import org .elasticsearch .painless .Definition .Type ;
25
+ import org .elasticsearch .painless .Definition .def ;
26
26
import org .elasticsearch .painless .FunctionRef ;
27
27
import org .elasticsearch .painless .Globals ;
28
28
import org .elasticsearch .painless .Locals ;
@@ -101,14 +101,14 @@ void extractVariables(Set<String> variables) {
101
101
102
102
@ Override
103
103
void analyze (Locals locals ) {
104
- final Type returnType ;
105
- final List <String > actualParamTypeStrs ;
104
+ Class <?> returnType ;
105
+ List <String > actualParamTypeStrs ;
106
106
Method interfaceMethod ;
107
107
// inspect the target first, set interface method if we know it.
108
108
if (expected == null ) {
109
109
interfaceMethod = null ;
110
110
// we don't know anything: treat as def
111
- returnType = locals . getDefinition (). DefType ;
111
+ returnType = def . class ;
112
112
// don't infer any types, replace any null types with def
113
113
actualParamTypeStrs = new ArrayList <>(paramTypeStrs .size ());
114
114
for (String type : paramTypeStrs ) {
@@ -131,9 +131,9 @@ void analyze(Locals locals) {
131
131
"] in [" + Definition .ClassToName (expected ) + "]" );
132
132
// for method invocation, its allowed to ignore the return value
133
133
if (interfaceMethod .rtn .equals (locals .getDefinition ().voidType )) {
134
- returnType = locals . getDefinition (). DefType ;
134
+ returnType = def . class ;
135
135
} else {
136
- returnType = interfaceMethod .rtn ;
136
+ returnType = Definition . TypeToClass ( interfaceMethod .rtn ) ;
137
137
}
138
138
// replace any null types with the actual type
139
139
actualParamTypeStrs = new ArrayList <>(paramTypeStrs .size ());
@@ -169,11 +169,11 @@ void analyze(Locals locals) {
169
169
paramNames .addAll (paramNameStrs );
170
170
171
171
// desugar lambda body into a synthetic method
172
- desugared = new SFunction (reserved , location , returnType . name , name ,
172
+ desugared = new SFunction (reserved , location , Definition . ClassToName ( returnType ) , name ,
173
173
paramTypes , paramNames , statements , true );
174
174
desugared .generateSignature (locals .getDefinition ());
175
- desugared .analyze (Locals .newLambdaScope (locals .getProgramScope (), returnType , desugared . parameters ,
176
- captures .size (), reserved .getMaxLoopCounter ()));
175
+ desugared .analyze (Locals .newLambdaScope (locals .getProgramScope (), locals . getDefinition (). ClassToType ( returnType ) ,
176
+ desugared . parameters , captures .size (), reserved .getMaxLoopCounter ()));
177
177
178
178
// setup method reference to synthetic method
179
179
if (expected == null ) {
@@ -190,12 +190,12 @@ void analyze(Locals locals) {
190
190
191
191
// check casts between the interface method and the delegate method are legal
192
192
for (int i = 0 ; i < interfaceMethod .arguments .size (); ++i ) {
193
- Type from = interfaceMethod .arguments .get (i );
194
- Type to = desugared .parameters .get (i + captures .size ()).type ;
195
- AnalyzerCaster .getLegalCast (location , Definition . TypeToClass ( from ), Definition . TypeToClass ( to ) , false , true );
193
+ Class <?> from = Definition . TypeToClass ( interfaceMethod .arguments .get (i ) );
194
+ Class <?> to = Definition . TypeToClass ( desugared .parameters .get (i + captures .size ()).type ) ;
195
+ AnalyzerCaster .getLegalCast (location , from , to , false , true );
196
196
}
197
197
198
- if (interfaceMethod .rtn .equals ( locals . getDefinition (). voidType ) == false ) {
198
+ if (interfaceMethod .rtn .clazz != void . class ) {
199
199
AnalyzerCaster .getLegalCast (
200
200
location , Definition .TypeToClass (desugared .rtnType ), Definition .TypeToClass (interfaceMethod .rtn ), false , true );
201
201
}
@@ -212,7 +212,7 @@ void write(MethodWriter writer, Globals globals) {
212
212
writer .writeDebugInfo (location );
213
213
// load captures
214
214
for (Variable capture : captures ) {
215
- writer .visitVarInsn (capture .type .type .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
215
+ writer .visitVarInsn (MethodWriter . getType ( capture .type .clazz ) .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
216
216
}
217
217
218
218
writer .invokeDynamic (
@@ -230,7 +230,7 @@ void write(MethodWriter writer, Globals globals) {
230
230
writer .push ((String )null );
231
231
// load captures
232
232
for (Variable capture : captures ) {
233
- writer .visitVarInsn (capture .type .type .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
233
+ writer .visitVarInsn (MethodWriter . getType ( capture .type .clazz ) .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
234
234
}
235
235
}
236
236
@@ -247,7 +247,7 @@ public String getPointer() {
247
247
public org .objectweb .asm .Type [] getCaptures () {
248
248
org .objectweb .asm .Type [] types = new org .objectweb .asm .Type [captures .size ()];
249
249
for (int i = 0 ; i < types .length ; i ++) {
250
- types [i ] = captures .get (i ).type .type ;
250
+ types [i ] = MethodWriter . getType ( captures .get (i ).type .clazz ) ;
251
251
}
252
252
return types ;
253
253
}
0 commit comments