Move QuickFixWrapper#findSameElementInCopy to CodeInsightUtilCore (IDEA-CR-61344)

GitOrigin-RevId: a21e780d41f33453e9ca4eb060a37b9d926b9f48
This commit is contained in:
Tagir Valeev
2020-04-16 05:03:27 +00:00
committed by intellij-monorepo-bot
parent a09bfd1268
commit bfe39804db
25 changed files with 85 additions and 87 deletions
@@ -15,9 +15,9 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -137,7 +137,7 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new AddTypeArgumentsFix(QuickFixWrapper.findSameElementInCopy(myArgList, target), myIndex, myToType,
return new AddTypeArgumentsFix(CodeInsightUtilCore.findSameElementInCopy(myArgList, target), myIndex, myToType,
myArgumentFixerActionFactory);
}
@@ -2,6 +2,7 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.guess.GuessManager;
@@ -9,7 +10,6 @@ import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.HighPriorityAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
@@ -161,6 +161,6 @@ public class AddTypeCastFix extends LocalQuickFixAndIntentionActionOnPsiElement
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiExpression expression = (PsiExpression)getStartElement();
return expression == null ? null : new AddTypeCastFix(myType, QuickFixWrapper.findSameElementInCopy(expression, target));
return expression == null ? null : new AddTypeCastFix(myType, CodeInsightUtilCore.findSameElementInCopy(expression, target));
}
}
@@ -16,11 +16,11 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.HighPriorityAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -82,7 +82,7 @@ public class CastMethodArgumentFix extends MethodArgumentFix implements HighPrio
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new CastMethodArgumentFix(QuickFixWrapper.findSameElementInCopy(myArgList, target), myIndex, myToType,
return new CastMethodArgumentFix(CodeInsightUtilCore.findSameElementInCopy(myArgList, target), myIndex, myToType,
myArgumentFixerActionFactory);
}
@@ -3,13 +3,13 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.RemoveRedundantTypeArgumentsUtil;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.project.Project;
@@ -203,6 +203,6 @@ public final class ChangeNewOperatorTypeFix implements IntentionAction {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new ChangeNewOperatorTypeFix(myType, QuickFixWrapper.findSameElementInCopy(myExpression, target));
return new ChangeNewOperatorTypeFix(myType, CodeInsightUtilCore.findSameElementInCopy(myExpression, target));
}
}
@@ -15,13 +15,13 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
@@ -134,8 +134,8 @@ public final class RemoveRedundantArgumentsFix implements IntentionAction {
@Override
public @NotNull FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new RemoveRedundantArgumentsFix(
QuickFixWrapper.findSameElementInCopy(myTargetMethod, target),
ContainerUtil.map2Array(myArguments, PsiExpression.class, arg -> QuickFixWrapper.findSameElementInCopy(arg, target)),
CodeInsightUtilCore.findSameElementInCopy(myTargetMethod, target),
ContainerUtil.map2Array(myArguments, PsiExpression.class, arg -> CodeInsightUtilCore.findSameElementInCopy(arg, target)),
mySubstitutor);
}
}
@@ -1,12 +1,12 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
@@ -186,6 +186,6 @@ public class WrapExpressionFix implements IntentionAction {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new WrapExpressionFix(myExpectedType, QuickFixWrapper.findSameElementInCopy(myExpression, target));
return new WrapExpressionFix(myExpectedType, CodeInsightUtilCore.findSameElementInCopy(myExpression, target));
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.Nullability;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
@@ -23,7 +24,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.dataFlow.NullabilityUtil;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -68,7 +68,7 @@ public class WrapObjectWithOptionalOfNullableFix extends MethodArgumentFix imple
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new WrapObjectWithOptionalOfNullableFix(QuickFixWrapper.findSameElementInCopy(myArgList, target), myIndex, myToType,
return new WrapObjectWithOptionalOfNullableFix(CodeInsightUtilCore.findSameElementInCopy(myArgList, target), myIndex, myToType,
myArgumentFixerActionFactory);
}
@@ -15,13 +15,13 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.HighPriorityAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
@@ -241,7 +241,7 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new MyMethodArgumentFix(QuickFixWrapper.findSameElementInCopy(myArgList, target), myIndex, myToType,
return new MyMethodArgumentFix(CodeInsightUtilCore.findSameElementInCopy(myArgList, target), myIndex, myToType,
(Wrapper)myArgumentFixerActionFactory);
}
}
@@ -259,6 +259,6 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiExpression expression = (PsiExpression)getStartElement();
if (expression == null) return null;
return new WrapWithAdapterMethodCallFix(myType, QuickFixWrapper.findSameElementInCopy(expression, target), myWrapper);
return new WrapWithAdapterMethodCallFix(myType, CodeInsightUtilCore.findSameElementInCopy(expression, target), myWrapper);
}
}
@@ -16,7 +16,7 @@
package com.intellij.codeInsight.intention;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
@@ -58,7 +58,7 @@ public class AddAnnotationFix extends AddAnnotationPsiFix implements IntentionAc
if (element == null) return null;
// myPairs is used to copy from, so should be safe
return new AddAnnotationFix(
myAnnotation, (PsiModifierListOwner)QuickFixWrapper.findSameElementInCopy(element, target),
myAnnotation, (PsiModifierListOwner)CodeInsightUtilCore.findSameElementInCopy(element, target),
myPairs, myAnnotationsToRemove);
}
}
@@ -1,14 +1,10 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.intention;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.ExternalAnnotationsManager;
import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.codeInsight.*;
import com.intellij.codeInsight.daemon.impl.analysis.AnnotationsHighlightUtil;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.java.analysis.JavaAnalysisBundle;
import com.intellij.lang.findUsages.LanguageFindUsages;
import com.intellij.openapi.command.WriteCommandAction;
@@ -357,7 +353,7 @@ public class AddAnnotationPsiFix extends LocalQuickFixOnPsiElement {
if (element == null) return null;
// myPairs is used to copy from, so should be safe
return new AddAnnotationPsiFix(
myAnnotation, (PsiModifierListOwner)QuickFixWrapper.findSameElementInCopy(element, target),
myAnnotation, (PsiModifierListOwner)CodeInsightUtilCore.findSameElementInCopy(element, target),
myPairs, myAnnotationsToRemove);
}
}
@@ -15,10 +15,10 @@
*/
package com.intellij.codeInspection.dataFlow.fix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.java.analysis.JavaAnalysisBundle;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -64,6 +64,6 @@ public class SurroundWithRequireNonNullFix implements LocalQuickFix {
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiExpression expression = myQualifierPointer.getElement();
if (expression == null) return null;
return new SurroundWithRequireNonNullFix(QuickFixWrapper.findSameElementInCopy(expression, target));
return new SurroundWithRequireNonNullFix(CodeInsightUtilCore.findSameElementInCopy(expression, target));
}
}
@@ -15,11 +15,11 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
@@ -77,6 +77,6 @@ public final class AddMethodBodyFix implements IntentionAction {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new AddMethodBodyFix(QuickFixWrapper.findSameElementInCopy(myMethod, target));
return new AddMethodBodyFix(CodeInsightUtilCore.findSameElementInCopy(myMethod, target));
}
}
@@ -1,6 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInsight.lookup.ExpressionLookupItem;
@@ -10,7 +11,6 @@ import com.intellij.codeInsight.template.TemplateBuilderFactory;
import com.intellij.codeInsight.template.TemplateBuilderImpl;
import com.intellij.codeInsight.template.impl.ConstantNode;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.java.JavaBundle;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
@@ -144,6 +144,6 @@ public class AddVariableInitializerFix extends LocalQuickFixAndIntentionActionOn
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiElement var = getStartElement();
return var == null ? null : new AddVariableInitializerFix((PsiVariable)QuickFixWrapper.findSameElementInCopy(var, target));
return var == null ? null : new AddVariableInitializerFix((PsiVariable)CodeInsightUtilCore.findSameElementInCopy(var, target));
}
}
@@ -15,13 +15,13 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.GetterSetterPrototypeProvider;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.LowPriorityAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -144,6 +144,6 @@ public class CreateGetterOrSetterFix implements IntentionAction, LowPriorityActi
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new CreateGetterOrSetterFix(myCreateGetter, myCreateSetter, QuickFixWrapper.findSameElementInCopy(myField, target));
return new CreateGetterOrSetterFix(myCreateGetter, myCreateSetter, CodeInsightUtilCore.findSameElementInCopy(myField, target));
}
}
@@ -9,7 +9,6 @@ import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateBuilderImpl;
import com.intellij.codeInsight.template.TemplateEditingAdapter;
import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -197,6 +196,6 @@ public class CreateLocalFromUsageFix extends CreateVarFromUsageFix {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new CreateLocalFromUsageFix(QuickFixWrapper.findSameElementInCopy(myReferenceExpression, target));
return new CreateLocalFromUsageFix(CodeInsightUtilCore.findSameElementInCopy(myReferenceExpression, target));
}
}
@@ -15,10 +15,10 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
@@ -69,6 +69,6 @@ public class DeleteElementFix extends LocalQuickFixAndIntentionActionOnPsiElemen
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiElement element = getStartElement();
return element == null ? null : new DeleteElementFix(QuickFixWrapper.findSameElementInCopy(element, target), myText);
return element == null ? null : new DeleteElementFix(CodeInsightUtilCore.findSameElementInCopy(element, target), myText);
}
}
@@ -15,11 +15,11 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiCodeBlock;
@@ -77,6 +77,6 @@ public final class DeleteMethodBodyFix implements IntentionAction {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new DeleteMethodBodyFix(QuickFixWrapper.findSameElementInCopy(myMethod, target));
return new DeleteMethodBodyFix(CodeInsightUtilCore.findSameElementInCopy(myMethod, target));
}
}
@@ -2,10 +2,10 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.BlockUtils;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -81,6 +81,6 @@ public final class DeleteReturnFix extends LocalQuickFixAndIntentionActionOnPsiE
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiReturnStatement returnStatement = myStatementPtr.getElement();
if (returnStatement == null) return null;
return new DeleteReturnFix(QuickFixWrapper.findSameElementInCopy(returnStatement, target), myIsLastStatement, myHasSideEffects);
return new DeleteReturnFix(CodeInsightUtilCore.findSameElementInCopy(returnStatement, target), myIsLastStatement, myHasSideEffects);
}
}
@@ -16,12 +16,12 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.BlockUtils;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.LowPriorityAction;
import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -128,7 +128,7 @@ public class DeleteSideEffectsAwareFix extends LocalQuickFixAndIntentionActionOn
PsiExpression expression = myExpressionPtr.getElement();
PsiStatement statement = myStatementPtr.getElement();
if (expression == null || statement == null) return null;
return new DeleteSideEffectsAwareFix(QuickFixWrapper.findSameElementInCopy(statement, target),
QuickFixWrapper.findSameElementInCopy(expression, target));
return new DeleteSideEffectsAwareFix(CodeInsightUtilCore.findSameElementInCopy(statement, target),
CodeInsightUtilCore.findSameElementInCopy(expression, target));
}
}
@@ -1,11 +1,11 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.generation.surroundWith.JavaWithTryCatchSurrounder;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
@@ -93,6 +93,6 @@ public class SurroundWithTryCatchFix implements IntentionAction {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
return new SurroundWithTryCatchFix(QuickFixWrapper.findSameElementInCopy(myElement, target));
return new SurroundWithTryCatchFix(CodeInsightUtilCore.findSameElementInCopy(myElement, target));
}
}
@@ -1,10 +1,10 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingFeature;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
@@ -93,7 +93,8 @@ public class PatternVariableCanBeUsedInspection extends AbstractBaseJavaLocalIns
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiInstanceOfExpression instanceOf = myInstanceOfPointer.getElement();
return instanceOf == null ? null : new PatternVariableCanBeUsedFix(myName, QuickFixWrapper.findSameElementInCopy(instanceOf, target));
return instanceOf == null ? null : new PatternVariableCanBeUsedFix(myName, CodeInsightUtilCore
.findSameElementInCopy(instanceOf, target));
}
}
}
@@ -2,6 +2,7 @@
package com.intellij.codeInspection.ex;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.PriorityAction;
@@ -20,7 +21,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -122,9 +122,9 @@ public class QuickFixWrapper implements IntentionAction, PriorityAction {
if (result == null) return null;
PsiElement start, end, psi;
try {
start = findSameElementInCopy(myDescriptor.getStartElement(), target);
end = findSameElementInCopy(myDescriptor.getEndElement(), target);
psi = findSameElementInCopy(myDescriptor.getPsiElement(), target);
start = CodeInsightUtilCore.findSameElementInCopy(myDescriptor.getStartElement(), target);
end = CodeInsightUtilCore.findSameElementInCopy(myDescriptor.getEndElement(), target);
psi = CodeInsightUtilCore.findSameElementInCopy(myDescriptor.getPsiElement(), target);
}
catch (IllegalStateException e) {
return null;
@@ -148,34 +148,4 @@ public class QuickFixWrapper implements IntentionAction, PriorityAction {
};
return new QuickFixWrapper(descriptor, result);
}
/**
* Returns the same element in the file copy.
*
* @param element an element to find
* @param copy file that must be a copy of {@code element.getContainingFile()}
* @return found element; null if input element is null
* @throws IllegalStateException if it's detected that the supplied file is not exact copy of original file.
* The exception is thrown on a best-effort basis, so you cannot rely on it.
*/
@Contract("null, _ -> null; !null, _ -> !null")
public static <T extends PsiElement> T findSameElementInCopy(@Nullable T element, @NotNull PsiFile copy) throws IllegalStateException {
if (element == null) return null;
if (element.getClass().equals(copy.getClass())) {
//noinspection unchecked
return (T)copy;
}
TextRange range = element.getTextRange();
PsiElement newElement = copy.findElementAt(range.getStartOffset());
while (newElement != null) {
TextRange newRange = newElement.getTextRange();
if (newRange.equals(range) && newElement.getClass().equals(element.getClass())) {
//noinspection unchecked
return (T)newElement;
}
if (newRange.getStartOffset() < range.getStartOffset() || newRange.getEndOffset() > range.getEndOffset()) break;
newElement = newElement.getParent();
}
throw new IllegalStateException("Cannot find element in copy file");
}
}
@@ -18,6 +18,7 @@ package com.intellij.codeInsight;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -26,6 +27,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -233,4 +235,34 @@ public abstract class CodeInsightUtilCore extends FileModificationService {
}
return true;
}
/**
* Returns the same element in the file copy.
*
* @param element an element to find
* @param copy file that must be a copy of {@code element.getContainingFile()}
* @return found element; null if input element is null
* @throws IllegalStateException if it's detected that the supplied file is not exact copy of original file.
* The exception is thrown on a best-effort basis, so you cannot rely on it.
*/
@Contract("null, _ -> null; !null, _ -> !null")
public static <T extends PsiElement> T findSameElementInCopy(@Nullable T element, @NotNull PsiFile copy) throws IllegalStateException {
if (element == null) return null;
if (element.getClass().equals(copy.getClass())) {
//noinspection unchecked
return (T)copy;
}
TextRange range = element.getTextRange();
PsiElement newElement = copy.findElementAt(range.getStartOffset());
while (newElement != null) {
TextRange newRange = newElement.getTextRange();
if (newRange.equals(range) && newElement.getClass().equals(element.getClass())) {
//noinspection unchecked
return (T)newElement;
}
if (newRange.getStartOffset() < range.getStartOffset() || newRange.getEndOffset() > range.getEndOffset()) break;
newElement = newElement.getParent();
}
throw new IllegalStateException("Cannot find element in copy file");
}
}
@@ -1,11 +1,11 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.fixes;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInsight.template.TemplateBuilder;
import com.intellij.codeInsight.template.TemplateBuilderFactory;
import com.intellij.codeInsight.template.impl.ConstantNode;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
@@ -138,6 +138,6 @@ public final class CreateDefaultBranchFix extends BaseSwitchFix {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiSwitchBlock block = myBlock.getElement();
return block == null ? null : new CreateDefaultBranchFix(QuickFixWrapper.findSameElementInCopy(block, target), myMessage);
return block == null ? null : new CreateDefaultBranchFix(CodeInsightUtilCore.findSameElementInCopy(block, target), myMessage);
}
}
@@ -1,8 +1,8 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.fixes;
import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.intention.FileModifier;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.psi.*;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.InspectionGadgetsBundle;
@@ -61,6 +61,6 @@ public final class CreateMissingSwitchBranchesFix extends BaseSwitchFix {
@Override
public @Nullable FileModifier getFileModifierForPreview(@NotNull PsiFile target) {
PsiSwitchBlock block = myBlock.getElement();
return block == null ? null : new CreateMissingSwitchBranchesFix(QuickFixWrapper.findSameElementInCopy(block, target), myNames);
return block == null ? null : new CreateMissingSwitchBranchesFix(CodeInsightUtilCore.findSameElementInCopy(block, target), myNames);
}
}