mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[lombok] IDEA-255688 Get rid of LombokHighlightErrorFilter for "Variable initialized before usage Inspection"
Used in case of lombok lazy Getter GitOrigin-RevId: 37699b68fd2431efe92d05e86a3b09cb59e673b8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
69eb85b4f8
commit
b2853a3590
@@ -150,21 +150,6 @@ public class LombokHighlightErrorFilter implements HighlightInfoFilter {
|
||||
}
|
||||
|
||||
private enum LombokHighlightFilter {
|
||||
// ERROR HANDLERS
|
||||
|
||||
//see com.intellij.java.lomboktest.LombokHighlightingTest.testGetterLazyVariableNotInitialized
|
||||
VARIABLE_MIGHT_NOT_BEEN_INITIALIZED(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES) {
|
||||
@Override
|
||||
public boolean descriptionCheck(@Nullable String description, PsiElement highlightedElement) {
|
||||
return JavaErrorBundle.message("variable.not.initialized", highlightedElement.getText()).equals(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(@NotNull PsiElement highlightedElement) {
|
||||
return !LazyGetterHandler.isLazyGetterHandled(highlightedElement);
|
||||
}
|
||||
},
|
||||
|
||||
// WARNINGS HANDLERS
|
||||
|
||||
// field should have lazy getter and should be initialized in constructors
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.plushnikov.intellij.plugin.provider;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.VariableInitializedBeforeUsageSupport;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import de.plushnikov.intellij.plugin.LombokClassNames;
|
||||
import de.plushnikov.intellij.plugin.util.PsiAnnotationUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* A class that implements the VariableInitializedBeforeUsageSupport interface to provide support for Lombok annotated variables.
|
||||
* It checks if a variable expression should be ignored based on Lombok annotations.
|
||||
*/
|
||||
public class LombokVariableInitializedBeforeUsageSupport implements VariableInitializedBeforeUsageSupport {
|
||||
@Override
|
||||
public boolean ignoreVariableExpression(@NotNull PsiReferenceExpression psiExpression, @NotNull PsiVariable psiVariable) {
|
||||
final PsiField field = PsiTreeUtil.getParentOfType(psiExpression, PsiField.class);
|
||||
if (field == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiAnnotation getterAnnotation = field.getAnnotation(LombokClassNames.GETTER);
|
||||
return null != getterAnnotation && PsiAnnotationUtil.getBooleanAnnotationValue(getterAnnotation, "lazy", false);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@
|
||||
<lang.jvm.annotationPackageSupport implementation="de.plushnikov.intellij.plugin.provider.LombokAnnotationSupport"/>
|
||||
<lang.jvm.ignoreAnnotationParamSupport implementation="de.plushnikov.intellij.plugin.provider.LombokDefaultAnnotationParamSupport"/>
|
||||
<lang.jvm.ignoreVariableInitializerSupport implementation="de.plushnikov.intellij.plugin.provider.LombokVariableInitializerSupport"/>
|
||||
<lang.jvm.ignoreVariableInitializedBeforeUsageSupport implementation="de.plushnikov.intellij.plugin.provider.LombokVariableInitializedBeforeUsageSupport"/>
|
||||
<implicitUsageProvider implementation="de.plushnikov.intellij.plugin.provider.LombokImplicitUsageProvider"/>
|
||||
<projectConfigurable groupId="language"
|
||||
key="plugin.settings.title" bundle="messages.LombokBundle"
|
||||
|
||||
@@ -13,8 +13,7 @@ public class GetterLazyInvocationProduceNPE {
|
||||
}
|
||||
}
|
||||
|
||||
// no warning descr="Field 'bar' may be 'final'" any more?
|
||||
private Bar bar;
|
||||
private Bar <warning descr="Field 'bar' may be 'final'">bar</warning>;
|
||||
private Car car;
|
||||
|
||||
public GetterLazyInvocationProduceNPE(Bar bar, Car car) {
|
||||
|
||||
Reference in New Issue
Block a user