Skip to content

Commit

Permalink
Fix for #1243: keep imports that StaticImportVisitor skips as unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 15, 2021
1 parent 51e7349 commit e5dcc3b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2021 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 @@ -82,6 +82,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E as X
|X x
Expand All @@ -94,6 +95,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E as X
|X.F x = null
Expand All @@ -106,6 +108,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E as X
|X.F.G x = null
Expand All @@ -118,6 +121,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E as X
|def x = X.F.G.H
Expand All @@ -130,6 +134,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E.F as X
|X x = null
Expand All @@ -142,6 +147,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E.F as X
|X.G x = null
Expand All @@ -154,6 +160,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E.F as X
|def x = X.G.H
Expand All @@ -166,6 +173,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E.F.G as X
|X x = null
Expand All @@ -178,6 +186,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''\
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import a.b.c.d.E.F.G as X
|def x = X.H
Expand Down Expand Up @@ -320,6 +329,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| static getFineName() {}
|}
|'''

String contents = '''\
|import static p.Q.getBadName as getGoodName
|import static p.Q.getFineName
Expand All @@ -337,6 +347,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| static void setFineName(value) {}
|}
|'''

String contents = '''\
|import static p.Q.setBadName as setGoodName
|import static p.Q.setFineName
Expand All @@ -354,6 +365,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| static getFineName() {}
|}
|'''

String contents = '''\
|import static p.Q.getBadName as getGoodName
|import static p.Q.getFineName
Expand All @@ -375,6 +387,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| static void setFineName(value) {}
|}
|'''

String contents = '''\
|import static p.Q.setBadName as setGoodName
|import static p.Q.setFineName
Expand All @@ -400,6 +413,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| }
|}
|'''

String contents = '''\
|import static other.Wrapper.Feature.TopRanking as feature
|import static other.Wrapper.Feature.values as features
Expand All @@ -416,6 +430,7 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
createGroovyType 'a.b.c.d', 'E', '''
|interface E { interface F { interface G { String H = 'I' } } }
|'''

String contents = '''\
|import static a.b.c.d.E.F.G.H as X
|def x = X
Expand All @@ -437,6 +452,24 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
doContentsCompareTest(contents)
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1243
void testRetainStaticAlias10() {
String contents = '''\
|import static p.T.f as v
|print v
|'''
doContentsCompareTest(contents)
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1243
void testRetainStaticAlias11() {
String contents = '''\
|import static p.T.m as f
|f('x')
|'''
doContentsCompareTest(contents)
}

@Test
void testRemoveStaticAlias1() {
String originalContents = '''\
Expand Down Expand Up @@ -643,7 +676,6 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
| }
|}
|'''

doContentsCompareTest(originalContents, expectedContents)
}

Expand All @@ -664,7 +696,6 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite {
|TimeUnit units = DAYS
|units = MILLIS
|'''

doContentsCompareTest(contents)
}

Expand Down
Loading

0 comments on commit e5dcc3b

Please sign in to comment.