From 19f1cfb076bf08033b29ff10b45eb1b1a5d51ca1 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Tue, 13 Feb 2024 20:43:17 +0100 Subject: [PATCH] make sure that unused imports check don't ignore non-fully-qualified references when a file contains fully-qualified references. (#1152) --- .../intellij/plugins/haxe/util/HaxeImportUtil.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/intellij/plugins/haxe/util/HaxeImportUtil.java b/src/main/java/com/intellij/plugins/haxe/util/HaxeImportUtil.java index 99605cea5..57e2a03d0 100644 --- a/src/main/java/com/intellij/plugins/haxe/util/HaxeImportUtil.java +++ b/src/main/java/com/intellij/plugins/haxe/util/HaxeImportUtil.java @@ -128,6 +128,7 @@ else if (referencedElement instanceof HaxeReference) { public static Collection getExternalReferences(@NotNull PsiFile file) { final Map result = new HashMap<>(); + final List names = new ArrayList<>(); file.acceptChildren(new HaxeRecursiveVisitor() { @Override @@ -135,20 +136,28 @@ 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); } } }