IJ-CR-134196 [java-highlighting]IDEA-352727 Incomplete model with lombok

- skip unused import in incomplete mode

GitOrigin-RevId: 537fa533381ca5db2cba1e19cae3ca402c31f8e6
This commit is contained in:
Mikhail Pyltsin
2024-05-23 11:08:54 +02:00
committed by intellij-monorepo-bot
parent 9cdce615e7
commit 9ff8676d0f
4 changed files with 41 additions and 2 deletions

View File

@@ -215,11 +215,16 @@ public final class LombokAugmentProvider extends PsiAugmentProvider implements P
ContainerUtil.exists(extensibleClass.getOwnFields(), field -> hasAnyLombokAnnotation(field.getAnnotations())) ||
(file.getImportList() != null &&
ContainerUtil.exists(file.getImportList().getAllImportStatements(), statement -> {
PsiJavaCodeReferenceElement reference = statement.getImportReference();
return reference != null && reference.getText().startsWith("lombok");
return mightBeUsedImportForIncompleteMode(statement);
}));
}
@Override
protected boolean mightBeUsedImportForIncompleteMode(@NotNull PsiImportStatementBase psiImport) {
if (psiImport instanceof PsiImportStaticStatement) return false;
PsiJavaCodeReferenceElement reference = psiImport.getImportReference();
return reference != null && reference.getText().startsWith("lombok");
}
/**
* Checks if the given PsiModifierListOwner has any Lombok annotation.

View File

@@ -1,6 +1,7 @@
package com.intellij.java.lomboktest;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInspection.unusedImport.UnusedImportInspection;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.IncompleteDependenciesService;
import com.intellij.testFramework.PlatformTestUtil;
@@ -22,6 +23,7 @@ public class LombokIncompleteModeHighlightingTest extends LightDaemonAnalyzerTes
}
private void doTest(String fileName) {
enableInspectionTools(new UnusedImportInspection());
IncompleteDependenciesService service = getProject().getService(IncompleteDependenciesService.class);
try (var ignored = asAutoCloseable(WriteAction.compute(() -> service.enterIncompleteState()))) {
doTest("/plugins/lombok/testData/highlightingIncompleteMode/" + fileName, true, true);