use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class PydevConsoleReference method getVariants.
@NotNull
public Object[] getVariants() {
Map<String, LookupElement> variants = Maps.newHashMap();
try {
final List<PydevCompletionVariant> completions = myCommunication.getCompletions(getText(), myPrefix);
for (PydevCompletionVariant completion : completions) {
final PsiManager manager = myElement.getManager();
final String name = completion.getName();
final int type = completion.getType();
LookupElementBuilder builder = LookupElementBuilder.create(new PydevConsoleElement(manager, name, completion.getDescription())).withIcon(PyCodeCompletionImages.getImageForType(type));
String args = completion.getArgs();
if (args.equals("(%)")) {
builder.withPresentableText("%" + completion.getName());
builder = builder.withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
int offset = context.getStartOffset();
if (offset == 0 || !"%".equals(document.getText(TextRange.from(offset - 1, 1)))) {
document.insertString(offset, "%");
}
}
});
args = "";
} else if (!StringUtil.isEmptyOrSpaces(args)) {
builder = builder.withTailText(args);
}
// Set function insert handler
if (type == IToken.TYPE_FUNCTION || args.endsWith(")")) {
builder = builder.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
}
variants.put(name, builder);
}
} catch (Exception e) {
//LOG.error(e);
}
return variants.values().toArray();
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class PyUnwrapperTest method doNegativeTest.
private void doNegativeTest() {
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) {
assertEmpty(options);
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
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 Main by SpartanRefactoring.
the class SpartanizerAction method getPsiElementFromContext.
/**
* @param e the action event
* @return the psiElement extracted from the event's context
**/
@Nullable
private PsiElement getPsiElementFromContext(AnActionEvent e) {
PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
Editor editor = e.getData(PlatformDataKeys.EDITOR);
return psiFile == null || editor == null ? null : psiFile.findElementAt(editor.getCaretModel().getOffset());
}
Aggregations