Skip to content

Commit

Permalink
Fix for #1257: static member resolves before Class instance field/method
Browse files Browse the repository at this point in the history
see GROOVY-1809, GROOVY-3548, GROOVY-3549, GROOVY-8350
  • Loading branch information
eric-milles committed May 10, 2021
1 parent 3c7b1b3 commit b344a94
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -926,62 +926,6 @@ public void testClassLiteral5() {
assertType(contents, "foo", "java.lang.Class<java.util.Map$Entry>");
}

@Test
public void testClassReference1() {
String contents = "String.substring";
int start = contents.indexOf("substring"), until = start + 9;
assertDeclaringType(contents, start, until, "java.lang.String", true);
}

@Test
public void testClassReference2() {
String contents = "String.getPackage()";
assertType(contents, "getPackage", "java.lang.Package");
assertDeclaringType(contents, "getPackage", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference2a() {
String contents = "String.package";
assertType(contents, "package", "java.lang.Package");
assertDeclaringType(contents, "package", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference3() {
String contents = "String.class.getPackage()";
assertType(contents, "getPackage", "java.lang.Package");
assertDeclaringType(contents, "getPackage", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference3a() {
String contents = "String.class.package";
assertType(contents, "package", "java.lang.Package");
assertDeclaringType(contents, "package", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference4() {
String contents = "def clazz = String; clazz.getPackage()";
assertType(contents, "getPackage", "java.lang.Package");
assertDeclaringType(contents, "getPackage", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference4a() {
String contents = "def clazz = String; clazz.package";
assertType(contents, "package", "java.lang.Package");
assertDeclaringType(contents, "package", "java.lang.Class<java.lang.String>");
}

@Test
public void testClassReference4b() {
String contents = "Class clazz = String; clazz.package";
assertType(contents, "package", "java.lang.Package");
assertDeclaringType(contents, "package", "java.lang.Class");
}

@Test // GRECLIPSE-1229: constructors with map parameters
public void testConstructor1() {
String contents =
Expand Down Expand Up @@ -1123,169 +1067,6 @@ public void testSpecialConstructor2() {
assertDeclaringType(contents, "super()", "java.util.HashMap");
}

@Test
public void testStaticMethod1() {
String contents = "class Two { static Number x() { 42\n}\n}\n" + "Two.x()";
assertType(contents, "x", "java.lang.Number");
}

@Test
public void testStaticMethod2() {
String contents = "class Two { static Number x() { 42\n}\n}\n" + "Two.x";
assertUnknown(contents, "x");
}

@Test
public void testStaticMethod3() {
String contents =
"class Two {\n" +
" static Number x() {\n" +
" }\n" +
" def other() {\n" +
" x()\n" + // this
" }\n" +
"}\n";
assertType(contents, "x", "java.lang.Number");
}

@Test
public void testStaticMethod4() {
String contents =
"class Two {\n" +
" static Number x() {\n" +
" }\n" +
" def other() {\n" +
" x\n" + // this
" }\n" +
"}\n";
assertUnknown(contents, "x");
}

@Test // GRECLISPE-1244
public void testStaticMethod5() {
String contents =
"class Parent {\n" +
" static p() {}\n" +
"}\n" +
"class Child extends Parent {\n" +
" def c() {\n" +
" p()\n" +
" }\n" +
"}";
assertDeclaringType(contents, "p()", "Parent");
}

@Test // GRECLISPE-1244
public void testStaticMethod6() {
createUnit("Parent",
"class Parent {\n" +
" static p() {}\n" +
"}");
String contents =
"class Child extends Parent {\n" +
" def c() {\n" +
" p()\n" +
" }\n" +
"}";
assertDeclaringType(contents, "p()", "Parent");
}

@Test
public void testStaticMethod7() {
createUnit("foo", "Bar", "package foo\n" +
"import java.util.regex.*\n" +
"class Bar {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
"}");

String contents = "import static foo.Bar.*\nmeth([])";
assertType(contents, "meth([])", "java.util.Collection");
}

@Test
public void testStaticMethod8() {
createUnit("foo", "Bar", "package foo\n" +
"import java.util.regex.*\n" +
"class Bar {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
"}");

String contents = "import static foo.Bar.*\nmeth(~/abc/)";
assertType(contents, "meth(~/abc/)", "java.util.regex.Pattern");
}

@Test
public void testStaticMethod9() {
createUnit("foo", "Bar", "package foo\n" +
"import java.util.regex.*\n" +
"class Bar {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
"}");

String contents =
"import static foo.Bar.*\n" +
"import static java.util.regex.Pattern.*\n" +
"meth(compile('abc'))";
assertType(contents, "meth(compile('abc'))", "java.util.regex.Pattern");
}

@Test
public void testStaticMethod10() {
createUnit("foo", "Bar", "package foo\n" +
"import java.util.regex.*\n" +
"abstract class Bar {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
"}");

String contents =
"import static foo.Bar.*\n" +
"import static java.util.regex.Pattern.*\n" +
"meth(compile('abc'))";
assertType(contents, "meth", "java.util.regex.Pattern");
}

@Test
public void testStaticMethod11() {
String contents =
"import static java.util.regex.Pattern.*\n" +
"import java.util.regex.*\n" +
"abstract class Bar {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
" static main(args) {\n" +
" meth(compile('abc'))\n" +
" }\n" +
"}";
assertType(contents, "meth", "java.util.regex.Pattern");
}

@Test
public void testStaticMethod12() {
String contents =
"import static java.util.regex.Pattern.*\n" +
"import java.util.regex.*\n" +
"class Foo {\n" +
" static Object meth(Object o) { return o;}\n" +
" static Pattern meth(Pattern p) { return p;}\n" +
" static Collection meth(Collection c) { return c;}\n" +
"}\n" +
"abstract class Bar extends Foo {\n" +
" static main(args) {\n" +
" meth(compile('abc'))\n" +
" }\n" +
"}";
assertType(contents, "meth", "java.util.regex.Pattern");
}

@Test
public void testStaticThisAndSuper1() {
String contents =
Expand Down Expand Up @@ -2397,38 +2178,6 @@ public void testCatchBlock5() {
assertType(catchString2, start, end, "java.lang.Exception");
}

@Test
public void testStaticImports1() {
String contents =
"import static javax.swing.text.html.HTML.NULL_ATTRIBUTE_VALUE\n" +
"NULL_ATTRIBUTE_VALUE";
assertType(contents, "NULL_ATTRIBUTE_VALUE", "java.lang.String");
}

@Test
public void testStaticImports2() {
String contents =
"import static javax.swing.text.html.HTML.getAttributeKey\n" +
"getAttributeKey('')";
assertType(contents, "getAttributeKey('')", "javax.swing.text.html.HTML$Attribute");
}

@Test
public void testStaticImports3() {
String contents =
"import static javax.swing.text.html.HTML.*\n" +
"NULL_ATTRIBUTE_VALUE";
assertType(contents, "NULL_ATTRIBUTE_VALUE", "java.lang.String");
}

@Test
public void testStaticImports4() {
String contents =
"import static javax.swing.text.html.HTML.*\n" +
"getAttributeKey('')";
assertType(contents, "getAttributeKey('')", "javax.swing.text.html.HTML$Attribute");
}

private static final String CONTENTS_GETAT1 =
"class GetAt {\n" +
" String getAt(foo) {}\n" +
Expand Down
Loading

0 comments on commit b344a94

Please sign in to comment.