mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ReplaceWithTernaryOperatorFix: disable in batch mode; check document (IDEA-CR-40010)
This commit is contained in:
+3
-3
@@ -227,7 +227,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected List<LocalQuickFix> createMethodReferenceNPEFixes(PsiMethodReferenceExpression methodRef) {
|
||||
protected List<LocalQuickFix> createMethodReferenceNPEFixes(PsiMethodReferenceExpression methodRef, boolean onTheFly) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
|
||||
});
|
||||
NullabilityProblemKind.callMethodRefNPE.ifMyProblem(problem, methodRef ->
|
||||
holder.registerProblem(methodRef, InspectionsBundle.message("dataflow.message.npe.methodref.invocation"),
|
||||
createMethodReferenceNPEFixes(methodRef).toArray(LocalQuickFix.EMPTY_ARRAY)));
|
||||
createMethodReferenceNPEFixes(methodRef, holder.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY)));
|
||||
NullabilityProblemKind.callNPE.ifMyProblem(problem, call -> reportCallMayProduceNpe(holder, problem.getMessage(expressions), call));
|
||||
NullabilityProblemKind.passingNullableToNotNullParameter.ifMyProblem(problem, expr -> reportNullableArgument(holder, expr, expressions));
|
||||
NullabilityProblemKind.arrayAccessNPE.ifMyProblem(problem, expression -> {
|
||||
@@ -881,7 +881,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
|
||||
if (anchor.getParent() instanceof PsiMethodReferenceExpression) {
|
||||
PsiMethodReferenceExpression methodRef = (PsiMethodReferenceExpression)anchor.getParent();
|
||||
holder.registerProblem(methodRef, InspectionsBundle.message("dataflow.message.passing.nullable.argument.methodref"),
|
||||
createMethodReferenceNPEFixes(methodRef).toArray(LocalQuickFix.EMPTY_ARRAY));
|
||||
createMethodReferenceNPEFixes(methodRef, holder.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY));
|
||||
}
|
||||
else {
|
||||
PsiExpression expression = PsiUtil.skipParenthesizedExprDown((PsiExpression)anchor);
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.intellij.codeInspection;
|
||||
import com.intellij.codeInsight.template.TemplateBuilder;
|
||||
import com.intellij.codeInsight.template.TemplateBuilderFactory;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -83,10 +85,14 @@ public class ReplaceWithTernaryOperatorFix implements LocalQuickFix {
|
||||
Project project = file.getProject();
|
||||
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
|
||||
if (editor != null) {
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
||||
TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(elseExpression);
|
||||
builder.replaceElement(elseExpression, new ConstantNode(elseExpression.getText()));
|
||||
builder.run(editor, true);
|
||||
Document document = editor.getDocument();
|
||||
PsiFile topLevelFile = InjectedLanguageManager.getInstance(project).getTopLevelFile(file);
|
||||
if (topLevelFile != null && document == topLevelFile.getViewProvider().getDocument()) {
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
|
||||
TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(elseExpression);
|
||||
builder.replaceElement(elseExpression, new ConstantNode(elseExpression.getText()));
|
||||
builder.run(editor, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +109,12 @@ public class DataFlowInspection extends DataFlowInspectionBase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<LocalQuickFix> createMethodReferenceNPEFixes(PsiMethodReferenceExpression methodRef) {
|
||||
protected List<LocalQuickFix> createMethodReferenceNPEFixes(PsiMethodReferenceExpression methodRef, boolean onTheFly) {
|
||||
List<LocalQuickFix> fixes = new ArrayList<>();
|
||||
ContainerUtil.addIfNotNull(fixes, StreamFilterNotNullFix.makeFix(methodRef));
|
||||
fixes.add(new ReplaceWithTernaryOperatorFix.ReplaceMethodRefWithTernaryOperatorFix());
|
||||
if (onTheFly) {
|
||||
fixes.add(new ReplaceWithTernaryOperatorFix.ReplaceMethodRefWithTernaryOperatorFix());
|
||||
}
|
||||
return fixes;
|
||||
}
|
||||
|
||||
@@ -153,7 +155,7 @@ public class DataFlowInspection extends DataFlowInspectionBase {
|
||||
fixes.add(new SurroundWithIfFix(qualifier));
|
||||
}
|
||||
|
||||
if (ReplaceWithTernaryOperatorFix.isAvailable(qualifier, expression)) {
|
||||
if (onTheFly && ReplaceWithTernaryOperatorFix.isAvailable(qualifier, expression)) {
|
||||
fixes.add(new ReplaceWithTernaryOperatorFix(qualifier));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user