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