use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class MisspelledHeaderInspectionTest method testFix.
public void testFix() {
myFixture.enableInspections(new MisspelledHeaderInspection());
myFixture.configureByText(ManifestFileTypeFactory.MANIFEST, "ManifestVersion: 1.0\n");
List<IntentionAction> intentions = myFixture.filterAvailableIntentions("Change to");
assertEquals(1, intentions.size());
myFixture.launchAction(intentions.get(0));
myFixture.checkResult("Manifest-Version: 1.0\n");
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class MisspelledHeaderInspectionTest method testCustomHeaderFix.
public void testCustomHeaderFix() {
MisspelledHeaderInspection inspection = new MisspelledHeaderInspection();
myFixture.enableInspections(inspection);
myFixture.configureByText(ManifestFileTypeFactory.MANIFEST, "Custom-Header: -\n");
List<IntentionAction> intentions = myFixture.filterAvailableIntentions("Add ");
assertEquals(1, intentions.size());
myFixture.launchAction(intentions.get(0));
assertEquals(Collections.singleton("Custom-Header"), inspection.CUSTOM_HEADERS);
}
use of com.intellij.codeInsight.intention.IntentionAction in project kotlin by JetBrains.
the class AbstractQuickFixMultiFileTest method doAction.
@SuppressWarnings({ "HardCodedStringLiteral" })
public void doAction(String text, boolean actionShouldBeAvailable, String testFilePath) throws Exception {
Pattern pattern = text.startsWith("/") ? Pattern.compile(text.substring(1, text.length() - 1)) : Pattern.compile(StringUtil.escapeToRegexp(text));
List<IntentionAction> availableActions = getAvailableActions();
IntentionAction action = findActionByPattern(pattern, availableActions);
if (action == null) {
if (actionShouldBeAvailable) {
List<String> texts = getActionsTexts(availableActions);
Collection<HighlightInfo> infos = doHighlighting();
fail("Action with text '" + text + "' is not available in test " + testFilePath + "\n" + "Available actions (" + texts.size() + "): \n" + StringUtil.join(texts, "\n") + "\nActions:\n" + StringUtil.join(availableActions, "\n") + "\nInfos:\n" + StringUtil.join(infos, "\n"));
} else {
DirectiveBasedActionUtils.INSTANCE.checkAvailableActionsAreExpected(getFile(), availableActions);
}
} else {
if (!actionShouldBeAvailable) {
fail("Action '" + text + "' is available (but must not) in test " + testFilePath);
}
ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText());
UIUtil.dispatchAllInvocationEvents();
//noinspection ConstantConditions
if (!shouldBeAvailableAfterExecution()) {
IntentionAction afterAction = findActionByPattern(pattern, getAvailableActions());
if (afterAction != null) {
fail("Action '" + text + "' is still available after its invocation in test " + testFilePath);
}
}
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project kotlin by JetBrains.
the class AbstractQuickFixTest method checkForUnexpectedActions.
private void checkForUnexpectedActions() throws ClassNotFoundException {
String text = getEditor().getDocument().getText();
Pair<String, Boolean> pair = parseActionHintImpl(getFile(), text);
if (!pair.second) {
List<IntentionAction> actions = getAvailableActions();
String prefix = "class ";
if (pair.first.startsWith(prefix)) {
String className = pair.first.substring(prefix.length());
final Class<?> aClass = Class.forName(className);
assert IntentionAction.class.isAssignableFrom(aClass) : className + " should be inheritor of IntentionAction";
final Set<String> validActions = new HashSet<String>(InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// ACTION:"));
CollectionsKt.removeAll(actions, new Function1<IntentionAction, Boolean>() {
@Override
public Boolean invoke(IntentionAction action) {
return !aClass.isAssignableFrom(action.getClass()) || validActions.contains(action.getText());
}
});
if (!actions.isEmpty()) {
Assert.fail("Unexpected intention actions present\n " + CollectionsKt.map(actions, new Function1<IntentionAction, String>() {
@Override
public String invoke(IntentionAction action) {
return action.getClass().toString() + " " + action.toString() + "\n";
}
}));
}
for (IntentionAction action : actions) {
if (aClass.isAssignableFrom(action.getClass()) && !validActions.contains(action.getText())) {
Assert.fail("Unexpected intention action " + action.getClass() + " found");
}
}
} else {
// Action shouldn't be found. Check that other actions are expected and thus tested action isn't there under another name.
DirectiveBasedActionUtils.INSTANCE.checkAvailableActionsAreExpected(getFile(), actions);
}
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project kotlin by JetBrains.
the class AbstractIntentionTest method doTest.
protected void doTest(@NotNull String path) throws Exception {
File mainFile = new File(path);
String mainFileName = FileUtil.getNameWithoutExtension(mainFile);
IntentionAction intentionAction = createIntention(mainFile);
List<String> sourceFilePaths = new ArrayList<String>();
File parentDir = mainFile.getParentFile();
extraFileLoop: //noinspection ForLoopThatDoesntUseLoopVariable
for (int i = 1; true; i++) {
for (String extension : EXTENSIONS) {
File extraFile = new File(parentDir, mainFileName + "." + i + extension);
if (extraFile.exists()) {
sourceFilePaths.add(extraFile.getPath());
continue extraFileLoop;
}
}
break;
}
sourceFilePaths.add(path);
Map<String, PsiFile> pathToFiles = ContainerUtil.newMapFromKeys(sourceFilePaths.iterator(), new Convertor<String, PsiFile>() {
@Override
public PsiFile convert(String path) {
try {
configureByFile(path);
} catch (Exception e) {
throw new RuntimeException(e);
}
return myFile;
}
});
String fileText = FileUtil.loadFile(mainFile, true);
assertTrue("\"<caret>\" is missing in file \"" + mainFile + "\"", fileText.contains("<caret>"));
String minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ");
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion))
return;
boolean isWithRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null;
try {
if (isWithRuntime) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(getModule(), PluginTestCaseBase.mockJdk());
}
ConfigLibraryUtil.configureLibrariesByDirective(getModule(), PlatformTestUtil.getCommunityPath(), fileText);
if (getFile() instanceof KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
DirectiveBasedActionUtils.INSTANCE.checkForUnexpectedErrors((KtFile) getFile());
}
doTestFor(path, pathToFiles, intentionAction, fileText);
if (getFile() instanceof KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
DirectiveBasedActionUtils.INSTANCE.checkForUnexpectedErrors((KtFile) getFile());
}
} finally {
ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText);
if (isWithRuntime) {
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(getModule(), getTestProjectJdk());
}
}
}
Aggregations