use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.
the class CodeInsightAction method actionPerformedImpl.
public void actionPerformedImpl(@NotNull final Project project, final Editor editor) {
if (editor == null)
return;
//final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
if (psiFile == null)
return;
final CodeInsightActionHandler handler = getHandler();
PsiElement elementToMakeWritable = handler.getElementToMakeWritable(psiFile);
if (elementToMakeWritable != null && !(EditorModificationUtil.checkModificationAllowed(editor) && FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable))) {
return;
}
CommandProcessor.getInstance().executeCommand(project, () -> {
final Runnable action = () -> {
if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing())
return;
handler.invoke(project, editor, psiFile);
};
if (handler.startInWriteAction()) {
ApplicationManager.getApplication().runWriteAction(action);
} else {
action.run();
}
}, getCommandName(), DocCommandGroupId.noneGroupId(editor.getDocument()));
}
use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.
the class GroovyGoToSuperTest method doTest.
private void doTest() throws Throwable {
final List<String> data = TestUtils.readInput(getTestDataPath() + getTestName(true) + ".test");
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, data.get(0));
final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(GroovyLanguage.INSTANCE);
handler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResult(data.get(1));
}
use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.
the class GenerateDTDAction method getHandler.
@Override
@NotNull
protected CodeInsightActionHandler getHandler() {
return new CodeInsightActionHandler() {
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final XmlDocument document = findSuitableXmlDocument(file);
if (document != null) {
@NonNls final StringBuilder buffer = new StringBuilder();
buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
buffer.append(XmlUtil.generateDocumentDTD(document, true));
buffer.append("]>\n");
XmlFile tempFile;
try {
final XmlProlog prolog = document.getProlog();
final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
if (childOfType != null) {
final String text = childOfType.getText();
buffer.insert(0, text);
final PsiElement nextSibling = childOfType.getNextSibling();
if (nextSibling instanceof PsiWhiteSpace) {
buffer.insert(text.length(), nextSibling.getText());
}
}
tempFile = (XmlFile) PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
prolog.replace(tempFile.getDocument().getProlog());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
};
}
use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-plugins by JetBrains.
the class DartServerGotoSuperHandlerTest method doTest.
private void doTest() throws Throwable {
myFixture.configureByFile(getTestName(false) + ".dart");
initServer();
final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(DartLanguage.INSTANCE);
handler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
Aggregations