Search in sources :

Example 51 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class SuperClassHasFrequentlyUsedInheritorsInspectionTest method doTest.

private void doTest(final int expectedSize) {
    myFixture.configureByFile(getTestName(false) + ".java");
    myFixture.enableInspections(SuperClassHasFrequentlyUsedInheritorsInspection.class);
    final Set<Pair<String, Integer>> actualSet = new HashSet<Pair<String, Integer>>();
    for (IntentionAction intentionAction : myFixture.getAvailableIntentions()) {
        if (intentionAction instanceof QuickFixWrapper) {
            ChangeSuperClassFix changeSuperClassFix = getQuickFixFromWrapper((QuickFixWrapper) intentionAction);
            if (changeSuperClassFix != null) {
                actualSet.add(Pair.create(changeSuperClassFix.getNewSuperClass().getQualifiedName(), changeSuperClassFix.getPercent()));
            }
        }
    }
    assertSize(expectedSize, actualSet);
}
Also used : ChangeSuperClassFix(com.intellij.codeInspection.inheritance.ChangeSuperClassFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) HashSet(com.intellij.util.containers.HashSet) Pair(com.intellij.openapi.util.Pair)

Example 52 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class RawTypeCanBeGenericTest method doTest.

private void doTest(String intentionName) {
    myFixture.configureByFiles(getTestName(false) + ".java");
    final IntentionAction singleIntention = myFixture.findSingleIntention(intentionName);
    myFixture.launchAction(singleIntention);
    myFixture.checkResultByFile(getTestName(false) + ".java", getTestName(false) + "_after.java", true);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 53 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class BlockMarkerCommentsTest method doTestQuickFix.

private void doTestQuickFix() {
    final String testFileName = getTestName(false);
    myFixture.enableInspections(new BlockMarkerCommentsInspection());
    myFixture.configureByFile(testFileName + ".java");
    final IntentionAction intentionAction = myFixture.findSingleIntention("Remove block marker comments");
    assertNotNull(intentionAction);
    myFixture.launchAction(intentionAction);
    myFixture.checkResultByFile(testFileName + "_after.java", true);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 54 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class DaemonAnalyzerTestCase method findAndInvokeIntentionAction.

protected static void findAndInvokeIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor, @NotNull PsiFile file) {
    List<IntentionAction> actions = getIntentionActions(infos, editor, file);
    IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
    if (intentionAction == null) {
        fail(String.format("Could not find action by name %s.\n" + "Actions: [%s]\n" + "HighlightInfos: [%s]", intentionActionName, StringUtil.join(ContainerUtil.map(actions, c -> c.getText()), ", "), StringUtil.join(infos, ", ")));
    }
    CodeInsightTestFixtureImpl.invokeIntention(intentionAction, file, editor, intentionActionName);
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) InspectionToolProvider(com.intellij.codeInspection.InspectionToolProvider) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) StartupManagerEx(com.intellij.ide.startup.StartupManagerEx) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ReferenceProvidersRegistry(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry) LanguageAnnotators(com.intellij.lang.LanguageAnnotators) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) TIntArrayList(gnu.trove.TIntArrayList) LightQuickFixTestCase(com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase) Extensions(com.intellij.openapi.extensions.Extensions) Collection(java.util.Collection) TextRange(com.intellij.openapi.util.TextRange) JavaFileType(com.intellij.ide.highlighter.JavaFileType) XmlFileNSInfoProvider(com.intellij.psi.xml.XmlFileNSInfoProvider) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) StdLanguages(com.intellij.lang.StdLanguages) com.intellij.psi(com.intellij.psi) IndexPatternBuilder(com.intellij.psi.impl.search.IndexPatternBuilder) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DaemonCodeAnalyzerEx(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) HighlightTestInfo(com.intellij.testFramework.HighlightTestInfo) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) StartupManager(com.intellij.openapi.startup.StartupManager) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) JavaLanguage(com.intellij.lang.java.JavaLanguage) FileTreeAccessFilter(com.intellij.testFramework.FileTreeAccessFilter) CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Editor(com.intellij.openapi.editor.Editor) File(java.io.File) ExternalAnnotatorsFilter(com.intellij.lang.ExternalAnnotatorsFilter) InspectionsKt(com.intellij.testFramework.InspectionsKt) Result(com.intellij.openapi.application.Result) XmlSchemaProvider(com.intellij.xml.XmlSchemaProvider) Pair(com.intellij.openapi.util.Pair) com.intellij.openapi.vfs(com.intellij.openapi.vfs) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) RetentionPolicy(java.lang.annotation.RetentionPolicy) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 55 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class DefaultQuickFixProvider method registerPriorityActions.

private static void registerPriorityActions(@NotNull QuickFixActionRegistrar registrar, @NotNull TextRange fixRange, @NotNull PsiReferenceExpression refExpr) {
    final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(refExpr.getProject());
    final Map<VariableKind, IntentionAction> map = new EnumMap<>(VariableKind.class);
    map.put(VariableKind.FIELD, new CreateFieldFromUsageFix(refExpr));
    map.put(VariableKind.STATIC_FINAL_FIELD, new CreateConstantFieldFromUsageFix(refExpr));
    if (!refExpr.isQualified()) {
        map.put(VariableKind.LOCAL_VARIABLE, new CreateLocalFromUsageFix(refExpr));
        map.put(VariableKind.PARAMETER, new CreateParameterFromUsageFix(refExpr));
    }
    final VariableKind kind = getKind(styleManager, refExpr);
    if (map.containsKey(kind)) {
        map.put(kind, PriorityIntentionActionWrapper.highPriority(map.get(kind)));
    }
    for (IntentionAction action : map.values()) {
        registrar.register(fixRange, action, null);
    }
}
Also used : JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) EnumMap(java.util.EnumMap) VariableKind(com.intellij.psi.codeStyle.VariableKind)

Aggregations

IntentionAction (com.intellij.codeInsight.intention.IntentionAction)242 VirtualFile (com.intellij.openapi.vfs.VirtualFile)39 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)31 NotNull (org.jetbrains.annotations.NotNull)23 Project (com.intellij.openapi.project.Project)20 TextRange (com.intellij.openapi.util.TextRange)20 Editor (com.intellij.openapi.editor.Editor)17 PsiFile (com.intellij.psi.PsiFile)17 Annotation (com.intellij.lang.annotation.Annotation)16 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 ArrayList (java.util.ArrayList)14 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)10 QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)9 Pair (com.intellij.openapi.util.Pair)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)7 EmptyIntentionAction (com.intellij.codeInsight.intention.EmptyIntentionAction)6 AndroidMissingOnClickHandlerInspection (org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)5 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)5