use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class PyUnwrapperTest method doTest.
private void doTest(final int option) {
String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
String after = "refactoring/unwrap/" + getTestName(true) + "_after.py";
myFixture.configureByFile(before);
UnwrapHandler h = new UnwrapHandler() {
@Override
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
assertTrue("No available options to unwrap", !options.isEmpty());
options.get(option).actionPerformed(null);
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResultByFile(after, true);
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class PyUnwrapperTest method doNegativeTest.
private void doNegativeTest(final String optionName) {
String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
myFixture.configureByFile(before);
UnwrapHandler h = new UnwrapHandler() {
@Override
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
for (AnAction option : options) {
assertFalse("\"" + optionName + "\" is available to unwrap ", option.toString().contains(optionName));
}
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class GroovyTestGenerator method generateTest.
@Nullable
@Override
public PsiElement generateTest(final Project project, final CreateTestDialog d) {
return WriteAction.compute(() -> {
final PsiClass test = (PsiClass) PostprocessReformattingAspect.getInstance(project).postponeFormattingInside((Computable<PsiElement>) () -> {
try {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
GrTypeDefinition targetClass = CreateClassActionBase.createClassByType(d.getTargetDirectory(), d.getClassName(), PsiManager.getInstance(project), null, GroovyTemplates.GROOVY_CLASS, true);
if (targetClass == null)
return null;
addSuperClass(targetClass, project, d.getSuperClassName());
Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.getContainingFile(), targetClass);
addTestMethods(editor, targetClass, d.getSelectedTestFrameworkDescriptor(), d.getSelectedMethods(), d.shouldGeneratedBefore(), d.shouldGeneratedAfter());
return targetClass;
} catch (IncorrectOperationException e1) {
showErrorLater(project, d.getClassName());
return null;
}
});
if (test == null)
return null;
JavaCodeStyleManager.getInstance(test.getProject()).shortenClassReferences(test);
CodeStyleManager.getInstance(project).reformat(test);
return test;
});
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class IntroduceVariableValidatorTest method processFile.
private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
String result = "";
int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
if (startOffset < 0) {
startOffset = fileText.indexOf(ALL_MARKER);
replaceAllOccurences = true;
fileText = IntroduceVariableTest.removeAllMarker(fileText);
} else {
replaceAllOccurences = false;
fileText = TestUtils.removeBeginMarker(fileText);
}
int endOffset = fileText.indexOf(TestUtils.END_MARKER);
fileText = TestUtils.removeEndMarker(fileText);
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
Editor myEditor = myFixture.getEditor();
myEditor.getSelectionModel().setSelection(startOffset, endOffset);
GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
String varName = "preved";
GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
result = validator.isOKTest(varName, replaceAllOccurences);
return result;
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class XPathAction method isEnabled.
protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
final Project project = event.getProject();
if (project == null) {
// no active project
return false;
}
Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
if (editor == null) {
FileEditorManager fem = FileEditorManager.getInstance(project);
editor = fem.getSelectedTextEditor();
}
if (editor == null) {
return false;
}
// do we have an xml file?
final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
// this is also true for DTD documents...
if (!(psiFile instanceof XmlFile) || psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
return false;
}
return !checkAvailable || isEnabledAt((XmlFile) psiFile, editor.getCaretModel().getOffset());
}
Aggregations