Skip to content

Commit

Permalink
Fix for #1382: static, explicit-this reference to private static field
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 23, 2022
1 parent 8cf63f5 commit fcc22a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2021 the original author or authors.
* Copyright 2009-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -566,26 +566,68 @@ public void testStaticReference27() {

@Test
public void testStaticReference28() {
String contents =
"class C {\n" +
" static String getName() {'foo'}\n" +
" static void sm() {\n" +
" this.getName()\n" +
" this.name\n" +
" }\n" +
"}\n";
assertKnown(contents, "getName", "C", "java.lang.String");
assertKnown(contents, "name", "C", "java.lang.String");
}

@Test
public void testStaticReference29() {
String contents =
"class C {\n" +
" final static String name = 'foo'\n" +
" static void sm() {\n" +
" this.getName()\n" +
" this.name\n" +
" }\n" +
"}\n";
assertKnown(contents, "getName", "C", "java.lang.String");
assertKnown(contents, "name", "C", "java.lang.String");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1382
public void testStaticReference30() {
String contents =
"class C {\n" +
" private static String name = 'foo'\n" +
" static void sm() {\n" +
" this.getName()\n" +
" this.name\n" +
" }\n" +
"}\n";
assertKnown(contents, "getName", "java.lang.Class", "java.lang.String");
assertKnown(contents, "name", "C", "java.lang.String");
}

@Test
public void testStaticReference31() {
String contents =
"static getStaticProperty() {}\n" +
"static staticMethod() {\n" +
" getStaticProperty()\n" +
" staticProperty\n" +
"}\n";
assertKnown(contents, "getStaticProperty", "Search", "java.lang.Object");
assertKnown(contents, "staticProperty", "Search", "java.lang.Object");
assertKnown(contents, "staticProperty", "Search", "java.lang.Object");
}

@Test
public void testStaticReference29() {
public void testStaticReference32() {
String contents =
"static getStaticProperty() {}\n" +
"def scriptMethod() {\n" +
" getStaticProperty()\n" +
" staticProperty\n" +
"}\n";
assertKnown(contents, "getStaticProperty", "Search", "java.lang.Object");
assertKnown(contents, "staticProperty", "Search", "java.lang.Object");
assertKnown(contents, "staticProperty", "Search", "java.lang.Object");
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected TypeLookupResult findTypeForNameWithKnownObjectExpression(final String
if (isSuperObjectExpression(scope)) {
confidence = TypeConfidence.UNKNOWN;
// "this.field" reference to private field of super class yields MissingPropertyException
} else if (isThisObjectExpression(scope) && isNotThisOrOuterClass(declaringType, resolvedDeclaringType)) {
} else if (isThisObjectExpression(scope) && isNotThisOrOuterClass(declaring, resolvedDeclaringType)) {
confidence = TypeConfidence.UNKNOWN;
}
}
Expand All @@ -424,7 +424,7 @@ protected TypeLookupResult findTypeForNameWithKnownObjectExpression(final String
GroovyUtils.getGroovyVersion().getMajor() > 3) // GROOVY-9851
confidence = TypeConfidence.UNKNOWN;
// "this.method()" reference to private method of super class yields MissingMethodException
} else if (isThisObjectExpression(scope) && isNotThisOrOuterClass(declaringType, resolvedDeclaringType)) {
} else if (isThisObjectExpression(scope) && isNotThisOrOuterClass(declaring, resolvedDeclaringType)) {
confidence = TypeConfidence.UNKNOWN;
}
} else if (method.getName().startsWith("is") && !name.startsWith("is") && !scope.isMethodCall() && isSuperObjectExpression(scope) && GroovyUtils.getGroovyVersion().getMajor() < 4) {
Expand Down

0 comments on commit fcc22a7

Please sign in to comment.