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);
}
}
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);
}
}
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");
}
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);
}
}
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));
}
Aggregations