30
30
import org .codehaus .groovy .ast .Variable ;
31
31
import org .codehaus .groovy .ast .expr .ArgumentListExpression ;
32
32
import org .codehaus .groovy .ast .expr .BinaryExpression ;
33
- import org .codehaus .groovy .ast .expr .BooleanExpression ;
34
33
import org .codehaus .groovy .ast .expr .CastExpression ;
35
- import org .codehaus .groovy .ast .expr .ClassExpression ;
36
34
import org .codehaus .groovy .ast .expr .ClosureExpression ;
37
35
import org .codehaus .groovy .ast .expr .ConstantExpression ;
38
36
import org .codehaus .groovy .ast .expr .DeclarationExpression ;
41
39
import org .codehaus .groovy .ast .expr .MethodCallExpression ;
42
40
import org .codehaus .groovy .ast .expr .PropertyExpression ;
43
41
import org .codehaus .groovy .ast .expr .StaticMethodCallExpression ;
44
- import org .codehaus .groovy .ast .expr .TernaryExpression ;
45
42
import org .codehaus .groovy .ast .expr .TupleExpression ;
46
43
import org .codehaus .groovy .ast .expr .VariableExpression ;
47
44
import org .codehaus .groovy .control .SourceUnit ;
48
45
import org .codehaus .groovy .syntax .SyntaxException ;
49
46
import org .codehaus .groovy .syntax .Token ;
50
- import org .codehaus .groovy .syntax .Types ;
51
47
52
48
import java .util .Collection ;
53
- import java .util .List ;
49
+
50
+ import static org .codehaus .groovy .ast .tools .GeneralUtils .callX ;
51
+ import static org .codehaus .groovy .ast .tools .GeneralUtils .classX ;
52
+ import static org .codehaus .groovy .ast .tools .GeneralUtils .isInstanceOfX ;
53
+ import static org .codehaus .groovy .ast .tools .GeneralUtils .ternaryX ;
54
+ import static org .codehaus .groovy .ast .tools .GeneralUtils .varX ;
54
55
55
56
/**
56
57
* This expression transformer is used internally by the {@link org.codehaus.groovy.transform.trait.TraitASTTransformation
@@ -155,7 +156,7 @@ public Expression transform(final Expression exp) {
155
156
FieldNode fn = (accessedVariable instanceof FieldNode ? (FieldNode ) accessedVariable : ((PropertyNode ) accessedVariable ).getField ());
156
157
boolean isStatic = java .lang .reflect .Modifier .isStatic (accessedVariable .getModifiers ());
157
158
Expression receiver = createFieldHelperReceiver ();
158
- if (isStatic ) receiver = createStaticReceiver (receiver );
159
+ if (isStatic ) receiver = asClass (receiver );
159
160
160
161
MethodCallExpression mce = new MethodCallExpression (
161
162
receiver ,
@@ -316,6 +317,7 @@ private static void markDynamicCall(final MethodCallExpression mce, final FieldN
316
317
}
317
318
}
318
319
320
+ /* GRECLIPSE edit
319
321
private TernaryExpression createStaticReceiver(final Expression receiver) {
320
322
return new TernaryExpression(
321
323
new BooleanExpression(new BinaryExpression(
@@ -324,9 +326,10 @@ private TernaryExpression createStaticReceiver(final Expression receiver) {
324
326
new ClassExpression(ClassHelper.CLASS_Type)
325
327
)),
326
328
receiver,
327
- new MethodCallExpression (createFieldHelperReceiver () , "getClass" , ArgumentListExpression .EMPTY_ARGUMENTS )
329
+ new MethodCallExpression(receiver , "getClass", ArgumentListExpression.EMPTY_ARGUMENTS)
328
330
);
329
331
}
332
+ */
330
333
331
334
private BinaryExpression createAssignmentToField (final Expression rightExpression ,
332
335
final Token operation , final String fieldName ) {
@@ -390,6 +393,7 @@ private Expression transformSuperMethodCall(final MethodCallExpression call) {
390
393
private Expression transformMethodCallOnThis (final MethodCallExpression call ) {
391
394
Expression method = call .getMethod ();
392
395
Expression arguments = call .getArguments ();
396
+ /* GRECLIPSE edit -- GROOVY-10106
393
397
if (method instanceof ConstantExpression) {
394
398
String methodName = method.getText();
395
399
List<MethodNode> methods = traitClass.getMethods(methodName);
@@ -408,19 +412,40 @@ private Expression transformMethodCallOnThis(final MethodCallExpression call) {
408
412
}
409
413
410
414
return transformMethodCallOnThisFallBack(call, method, arguments);
415
+ */
416
+ if (method instanceof ConstantExpression ) {
417
+ String methodName = call .getMethodAsString ();
418
+ for (MethodNode methodNode : traitClass .getMethods (methodName )) {
419
+ if (methodName .equals (methodNode .getName ()) && (methodNode .isStatic () || methodNode .isPrivate ())) {
420
+ ArgumentListExpression newArgs = createArgumentList (methodNode .isStatic () ? asClass (call .getObjectExpression ()) : weaved , arguments );
421
+ MethodCallExpression newCall = callX (inClosure ? classX (traitHelperClass ) : varX ("this" ), methodName , newArgs );
422
+ newCall .setImplicitThis (true );
423
+ newCall .setSafe (call .isSafe ());
424
+ newCall .setSourcePosition (call );
425
+ newCall .setSpreadSafe (call .isSpreadSafe ());
426
+ return newCall ;
427
+ }
428
+ }
429
+ }
411
430
431
+ MethodCallExpression newCall = callX (inClosure ? call .getObjectExpression () : weaved , method , transform (arguments ));
432
+ newCall .setImplicitThis (inClosure ? call .isImplicitThis () : false );
433
+ newCall .setSafe (call .isSafe ());
434
+ newCall .setSourcePosition (call );
435
+ newCall .setSpreadSafe (call .isSpreadSafe ());
436
+ return newCall ;
437
+ // GRECLIPSE end
412
438
}
413
439
440
+ /* GRECLIPSE edit
414
441
private Expression transformMethodCallOnThisFallBack(final MethodCallExpression call,
415
442
final Expression method, final Expression arguments) {
416
443
MethodCallExpression transformed = new MethodCallExpression(
417
444
weaved,
418
445
method,
419
446
transform(arguments)
420
447
);
421
- /* GRECLIPSE edit
422
448
transformed.setSourcePosition(call);
423
- */
424
449
transformed.setSafe(call.isSafe());
425
450
transformed.setSpreadSafe(call.isSpreadSafe());
426
451
transformed.setImplicitThis(false);
@@ -433,9 +458,7 @@ private Expression transformMethodCallOnThisInClosure(final MethodCallExpression
433
458
call.getMethod(),
434
459
transform(call.getArguments())
435
460
);
436
- /* GRECLIPSE edit
437
461
transformed.setSourcePosition(call);
438
- */
439
462
transformed.setSafe(call.isSafe());
440
463
transformed.setSpreadSafe(call.isSpreadSafe());
441
464
transformed.setImplicitThis(call.isImplicitThis());
@@ -471,11 +494,31 @@ private Expression transformPrivateMethodCallOnThisInClosure(final MethodCallExp
471
494
transformed.setImplicitThis(true);
472
495
return transformed;
473
496
}
497
+ */
498
+ private ArgumentListExpression createArgumentList (final Expression self , final Expression arguments ) {
499
+ ArgumentListExpression newArgs = new ArgumentListExpression ();
500
+ newArgs .addExpression (self );
501
+ if (arguments instanceof TupleExpression ) {
502
+ for (Expression argument : (TupleExpression ) arguments ) {
503
+ newArgs .addExpression (transform (argument ));
504
+ }
505
+ } else {
506
+ newArgs .addExpression (transform (arguments ));
507
+ }
508
+ return newArgs ;
509
+ }
510
+
511
+ private static Expression asClass (final Expression e ) {
512
+ ClassNode rawClass = ClassHelper .CLASS_Type .getPlainNodeReference ();
513
+ return ternaryX (isInstanceOfX (e , rawClass ), e , callX (e , "getClass" ));
514
+ }
515
+ // GRECLIPSE end
474
516
475
517
private Expression createFieldHelperReceiver () {
476
518
return ClassHelper .CLASS_Type .equals (weaved .getOriginType ()) ? weaved : new CastExpression (fieldHelper , weaved );
477
519
}
478
520
521
+ /* GRECLIPSE edit
479
522
private ArgumentListExpression createArgumentList(final Expression origCallArgs) {
480
523
ArgumentListExpression newArgs = new ArgumentListExpression();
481
524
newArgs.addExpression(new VariableExpression(weaved));
@@ -489,4 +532,5 @@ private ArgumentListExpression createArgumentList(final Expression origCallArgs)
489
532
}
490
533
return newArgs;
491
534
}
535
+ */
492
536
}
0 commit comments