use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method doGetAvailableIntentions.
@NotNull
private static List<IntentionAction> doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) {
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
List<IntentionAction> result = new ArrayList<>();
IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject());
for (Map.Entry<IntentionAction, List<IntentionAction>> entry : intentionListStep.getActionsWithSubActions().entrySet()) {
result.add(entry.getKey());
result.addAll(entry.getValue());
}
List<HighlightInfo> infos = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject()).getFileLevelHighlights(file.getProject(), file);
for (HighlightInfo info : infos) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
if (actionInGroup.getAction().isAvailable(file.getProject(), editor, file)) {
result.add(actionInGroup.getAction());
List<IntentionAction> options = actionInGroup.getOptions(file, editor);
if (options != null) {
for (IntentionAction subAction : options) {
if (subAction.isAvailable(file.getProject(), editor, file)) {
result.add(subAction);
}
}
}
}
}
}
return result;
}
use of com.intellij.codeInsight.intention.IntentionAction in project android by JetBrains.
the class AndroidLintTest method doTestWithFix.
private void doTestWithFix(@NotNull AndroidLintInspectionBase inspection, @NotNull String message, @NotNull String copyTo, @NotNull String extension) throws IOException {
final IntentionAction action = doTestHighlightingAndGetQuickfix(inspection, message, copyTo, extension);
assertNotNull(action);
doTestWithAction(extension, action);
}
use of com.intellij.codeInsight.intention.IntentionAction in project android by JetBrains.
the class AndroidLintTest method testSingleLine.
/**
* Quick fix is available on singleLine="true" and does the right thing
*/
public void testSingleLine() throws Exception {
deleteManifest();
myFixture.copyFileToProject(BASE_PATH_GLOBAL + "deprecation/AndroidManifest.xml", "AndroidManifest.xml");
myFixture.enableInspections(new AndroidLintDeprecatedInspection());
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(BASE_PATH + "singleLine.xml", "res/layout/singleLine.xml"));
final IntentionAction action = AndroidTestUtils.getIntentionAction(myFixture, "Replace singleLine=\"true\" with maxLines=\"1\"");
assertNotNull(action);
doTestWithAction("xml", action);
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-plugins by JetBrains.
the class DartServerQuickFixTest method doCrLfAwareTest.
private void doCrLfAwareTest(@NotNull final String content, @NotNull final String intentionStartText, @NotNull final String after) {
final VirtualFile file = myFixture.configureByText("foo.dart", content).getVirtualFile();
// configureByText() has normalized line breaks, save once again
ApplicationManager.getApplication().runWriteAction(() -> {
try {
final int i = content.indexOf("<caret>");
VfsUtil.saveText(file, content.substring(0, i) + content.substring(i + "<caret>".length()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
final IntentionAction quickFix = myFixture.findSingleIntention(intentionStartText);
ApplicationManager.getApplication().runWriteAction(() -> quickFix.invoke(getProject(), getEditor(), getFile()));
myFixture.checkResult(after);
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-plugins by JetBrains.
the class DartServerQuickFixTest method testCreatePartFile.
public void testCreatePartFile() throws Throwable {
myFixture.configureByFile(getTestName(false) + ".dart");
final IntentionAction quickFix = myFixture.findSingleIntention("Create file 'CreatePartFile_part.dart'");
assertEquals(true, quickFix.isAvailable(getProject(), getEditor(), getFile()));
ApplicationManager.getApplication().runWriteAction(() -> quickFix.invoke(getProject(), getEditor(), getFile()));
final VirtualFile newFile = myFixture.findFileInTempDir("CreatePartFile_part.dart");
assertNotNull(newFile);
// TODO content of created file is not added because DartQuickFix.navigate() behaves differently in test environment
//myFixture.openFileInEditor(newFile);
//myFixture.checkResultByFile("CreatePartFile_part.after.dart");
}
Aggregations