Search in sources :

Example 11 with IntentionAction

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

the class XmlHighlightVisitor method bindMessageToAstNode.

private void bindMessageToAstNode(final PsiElement childByRole, final HighlightInfoType warning, int length, @NotNull String localizedMessage, IntentionAction... quickFixActions) {
    if (childByRole != null) {
        final TextRange textRange = childByRole.getTextRange();
        if (length == -1)
            length = textRange.getLength();
        final int startOffset = textRange.getStartOffset();
        HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(warning).range(childByRole, startOffset, startOffset + length).descriptionAndTooltip(localizedMessage).create();
        if (highlightInfo == null) {
            highlightInfo = HighlightInfo.newHighlightInfo(warning).range(new TextRange(startOffset, startOffset + length)).textAttributes(NONEMPTY_TEXT_ATTRIBUTES).descriptionAndTooltip(localizedMessage).create();
        }
        for (final IntentionAction quickFixAction : quickFixActions) {
            if (quickFixAction == null)
                continue;
            QuickFixAction.registerQuickFixAction(highlightInfo, textRange, quickFixAction);
        }
        addToResults(highlightInfo);
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange)

Example 12 with IntentionAction

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

the class XmlHighlightVisitor method checkAttribute.

private void checkAttribute(XmlAttribute attribute) {
    XmlTag tag = attribute.getParent();
    if (tag == null)
        return;
    final String name = attribute.getName();
    PsiElement prevLeaf = PsiTreeUtil.prevLeaf(attribute);
    if (!(prevLeaf instanceof PsiWhiteSpace)) {
        TextRange textRange = attribute.getTextRange();
        HighlightInfoType type = tag instanceof HtmlTag ? HighlightInfoType.WARNING : HighlightInfoType.ERROR;
        String description = XmlErrorMessages.message("attribute.should.be.preceded.with.space");
        HighlightInfo info = HighlightInfo.newHighlightInfo(type).range(textRange.getStartOffset(), textRange.getStartOffset()).descriptionAndTooltip(description).create();
        addToResults(info);
    }
    if (attribute.isNamespaceDeclaration() || XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(attribute.getNamespace())) {
        //checkReferences(attribute.getValueElement());
        return;
    }
    XmlElementDescriptor elementDescriptor = tag.getDescriptor();
    if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor || ourDoJaxpTesting) {
        return;
    }
    XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
    if (attributeDescriptor == null) {
        if (!XmlUtil.attributeFromTemplateFramework(name, tag)) {
            final String localizedMessage = XmlErrorMessages.message("attribute.is.not.allowed.here", name);
            final HighlightInfo highlightInfo = reportAttributeProblem(tag, name, attribute, localizedMessage);
            if (highlightInfo != null) {
                PsiFile file = tag.getContainingFile();
                if (file != null) {
                    for (XmlUndefinedElementFixProvider fixProvider : Extensions.getExtensions(XmlUndefinedElementFixProvider.EP_NAME)) {
                        IntentionAction[] fixes = fixProvider.createFixes(attribute);
                        if (fixes != null) {
                            for (IntentionAction action : fixes) {
                                QuickFixAction.registerQuickFixAction(highlightInfo, action);
                            }
                            break;
                        }
                    }
                }
            }
        }
    } else {
        checkDuplicateAttribute(tag, attribute);
        // we skip resolve of attribute references since there is separate check when taking attribute descriptors
        PsiReference[] attrRefs = attribute.getReferences();
        doCheckRefs(attribute, attrRefs, !attribute.getNamespacePrefix().isEmpty() ? 2 : 1);
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HtmlTag(com.intellij.psi.html.HtmlTag) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Example 13 with IntentionAction

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

the class XmlNamespacesTest method testFixAll.

public void testFixAll() throws Exception {
    myFixture.configureByFiles("fixAll.xml", "spring-beans-2.5.xsd", "spring-batch-2.1.xsd");
    IntentionAction action = myFixture.findSingleIntention("Fix all");
    assertNotNull(action);
    myFixture.launchAction(action);
    myFixture.checkResultByFile("fixAll_after.xml");
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 14 with IntentionAction

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

the class FetchExternalResourcesFixTest method doAction.

// just check for action availability
@Override
protected void doAction(@NotNull ActionHint actionHint, String testFullPath, String testName) throws Exception {
    IntentionAction action = findActionAndCheck(actionHint, testFullPath);
    if (action != null && testName.equals("5.xml")) {
        final String uri = FetchExtResourceAction.findUri(myFile, myEditor.getCaretModel().getOffset());
        final String url = FetchExtResourceAction.findUrl(myFile, myEditor.getCaretModel().getOffset(), uri);
        assertEquals("http://www.springframework.org/schema/aop/spring-aop.xsd", url);
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 15 with IntentionAction

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

the class SecondUnsafeCallTest method doTest.

public void doTest() throws Exception {
    final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
    myFixture.configureByText("a.groovy", data.get(0));
    myFixture.enableInspections(new SecondUnsafeCallInspection());
    final IntentionAction action = myFixture.findSingleIntention("Second unsafe call");
    myFixture.launchAction(action);
    myFixture.checkResult(data.get(1));
}
Also used : SecondUnsafeCallInspection(org.jetbrains.plugins.groovy.codeInspection.secondUnsafeCall.SecondUnsafeCallInspection) 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