Search in sources :

Example 86 with IntentionAction

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

the class QuickFixFactoryImpl method registerFixesForUnusedParameter.

@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
    Project myProject = parameter.getProject();
    InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
    UnusedDeclarationInspectionBase unusedParametersInspection = (UnusedDeclarationInspectionBase) profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.SHORT_NAME, parameter);
    LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
    List<IntentionAction> options = new ArrayList<>();
    HighlightDisplayKey myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME);
    options.addAll(IntentionManager.getInstance().getStandardIntentionOptions(myUnusedSymbolKey, parameter));
    if (unusedParametersInspection != null) {
        SuppressQuickFix[] batchSuppressActions = unusedParametersInspection.getBatchSuppressActions(parameter);
        Collections.addAll(options, SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions));
    }
    //need suppress from Unused Parameters but settings from Unused Symbol
    QuickFixAction.registerQuickFixAction((HighlightInfo) highlightInfo, new SafeDeleteFix(parameter), options, HighlightDisplayKey.getDisplayNameByKey(myUnusedSymbolKey));
}
Also used : UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) Project(com.intellij.openapi.project.Project) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) ArrayList(java.util.ArrayList)

Example 87 with IntentionAction

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

the class QuickFixWrapper method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    PsiElement psiElement = myDescriptor.getPsiElement();
    if (psiElement == null || !psiElement.isValid())
        return false;
    final LocalQuickFix fix = getFix();
    return !(fix instanceof IntentionAction) || ((IntentionAction) fix).isAvailable(project, editor, file);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElement(com.intellij.psi.PsiElement)

Example 88 with IntentionAction

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

the class WebReferencesAnnotatorBase method apply.

@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
    if (infos == null || infos.length == 0) {
        return;
    }
    final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
    for (MyInfo info : infos) {
        if (!info.myResult) {
            final PsiElement element = info.myAnchor.retrieve();
            if (element != null) {
                final int start = element.getTextRange().getStartOffset();
                final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
                final String message = getErrorMessage(info.myUrl);
                final Annotation annotation;
                if (displayLevel == HighlightDisplayLevel.ERROR) {
                    annotation = holder.createErrorAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WARNING) {
                    annotation = holder.createWarningAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
                    annotation = holder.createInfoAnnotation(range, message);
                } else {
                    annotation = holder.createWarningAnnotation(range, message);
                }
                for (IntentionAction action : getQuickFixes()) {
                    annotation.registerFix(action);
                }
            }
        }
    }
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) Annotation(com.intellij.lang.annotation.Annotation)

Example 89 with IntentionAction

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

the class OrderEntryTest method doTest.

private void doTest(String fileName) throws Exception {
    String testFullPath = BASE_PATH + fileName;
    VirtualFile root = ModuleRootManager.getInstance(myModule).getContentRoots()[0].getParent();
    VirtualFile virtualFile = root.findFileByRelativePath(fileName);
    configureByExistingFile(virtualFile);
    ActionHint actionHint = ActionHint.parse(getFile(), getFile().getText());
    Collection<HighlightInfo> infosBefore = highlightErrors();
    final IntentionAction action = findActionAndCheck(actionHint, infosBefore);
    if (action != null) {
        String text = action.getText();
        WriteCommandAction.runWriteCommandAction(null, () -> action.invoke(getProject(), getEditor(), getFile()));
        Collection<HighlightInfo> infosAfter = highlightErrors();
        final IntentionAction afterAction = findActionWithText(text);
        if (afterAction != null) {
            fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
        }
        assertEquals(infosBefore.size() - 1, infosAfter.size());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

Example 90 with IntentionAction

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

the class StaticImportMethodWithCommonNameTest method testFindStaticMember.

public void testFindStaticMember() throws Exception {
    myFixture.configureByText("a.java", "class A { {String s = for<caret>mat(\"\",\"\");}}");
    final IntentionAction intention = myFixture.findSingleIntention(QuickFixBundle.message("static.import.method.text"));
    assertNotNull(intention);
    myFixture.launchAction(intention);
    myFixture.checkResult("import static java.lang.String.format;\n" + "\n" + "class A { {String s = format(\"\",\"\");}}", false);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

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