Skip to content

Commit

Permalink
make sure that unused imports check don't ignore non-fully-qualified …
Browse files Browse the repository at this point in the history
…references when a file contains fully-qualified references. (#1152)
  • Loading branch information
m0rkeulv committed Feb 13, 2024
1 parent 27f1155 commit 19f1cfb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/com/intellij/plugins/haxe/util/HaxeImportUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,36 @@ else if (referencedElement instanceof HaxeReference) {

public static Collection<PsiElement> getExternalReferences(@NotNull PsiFile file) {
final Map<PsiElement, PsiElement> result = new HashMap<>();
final List<String> names = new ArrayList<>();

file.acceptChildren(new HaxeRecursiveVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof HaxePackageStatement || element instanceof HaxeImportStatement || element instanceof HaxeUsingStatement) return;
if (element instanceof HaxeReference reference) {
PsiElement referencedElement = reference.resolve();
if (!result.containsKey(referencedElement)) {
// makes sure that even if we have a fully qualified a.b.SomeClass added to the list
// that any reference of just the class name (SomeClass) without package structure is also added as reference
String qualifiedName = reference.getQualifiedName();
if (!names.contains(qualifiedName)) {

boolean qualified = reference.isQualified();
if (!(qualified || referencedElement instanceof PsiPackage)){
result.put(referencedElement, element);
names.add(qualifiedName);
}
if (qualified) {
if (referencedElement instanceof HaxeClass) {
result.put(referencedElement, element);
names.add(qualifiedName);
}
if (referencedElement instanceof HaxeIdentifier) {
result.put(referencedElement, element);
names.add(qualifiedName);
}
if (referencedElement instanceof HaxeImportAlias) {
result.put(referencedElement, element);
names.add(qualifiedName);
}
}
}
Expand Down

0 comments on commit 19f1cfb

Please sign in to comment.