@@ -4111,9 +4111,8 @@ public void visitMethodCallExpression(MethodCallExpression call) {
41114111 mn = accessibleMethods ;
41124112 if (accessibleMethods .isEmpty ()) {
41134113 // choose an arbitrary method to display an error message
4114- MethodNode node = inaccessibleMethods .get (0 );
4115- ClassNode owner = node .getDeclaringClass ();
4116- addStaticTypeError ("Non-static method " + owner .getName () + "#" + node .getName () + " cannot be called from static context" , call );
4114+ MethodNode inaccessibleMethod = inaccessibleMethods .get (0 );
4115+ addStaticTypeError ("Non-static method " + prettyPrintTypeName (inaccessibleMethod .getDeclaringClass ()) + "#" + inaccessibleMethod .getName () + " cannot be called from static context" , call );
41174116 }
41184117 }
41194118
@@ -4141,19 +4140,24 @@ public void visitMethodCallExpression(MethodCallExpression call) {
41414140 mn = disambiguateMethods (mn , chosenReceiver != null ? chosenReceiver .getType () : null , args , call );
41424141 if (mn .size () == 1 ) {
41434142 MethodNode directMethodCallCandidate = mn .get (0 );
4143+ ClassNode declaringClass = directMethodCallCandidate .getDeclaringClass ();
4144+ if (chosenReceiver == null ) chosenReceiver = Receiver .make (declaringClass );
4145+ /* GRECLIPSE edit -- GROOVY-10939
41444146 if (call.getNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION) == null &&
41454147 !directMethodCallCandidate.isStatic() && objectExpression instanceof ClassExpression &&
41464148 !"java.lang.Class".equals(directMethodCallCandidate.getDeclaringClass().getName())) {
41474149 ClassNode owner = directMethodCallCandidate.getDeclaringClass();
41484150 addStaticTypeError("Non-static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
41494151 }
4152+ */
4153+ if (!directMethodCallCandidate .isStatic () && !(declaringClass .equals (CLASS_Type ) || declaringClass .equals (OBJECT_TYPE ))
4154+ && receiver .equals (CLASS_Type ) && chosenReceiver .getData () == null && !Boolean .TRUE .equals (call .getNodeMetaData (StaticTypesMarker .DYNAMIC_RESOLUTION ))) {
4155+ addStaticTypeError ("Non-static method " + prettyPrintTypeName (declaringClass ) + "#" + directMethodCallCandidate .getName () + " cannot be called from static context" , call );
4156+ }
41504157 // GRECLIPSE add -- GROOVY-10341
41514158 else if (directMethodCallCandidate .isAbstract () && isSuperExpression (objectExpression ))
41524159 addStaticTypeError ("Abstract method " + toMethodParametersString (directMethodCallCandidate .getName (), extractTypesFromParameters (directMethodCallCandidate .getParameters ())) + " cannot be called directly" , call );
41534160 // GRECLIPSE end
4154- if (chosenReceiver == null ) {
4155- chosenReceiver = Receiver .make (directMethodCallCandidate .getDeclaringClass ());
4156- }
41574161
41584162 ClassNode returnType = getType (directMethodCallCandidate );
41594163
@@ -4190,7 +4194,6 @@ else if (directMethodCallCandidate.isAbstract() && isSuperExpression(objectExpre
41904194
41914195 storeType (call , returnType );
41924196 storeTargetMethod (call , directMethodCallCandidate );
4193- ClassNode declaringClass = directMethodCallCandidate .getDeclaringClass ();
41944197 if (declaringClass .isInterface () && directMethodCallCandidate .isStatic () && !(directMethodCallCandidate instanceof ExtensionMethodNode )) {
41954198 typeCheckingContext .getEnclosingClassNode ().putNodeMetaData (MINIMUM_BYTECODE_VERSION , Opcodes .V1_8 );
41964199 }
0 commit comments