Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.intellij.java.language.psi.PsiField;
import com.intellij.java.language.psi.PsiMethod;
import com.intellij.java.language.psi.util.PsiUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.java.deadCodeNotWorking.OldStyleInspection;
import consulo.language.Language;
import consulo.language.editor.inspection.*;
Expand Down Expand Up @@ -50,6 +51,7 @@ public Set<JavaFeature> requiredFeatures() {
}

@Override
@RequiredReadAction
public boolean isAvailableForFile(@Nonnull PsiFile file) {
for (JavaFeature feature : requiredFeatures()) {
if (!PsiUtil.isAvailable(feature, file)) {
Expand Down Expand Up @@ -154,26 +156,31 @@ public PsiElementVisitor buildVisitorImpl(
) {
return new JavaElementVisitor() {
@Override
public void visitMethod(PsiMethod method) {
@RequiredReadAction
public void visitMethod(@Nonnull PsiMethod method) {
addDescriptors(checkMethod(method, holder.getManager(), isOnTheFly, state));
}

@Override
public void visitClass(PsiClass aClass) {
@RequiredReadAction
public void visitClass(@Nonnull PsiClass aClass) {
addDescriptors(checkClass(aClass, holder.getManager(), isOnTheFly, state));
}

@Override
public void visitField(PsiField field) {
@RequiredReadAction
public void visitField(@Nonnull PsiField field) {
addDescriptors(checkField(field, holder.getManager(), isOnTheFly, state));
}

@Override
@RequiredReadAction
public void visitFile(PsiFile file) {
addDescriptors(checkFile(file, holder.getManager(), isOnTheFly, state));
}

private void addDescriptors(final ProblemDescriptor[] descriptors) {
@RequiredReadAction
private void addDescriptors(ProblemDescriptor[] descriptors) {
if (descriptors != null) {
for (ProblemDescriptor descriptor : descriptors) {
holder.registerProblem(descriptor);
Expand All @@ -184,7 +191,7 @@ private void addDescriptors(final ProblemDescriptor[] descriptors) {
}

@Override
public PsiNamedElement getProblemElement(final PsiElement psiElement) {
public PsiNamedElement getProblemElement(PsiElement psiElement) {
return PsiTreeUtil.getNonStrictParentOfType(psiElement, PsiFile.class, PsiClass.class, PsiMethod.class, PsiField.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

/**
* @author VISTALL
* @since 19/03/2023
* @since 2023-03-19
*/
public class DataFlowInspectionStateBase
{
public boolean SUGGEST_NULLABLE_ANNOTATIONS;
public boolean DONT_REPORT_TRUE_ASSERT_STATEMENTS;
public boolean TREAT_UNKNOWN_MEMBERS_AS_NULLABLE;
public boolean IGNORE_ASSERT_STATEMENTS;
public boolean REPORT_CONSTANT_REFERENCE_VALUES = true;
public boolean REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER = true;
public boolean REPORT_NULLABLE_METHODS_RETURNING_NOT_NULL = true;
public boolean REPORT_UNSOUND_WARNINGS = true;
public class DataFlowInspectionStateBase {
public boolean SUGGEST_NULLABLE_ANNOTATIONS;
public boolean DONT_REPORT_TRUE_ASSERT_STATEMENTS;
public boolean TREAT_UNKNOWN_MEMBERS_AS_NULLABLE;
public boolean IGNORE_ASSERT_STATEMENTS;
public boolean REPORT_CONSTANT_REFERENCE_VALUES = true;
public boolean REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER = true;
public boolean REPORT_NULLABLE_METHODS_RETURNING_NOT_NULL = true;
public boolean REPORT_UNSOUND_WARNINGS = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static NullabilityProblem<?> fromContext(
}
PsiElement parent = context.getParent();
if (parent instanceof PsiReferenceExpression refExpr) {
if (refExpr.resolve() instanceof PsiMember member && member.hasModifierProperty(PsiModifier.STATIC)) {
if (refExpr.resolve() instanceof PsiMember member && member.isStatic()) {
return null;
}
if (parent.getParent() instanceof PsiMethodCallExpression methodCall) {
Expand Down Expand Up @@ -400,7 +400,7 @@ private static NullabilityProblem<?> getAssignmentProblem(
}
if (nullability == Nullability.UNKNOWN && lho instanceof PsiReferenceExpression lhoRefExpr) {
PsiField field = ObjectUtil.tryCast(lhoRefExpr.resolve(), PsiField.class);
if (field != null && !field.hasModifierProperty(PsiModifier.FINAL)) {
if (field != null && !field.isFinal()) {
return assigningToNonAnnotatedField.problem(context, expression);
}
}
Expand Down Expand Up @@ -573,17 +573,17 @@ public PsiExpression getDereferencedExpression() {
}

@Nonnull
public String getMessage(Map<PsiExpression, DataFlowInspectionBase.ConstantResult> expressions) {
public LocalizeValue getMessage(Map<PsiExpression, DataFlowInspectionBase.ConstantResult> expressions) {
if (myKind.myAlwaysNullMessage == null || myKind.myNormalMessage == null) {
throw new IllegalStateException("This problem kind has no message associated: " + myKind);
}
PsiExpression expression = PsiUtil.skipParenthesizedExprDown(getDereferencedExpression());
if (expression != null) {
if (ExpressionUtils.isNullLiteral(expression) || expressions.get(expression) == DataFlowInspectionBase.ConstantResult.NULL) {
return myKind.myAlwaysNullMessage.get();
return myKind.myAlwaysNullMessage;
}
}
return myKind.myNormalMessage.get();
return myKind.myNormalMessage;
}

@Nonnull
Expand All @@ -600,8 +600,8 @@ public boolean equals(Object o) {
return false;
}
NullabilityProblem<?> problem = (NullabilityProblem<?>)o;
return myKind.equals(problem.myKind) && myAnchor.equals(problem.myAnchor) &&
Objects.equals(myDereferencedExpression, problem.myDereferencedExpression);
return myKind.equals(problem.myKind) && myAnchor.equals(problem.myAnchor)
&& Objects.equals(myDereferencedExpression, problem.myDereferencedExpression);
}

@Override
Expand Down
Loading
Loading