Search in sources :

Example 26 with IntentionAction

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

the class AlphaUnsortedInspectionTest method testFixComments.

public void testFixComments() {
    myFixture.configureByText("p.properties", "a=a\n" + "d=d\n" + "# some comment on \"e\"\n" + "# this is multiline comment\n" + "e=e\n" + "b=b\n" + "c=b");
    myFixture.enableInspections(new AlphaUnsortedPropertiesFileInspection());
    final IntentionAction intention = myFixture.getAvailableIntention("Sort resource bundle files", "p.properties");
    assertNotNull(intention);
    myFixture.launchAction(intention);
    myFixture.checkResult("a=a\n" + "b=b\n" + "c=b\n" + "d=d\n" + "# some comment on \"e\"\n" + "# this is multiline comment\n" + "e=e");
}
Also used : AlphaUnsortedPropertiesFileInspection(com.intellij.codeInspection.unsorted.AlphaUnsortedPropertiesFileInspection) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 27 with IntentionAction

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

the class XsltNamespaceContext method getUnresolvedNamespaceFixesStatic.

public static IntentionAction[] getUnresolvedNamespaceFixesStatic(PsiReference reference, String localName) {
    final XmlElementFactory factory = XmlElementFactory.getInstance(reference.getElement().getProject());
    final XmlTag tag = factory.createTagFromText("<" + reference.getCanonicalText() + ":" + localName + " />", XMLLanguage.INSTANCE);
    final XmlFile xmlFile = PsiTreeUtil.getContextOfType(reference.getElement(), XmlFile.class, true);
    return new IntentionAction[] { new MyCreateNSDeclarationAction(tag, reference.getCanonicalText(), xmlFile) };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlElementFactory(com.intellij.psi.XmlElementFactory) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) XmlTag(com.intellij.psi.xml.XmlTag)

Example 28 with IntentionAction

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

the class FormClassAnnotator method annotateFormField.

private static void annotateFormField(final PsiField field, final PsiFile boundForm, final AnnotationHolder holder) {
    Annotation boundFieldAnnotation = holder.createInfoAnnotation(field, null);
    boundFieldAnnotation.setGutterIconRenderer(new BoundIconRenderer(field));
    LOG.assertTrue(boundForm instanceof PsiPlainTextFile);
    final PsiType guiComponentType = FormReferenceProvider.getGUIComponentType((PsiPlainTextFile) boundForm, field.getName());
    if (guiComponentType != null) {
        final PsiType fieldType = field.getType();
        if (!fieldType.isAssignableFrom(guiComponentType)) {
            String message = UIDesignerBundle.message("bound.field.type.mismatch", guiComponentType.getCanonicalText(), fieldType.getCanonicalText());
            Annotation annotation = holder.createErrorAnnotation(field.getTypeElement(), message);
            annotation.registerFix(new ChangeFormComponentTypeFix((PsiPlainTextFile) boundForm, field.getName(), field.getType()), null, null);
            annotation.registerFix(new ChangeBoundFieldTypeFix(field, guiComponentType), null, null);
        }
    }
    if (field.hasInitializer()) {
        final String message = UIDesignerBundle.message("field.is.overwritten.by.generated.code", field.getName());
        Annotation annotation = holder.createWarningAnnotation(field.getInitializer(), message);
        annotation.registerFix(new IntentionAction() {

            @Override
            @NotNull
            public String getText() {
                return message;
            }

            @Override
            @NotNull
            public String getFamilyName() {
                return UIBundle.message("remove.field.initializer.quick.fix");
            }

            @Override
            public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
                return field.getInitializer() != null;
            }

            @Override
            public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
                final PsiExpression initializer = field.getInitializer();
                LOG.assertTrue(initializer != null);
                initializer.delete();
            }

            @Override
            public boolean startInWriteAction() {
                return true;
            }
        });
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor)

Example 29 with IntentionAction

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

the class PyQuickFixTest method testRenameShadowingBuiltins.

// PY-8788
public void testRenameShadowingBuiltins() {
    final String fileName = "RenameShadowingBuiltins.py";
    myFixture.configureByFile(fileName);
    myFixture.enableInspections(PyShadowingBuiltinsInspection.class);
    myFixture.checkHighlighting(true, false, true);
    final IntentionAction intentionAction = myFixture.getAvailableIntention(PyBundle.message("QFIX.NAME.rename.element"));
    assertNotNull(intentionAction);
    myFixture.launchAction(intentionAction);
    myFixture.checkResultByFile(graftBeforeExt(fileName, "_after"));
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 30 with IntentionAction

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

the class PyQuickFixTest method testRedundantParentheses.

// PY-1470
public void testRedundantParentheses() {
    String[] testFiles = new String[] { "RedundantParentheses.py" };
    myFixture.enableInspections(PyRedundantParenthesesInspection.class);
    myFixture.configureByFiles(testFiles);
    myFixture.checkHighlighting(true, false, true);
    final IntentionAction intentionAction = myFixture.findSingleIntention(PyBundle.message("QFIX.redundant.parentheses"));
    assertNotNull(intentionAction);
    myFixture.launchAction(intentionAction);
    myFixture.checkResultByFile(graftBeforeExt(testFiles[0], "_after"));
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Aggregations

IntentionAction (com.intellij.codeInsight.intention.IntentionAction)241 VirtualFile (com.intellij.openapi.vfs.VirtualFile)39 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)31 NotNull (org.jetbrains.annotations.NotNull)22 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