use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class AbstractJavaFXQuickFixTest method doLaunchQuickfixTest.
protected void doLaunchQuickfixTest(final String tagName) throws Exception {
myFixture.configureByFiles(getTestName(true) + ".fxml");
final IntentionAction singleIntention = myFixture.findSingleIntention(getHint(tagName));
assertNotNull(singleIntention);
myFixture.launchAction(singleIntention);
myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class PropertiesAnnotator method highlightTokens.
private static void highlightTokens(final Property property, final ASTNode node, final AnnotationHolder holder, PropertiesHighlighter highlighter) {
Lexer lexer = highlighter.getHighlightingLexer();
final String s = node.getText();
lexer.start(s);
while (lexer.getTokenType() != null) {
IElementType elementType = lexer.getTokenType();
TextAttributesKey[] keys = highlighter.getTokenHighlights(elementType);
for (TextAttributesKey key : keys) {
Pair<String, HighlightSeverity> pair = PropertiesHighlighter.DISPLAY_NAMES.get(key);
String displayName = pair.getFirst();
HighlightSeverity severity = pair.getSecond();
if (severity != null) {
int start = lexer.getTokenStart() + node.getTextRange().getStartOffset();
int end = lexer.getTokenEnd() + node.getTextRange().getStartOffset();
TextRange textRange = new TextRange(start, end);
final Annotation annotation;
if (severity == HighlightSeverity.WARNING) {
annotation = holder.createWarningAnnotation(textRange, displayName);
} else if (severity == HighlightSeverity.ERROR) {
annotation = holder.createErrorAnnotation(textRange, displayName);
} else {
annotation = holder.createInfoAnnotation(textRange, displayName);
}
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
annotation.setEnforcedTextAttributes(attributes);
if (key == PropertiesHighlighter.PROPERTIES_INVALID_STRING_ESCAPE) {
annotation.registerFix(new IntentionAction() {
@NotNull
public String getText() {
return PropertiesBundle.message("unescape");
}
@NotNull
public String getFamilyName() {
return getText();
}
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!property.isValid() || !property.getManager().isInProject(property))
return false;
String text = property.getPropertiesFile().getContainingFile().getText();
int startOffset = annotation.getStartOffset();
return text.length() > startOffset && text.charAt(startOffset) == '\\';
}
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
int offset = annotation.getStartOffset();
if (property.getPropertiesFile().getContainingFile().getText().charAt(offset) == '\\') {
editor.getDocument().deleteString(offset, offset + 1);
}
}
public boolean startInWriteAction() {
return true;
}
});
}
}
}
lexer.advance();
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class SkeletonTestTask method runTestOn.
@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
// File with module skeleton
File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
// Module may be stored in "moduleName.py" or "moduleName/__init__.py"
if (skeletonFileOrDirectory.isDirectory()) {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
} else {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
}
final File skeletonFile = skeletonFileOrDirectory;
if (skeletonFile.exists()) {
// To make sure we do not reuse it
assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
}
ApplicationManager.getApplication().invokeAndWait(() -> {
// File that uses CLR library
myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
// Library itself
myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
// Another library
myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
myFixture.configureByFile(mySourceFileToRunGenerationOn);
}, ModalityState.NON_MODAL);
// This inspection should suggest us to generate stubs
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
final IntentionAction intention = myFixture.findSingleIntention(intentionName);
Assert.assertNotNull("No intention found to generate skeletons!", intention);
Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
fixTask.run(new AbstractProgressIndicatorBase());
}
});
FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
if (myExpectedSkeletonFile != null) {
final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
// TODO: Move to separate method ?
if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
}
}
myFixture.configureByFile(skeletonFile.getName());
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class MavenDependencyCompletionAndResolutionTest method testChooseFileIntentionForSystemDependency.
public void testChooseFileIntentionForSystemDependency() throws Throwable {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency><caret>" + " <groupId>xxx</groupId>" + " <artifactId>xxx</artifactId>" + " <version>xxx</version>" + " <scope>system</system>" + " </dependency>" + "</dependencies>");
IntentionAction action = getIntentionAtCaret("Choose File");
assertNotNull(action);
String libPath = myIndicesFixture.getRepositoryHelper().getTestDataPath("local1/junit/junit/4.0/junit-4.0.jar");
final VirtualFile libFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(libPath);
((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(() -> new VirtualFile[] { libFile });
XmlCodeStyleSettings xmlSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getCustomSettings(XmlCodeStyleSettings.class);
int prevValue = xmlSettings.XML_TEXT_WRAP;
try {
// prevent file path from wrapping.
xmlSettings.XML_TEXT_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
myFixture.launchAction(action);
} finally {
xmlSettings.XML_TEXT_WRAP = prevValue;
((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(null);
}
MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, myProjectPom);
MavenDomDependency dep = model.getDependencies().getDependencies().get(0);
assertEquals(findPsiFile(libFile), dep.getSystemPath().getValue());
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class MavenDependencyCompletionAndResolutionTest method testNoChooseFileIntentionForNonSystemDependency.
public void testNoChooseFileIntentionForNonSystemDependency() throws Throwable {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency><caret>" + " <groupId>xxx</groupId>" + " <artifactId>xxx</artifactId>" + " <version>xxx</version>" + " <scope>compile</system>" + " </dependency>" + "</dependencies>");
IntentionAction action = getIntentionAtCaret("Choose File");
assertNull(action);
}
Aggregations