Skip to content

Commit

Permalink
RemoveUnusedImports should retain explicit import when there are co…
Browse files Browse the repository at this point in the history
…nflicting classes in the same package (#4482)

* Add testcase

* Apply feedback

* Apply feedback:
* fix whitespace
* clearer test method name
* clearer class name

* Apply suggestions from code review

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
Laurens-W and timtebeek authored Sep 10, 2024
1 parent 7aed57c commit 7f14d4a
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1983,4 +1983,56 @@ public void foo() {
)
);
}

@Test
void retainExplicitImportWhenConflictingClassInSamePackage() {
rewriteRun(
java(
"""
package com.a;
class ConflictingClass {
}
""",
SourceSpec::skip
),
java(
"""
package com.b;
public class ConflictingClass {
public ConflictingClass() {
}
}
""",
SourceSpec::skip
),
java(
"""
package com.c;
import com.b.ConflictingClass;
public class ImplProvider {
static ConflictingClass getImpl(){
return new ConflictingClass();
}
}
""",
SourceSpec::skip
),
java(
"""
package com.a;
import com.b.ConflictingClass;
import com.c.ImplProvider;
class CImpl {
ConflictingClass impl = ImplProvider.getImpl();
}
"""
)
);
}
}

0 comments on commit 7f14d4a

Please sign in to comment.