Skip to content

Commit

Permalink
Fix for #709: disable force retention for config script alias imports
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 8, 2018
1 parent 5a2a409 commit d897df4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,47 @@ final class OrganizeImportsTests extends OrganizeImportsTestSuite {
doContentsCompareTest(contents)
}

@Test
void testOrganizeWithExtraImports6() {
addConfigScript '''\
withConfig(configuration) {
imports {
star 'groovy.transform'
alias 'Regexp', 'java.util.regex.Pattern'
}
}
'''

addGroovySource '''\
@Canonical
class One {
String string
Number number
private Regexp pattern
void setPattern(Regexp pattern) {
this.pattern = pattern
}
}
'''.stripIndent(), 'One', 'main'

String contents = '''\
@CompileStatic
final class Tests {
@org.junit.Test
void testCtors() {
One one = new One('value') // error: Cannot find matching method
Two two = new Two('value')
}
}
@Canonical @CompileStatic
class Two {
String value
}
'''.stripIndent()

doContentsCompareTest(contents)
}

@Test @NotYetImplemented
void testOrganizeWithInterleavedComments() {
String originalContents = '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public TextEdit calculateMissingImports() {
importsSlatedForRemoval.put(className, imp);
} else {
String fullName = className + " as " + imp.getAlias();
rewriter.addImport(fullName, FORCE_RETENTION);
rewriter.addImport(fullName, imp.getEnd() > 0 ? FORCE_RETENTION
: rewriter.getDefaultImportRewriteContext());
importsSlatedForRemoval.put(fullName, imp);
}
} else {
Expand Down Expand Up @@ -656,7 +657,7 @@ private void handleTypeReference(ClassNode node, boolean isAnnotation) {
visitTypeParameters(generics, name);
}

if (!node.isResolved() && node.redirect() != current) {
if (!node.isResolved() && !current.getModule().getClasses().contains(node.redirect())) {
// aliases come through as unresolved types
if (ALIASED_IMPORT.matcher(name).find()) {
doNotRemoveImport(name);
Expand Down

0 comments on commit d897df4

Please sign in to comment.