@@ -4111,9 +4111,8 @@ public void visitMethodCallExpression(MethodCallExpression call) {
4111
4111
mn = accessibleMethods ;
4112
4112
if (accessibleMethods .isEmpty ()) {
4113
4113
// 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 );
4117
4116
}
4118
4117
}
4119
4118
@@ -4141,19 +4140,24 @@ public void visitMethodCallExpression(MethodCallExpression call) {
4141
4140
mn = disambiguateMethods (mn , chosenReceiver != null ? chosenReceiver .getType () : null , args , call );
4142
4141
if (mn .size () == 1 ) {
4143
4142
MethodNode directMethodCallCandidate = mn .get (0 );
4143
+ ClassNode declaringClass = directMethodCallCandidate .getDeclaringClass ();
4144
+ if (chosenReceiver == null ) chosenReceiver = Receiver .make (declaringClass );
4145
+ /* GRECLIPSE edit -- GROOVY-10939
4144
4146
if (call.getNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION) == null &&
4145
4147
!directMethodCallCandidate.isStatic() && objectExpression instanceof ClassExpression &&
4146
4148
!"java.lang.Class".equals(directMethodCallCandidate.getDeclaringClass().getName())) {
4147
4149
ClassNode owner = directMethodCallCandidate.getDeclaringClass();
4148
4150
addStaticTypeError("Non-static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
4149
4151
}
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
+ }
4150
4157
// GRECLIPSE add -- GROOVY-10341
4151
4158
else if (directMethodCallCandidate .isAbstract () && isSuperExpression (objectExpression ))
4152
4159
addStaticTypeError ("Abstract method " + toMethodParametersString (directMethodCallCandidate .getName (), extractTypesFromParameters (directMethodCallCandidate .getParameters ())) + " cannot be called directly" , call );
4153
4160
// GRECLIPSE end
4154
- if (chosenReceiver == null ) {
4155
- chosenReceiver = Receiver .make (directMethodCallCandidate .getDeclaringClass ());
4156
- }
4157
4161
4158
4162
ClassNode returnType = getType (directMethodCallCandidate );
4159
4163
@@ -4190,7 +4194,6 @@ else if (directMethodCallCandidate.isAbstract() && isSuperExpression(objectExpre
4190
4194
4191
4195
storeType (call , returnType );
4192
4196
storeTargetMethod (call , directMethodCallCandidate );
4193
- ClassNode declaringClass = directMethodCallCandidate .getDeclaringClass ();
4194
4197
if (declaringClass .isInterface () && directMethodCallCandidate .isStatic () && !(directMethodCallCandidate instanceof ExtensionMethodNode )) {
4195
4198
typeCheckingContext .getEnclosingClassNode ().putNodeMetaData (MINIMUM_BYTECODE_VERSION , Opcodes .V1_8 );
4196
4199
}
0 commit comments