Search in sources :

Example 96 with IntentionAction

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

the class AbstractIntentionTest method createIntention.

private IntentionAction createIntention(File testDataFile) throws Exception {
    List<File> candidateFiles = Lists.newArrayList();
    File current = testDataFile.getParentFile();
    while (current != null) {
        File candidate = new File(current, intentionFileName());
        if (candidate.exists()) {
            candidateFiles.add(candidate);
        }
        current = current.getParentFile();
    }
    if (candidateFiles.isEmpty()) {
        throw new AssertionError(".intention file is not found for " + testDataFile + "\nAdd it to base directory of test data. It should contain fully-qualified name of intention class.");
    }
    if (candidateFiles.size() > 1) {
        throw new AssertionError("Several .intention files are available for " + testDataFile + "\nPlease remove some of them\n" + candidateFiles);
    }
    String className = FileUtil.loadFile(candidateFiles.get(0)).trim();
    return (IntentionAction) Class.forName(className).newInstance();
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiFile(com.intellij.psi.PsiFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 97 with IntentionAction

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

the class PackageAccessibilityInspectionTest method doTestFix.

private void doTestFix(String classText, String manifestText, String expected) {
    myFixture.enableInspections(new PackageAccessibilityInspection());
    PsiFile manifest = myFixture.addFileToProject("META-INF/MANIFEST.MF", manifestText);
    myFixture.configureByText("C.java", classText);
    IntentionAction intention = myFixture.findSingleIntention(OsmorcBundle.message("PackageAccessibilityInspection.fix"));
    myFixture.launchAction(intention);
    assertEquals(expected, manifest.getText());
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiFile(com.intellij.psi.PsiFile)

Example 98 with IntentionAction

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

the class StrutsFileSetCheckingAnnotatorTest method testStrutsXmlNoFacetSetup.

public void testStrutsXmlNoFacetSetup() throws Throwable {
    final IntentionAction intention = myFixture.getAvailableIntention("Edit Struts 2 facet settings", "struts-simple.xml");
    assertIntentionFound(intention);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 99 with IntentionAction

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

the class StrutsIntentionTest method testCreateActionMethodIntention.

/**
   * Check {@link com.intellij.struts2.dom.struts.action.ActionMethodConverter}.
   *
   * @throws Throwable Any exceptions.
   */
public void testCreateActionMethodIntention() throws Throwable {
    createStrutsFileSet("struts-action-method.xml");
    final List<IntentionAction> list = myFixture.getAllQuickFixes("struts-action-method.xml");
    final IntentionAction action = CodeInsightTestUtil.findIntentionByText(list, "Create action-method 'unknownMethod'");
    assertNotNull(action);
// myFixture.launchAction(action);
// myFixture.checkResultByFile("/src/MyClass.java", "/src/MyClassAfterCreateActionMethod.java", false);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 100 with IntentionAction

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

the class TsLintExternalAnnotator method apply.

@Override
public void apply(@NotNull PsiFile file, @Nullable JSLinterAnnotationResult<TsLintState> annotationResult, @NotNull AnnotationHolder holder) {
    if (annotationResult == null)
        return;
    TsLintConfigurable configurable = new TsLintConfigurable(file.getProject(), true);
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    IntentionAction fixAllFileIntention = new TsLintFileFixAction().asIntentionAction();
    JSLinterStandardFixes fixes = new JSLinterStandardFixes() {

        @Override
        public List<IntentionAction> createListForError(@Nullable VirtualFile configFile, @NotNull UntypedJSLinterConfigurable configurable, @NotNull JSLinterErrorBase errorBase) {
            List<IntentionAction> defaultIntentions = super.createListForError(configFile, configurable, errorBase);
            if (errorBase instanceof TsLinterError && ((TsLinterError) errorBase).hasFix()) {
                ArrayList<IntentionAction> result = ContainerUtil.newArrayList();
                if (document != null && myOnTheFly) {
                    result.add(new TsLintErrorFixAction((TsLinterError) errorBase, document));
                }
                result.add(fixAllFileIntention);
                result.addAll(defaultIntentions);
                return result;
            }
            return defaultIntentions;
        }
    };
    new JSLinterAnnotationsBuilder<>(file, annotationResult, holder, TsLintInspection.getHighlightDisplayKey(), configurable, TsLintBundle.message("tslint.framework.title") + ": ", getInspectionClass(), fixes).setHighlightingGranularity(HighlightingGranularity.element).apply(document);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TsLintErrorFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) TsLintConfigurable(com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TsLintFileFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction) Nullable(org.jetbrains.annotations.Nullable)

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