@@ -205,9 +205,7 @@ protected Expression transformBinaryExpression(BinaryExpression be) {
205205 if (left instanceof StaticMethodCallExpression ) {
206206 StaticMethodCallExpression smce = (StaticMethodCallExpression ) left ;
207207 StaticMethodCallExpression result = new StaticMethodCallExpression (smce .getOwnerType (), smce .getMethod (), right );
208- // GRECLIPSE add
209208 result .copyNodeMetaData (smce );
210- // GRECLIPSE end
211209 setSourcePosition (result , be );
212210 return result ;
213211 }
@@ -263,14 +261,6 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
263261 setSourcePosition (result , mce );
264262 return result ;
265263 }
266- if (name != null && !inLeftExpression ) { // maybe a closure field
267- result = findStaticFieldOrPropertyAccessorImportFromModule (name );
268- if (result != null ) {
269- result = new MethodCallExpression (result , "call" , args );
270- result .setSourcePosition (mce );
271- return result ;
272- }
273- }
274264 }
275265 } else if (currentMethod != null && currentMethod .isStatic () && isSuperExpression (object )) {
276266 Expression result = new MethodCallExpression (new ClassExpression (currentClass .getSuperClass ()), method , args );
@@ -446,59 +436,91 @@ private Expression findStaticFieldOrPropertyAccessorImportFromModule(String name
446436 }
447437
448438 private Expression findStaticMethodImportFromModule (Expression method , Expression args ) {
449- ModuleNode module = currentClass .getModule ();
450- if (module == null || !(method instanceof ConstantExpression )) return null ;
451- Map < String , ImportNode > importNodes = module . getStaticImports () ;
452- ConstantExpression ce = ( ConstantExpression ) method ;
439+ if ( currentClass .getModule () == null ) return null ;
440+ if (!(method instanceof ConstantExpression )) return null ;
441+ if (!((( ConstantExpression ) method ). getValue () instanceof String )) return null ;
442+
453443 Expression expression ;
454- Object value = ce .getValue ();
455- // skip non-Strings, e.g. Integer
456- if (!(value instanceof String )) return null ;
457- final String name = (String ) value ;
444+ String name = method .getText ();
445+ Map <String , ImportNode > staticImports = currentClass .getModule ().getStaticImports ();
458446 // look for one of these:
459- // import static SomeClass.method [as otherName]
460- // when resolving methodCall() or getProp() or setProp()
461- if (importNodes .containsKey (name )) {
462- ImportNode importNode = importNodes .get (name );
447+ // import static MyClass.field [as alias]
448+ // import static MyClass.method [as alias]
449+ // import static MyClass.property [as alias]
450+ // when resolving implicit-this call name(args)
451+ if (staticImports .containsKey (name )) {
452+ ImportNode importNode = staticImports .get (name );
463453 expression = findStaticMethod (importNode .getType (), importNode .getFieldName (), args );
464- if (expression != null ) return expression ;
465- expression = findStaticPropertyAccessorGivenArgs (importNode .getType (), getPropNameForAccessor (importNode .getFieldName ()), args );
466454 if (expression != null ) {
467- return newStaticMethodCallX (importNode .getType (), importNode .getFieldName (), args );
455+ return expression ;
456+ }
457+ if (!inClosure && !inLeftExpression ) {
458+ expression = findStaticPropertyOrField (importNode .getType (), importNode .getFieldName ());
459+ if (expression != null ) { // assume name refers to a callable static field/property
460+ MethodCallExpression call = new MethodCallExpression (expression , "call" , args );
461+ call .setImplicitThis (false );
462+ return call ;
463+ }
468464 }
469465 }
470466 // look for one of these:
471- // import static SomeClass.someProp [as otherName]
472- // when resolving getProp() or setProp()
473- if (isValidAccessorName (name )) {
474- String propName = getPropNameForAccessor (name );
475- if (importNodes .containsKey (propName )) {
476- ImportNode importNode = importNodes .get (propName );
477- ClassNode importClass = importNode .getType ();
467+ // import static MyClass.property [as alias]
468+ // import static MyClass.isProperty [as alias]
469+ // import static MyClass.getProperty [as alias]
470+ // import static MyClass.setProperty [as alias]
471+ // when resolving isName(), getName() or setName(args)
472+ boolean accessor = isValidAccessorName (name );
473+ if (accessor ) {
474+ ImportNode importNode = staticImports .get (name );
475+ if (importNode != null ) {
476+ String propName = getPropNameForAccessor (importNode .getFieldName ());
477+ expression = findStaticPropertyAccessorGivenArgs (importNode .getType (), propName , args );
478+ if (expression != null ) { // expression may refer to getter or setter, so make new call
479+ return newStaticMethodCallX (importNode .getType (), importNode .getFieldName (), args );
480+ }
481+ }
482+ importNode = staticImports .get (getPropNameForAccessor (name ));
483+ if (importNode != null ) {
484+ ClassNode importType = importNode .getType ();
478485 String importMember = importNode .getFieldName ();
479- expression = findStaticMethod (importClass , prefix (name ) + capitalize (importMember ), args );
486+ expression = findStaticMethod (importType , prefix (name ) + capitalize (importMember ), args );
480487 if (expression != null ) return expression ;
481- expression = findStaticPropertyAccessorGivenArgs (importClass , importMember , args );
488+ expression = findStaticPropertyAccessorGivenArgs (importType , importMember , args );
482489 if (expression != null ) {
483- return newStaticMethodCallX (importClass , prefix (name ) + capitalize (importMember ), args );
490+ return newStaticMethodCallX (importType , prefix (name ) + capitalize (importMember ), args );
484491 }
485492 }
486493 }
487- Map <String , ImportNode > starImports = module .getStaticStarImports ();
488- ClassNode starImportType ;
489- if (currentClass .isEnum () && starImports .containsKey (currentClass .getName ())) {
490- ImportNode importNode = starImports .get (currentClass .getName ());
491- starImportType = importNode == null ? null : importNode .getType ();
492- expression = findStaticMethod (starImportType , name , args );
494+
495+ Map <String , ImportNode > staticStarImports = currentClass .getModule ().getStaticStarImports ();
496+ if (currentClass .isEnum () && staticStarImports .containsKey (currentClass .getName ())) {
497+ ImportNode importNode = staticStarImports .get (currentClass .getName ());
498+ expression = findStaticMethod (importNode .getType (), name , args );
493499 return expression ;
494- } else {
495- for (ImportNode importNode : starImports .values ()) {
496- starImportType = importNode == null ? null : importNode .getType ();
497- expression = findStaticMethod (starImportType , name , args );
498- if (expression != null ) return expression ;
499- expression = findStaticPropertyAccessorGivenArgs (starImportType , getPropNameForAccessor (name ), args );
500- if (expression != null ) {
501- return newStaticMethodCallX (starImportType , name , args );
500+ }
501+ // look for one of these:
502+ // import static MyClass.*
503+ // when resolving name(args), getName(), etc.
504+ for (ImportNode importNode : staticStarImports .values ()) {
505+ ClassNode importType = importNode .getType ();
506+ expression = findStaticMethod (importType , name , args );
507+ if (expression != null ) return expression ;
508+ if (!inClosure && !inLeftExpression ) { // GROOVY-10329
509+ expression = findStaticPropertyOrField (importType , name );
510+ if (expression != null ) { // assume name refers to a callable static field/property
511+ MethodCallExpression call = new MethodCallExpression (expression , "call" , args );
512+ call .setImplicitThis (false );
513+ // GRECLIPSE add
514+ expression .setSourcePosition (method );
515+ // GRECLIPSE end
516+ return call ;
517+ }
518+ }
519+ if (accessor ) {
520+ String propName = getPropNameForAccessor (name );
521+ expression = findStaticPropertyAccessorGivenArgs (importType , propName , args );
522+ if (expression != null ) { // expression may refer to getter or setter, so ...
523+ return newStaticMethodCallX (importType , name , args );
502524 }
503525 }
504526 }
@@ -591,14 +613,14 @@ private static Expression findStaticMethod(ClassNode staticImportType, String me
591613 return null ;
592614 }
593615
594- private static PropertyExpression newStaticPropertyX (ClassNode type , String name ) {
595- return new PropertyExpression (new ClassExpression (type .getPlainNodeReference ()), name );
596- }
597-
598616 private static StaticMethodCallExpression newStaticMethodCallX (ClassNode type , String name , Expression args ) {
599617 return new StaticMethodCallExpression (type .getPlainNodeReference (), name , args );
600618 }
601619
620+ private static PropertyExpression newStaticPropertyX (ClassNode type , String name ) {
621+ return new PropertyExpression (new ClassExpression (type .getPlainNodeReference ()), name );
622+ }
623+
602624 @ Override
603625 protected SourceUnit getSourceUnit () {
604626 return sourceUnit ;
0 commit comments