use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable final DataContext dataContext) {
if (editor == null || file == null)
return;
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, offset, false);
if (expressions.isEmpty()) {
GrIntroduceHandlerBase.updateSelectionForVariable(editor, file, selectionModel, offset);
} else if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
final TextRange textRange = expressions.get(0).getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
} else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
}
}, grExpression -> grExpression.getText());
return;
}
}
invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class GrIntroduceClosureParameterProcessor method processInternalUsages.
private static void processInternalUsages(UsageInfo[] usages, GrIntroduceParameterSettings settings) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject());
// Replacing expression occurrences
for (UsageInfo usage : usages) {
if (usage instanceof ChangedMethodCallInfo) {
PsiElement element = usage.getElement();
processChangedMethodCall(element, settings);
} else if (usage instanceof InternalUsageInfo) {
PsiElement element = usage.getElement();
if (element == null)
continue;
GrExpression newExpr = factory.createExpressionFromText(settings.getName());
if (element instanceof GrExpression) {
((GrExpression) element).replaceWithExpression(newExpr, true);
} else {
element.replace(newExpr);
}
}
}
final StringPartInfo info = settings.getStringPartInfo();
if (info != null) {
final GrExpression expr = info.replaceLiteralWithConcatenation(settings.getName());
final Editor editor = PsiUtilBase.findEditor(expr);
if (editor != null) {
editor.getSelectionModel().removeSelection();
editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset());
}
}
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class PropertyRenameHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, @Nullable DataContext dataContext) {
PsiElement element = elements.length == 1 ? elements[0] : null;
if (element == null)
element = getElement(dataContext);
Editor editor = dataContext == null ? null : CommonDataKeys.EDITOR.getData(dataContext);
invokeInner(project, editor, element);
}
use of com.intellij.openapi.editor.Editor 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.openapi.editor.Editor in project intellij-community by JetBrains.
the class PySmartEnterTest method doTest.
public void doTest() {
myFixture.configureByFile("codeInsight/smartEnter/" + getTestName(true) + ".py");
final List<SmartEnterProcessor> processors = getSmartProcessors(PythonLanguage.getInstance());
new WriteCommandAction(myFixture.getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final Editor editor = myFixture.getEditor();
for (SmartEnterProcessor processor : processors) {
processor.process(myFixture.getProject(), editor, myFixture.getFile());
}
}
}.execute();
myFixture.checkResultByFile("codeInsight/smartEnter/" + getTestName(true) + "_after.py", true);
}
Aggregations