use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class CallerChooserBase method updateEditorTexts.
private void updateEditorTexts(final MethodNodeBase<M> node) {
final MethodNodeBase<M> parentNode = getCalleeNode(node);
final MethodNodeBase<M> callerNode = getCallerNode(node);
final String callerText = node != myRoot ? getText(callerNode.getMethod()) : getEmptyCallerText();
final Document callerDocument = myCallerEditor.getDocument();
final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : getEmptyCalleeText();
final Document calleeDocument = myCalleeEditor.getDocument();
ApplicationManager.getApplication().runWriteAction(() -> {
callerDocument.setText(callerText);
calleeDocument.setText(calleeText);
});
final M caller = callerNode.getMethod();
final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null;
if (caller != null && caller.isPhysical() && callee != null) {
HighlightManager highlighter = HighlightManager.getInstance(myProject);
EditorColorsManager colorManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
int start = getStartOffset(caller);
for (PsiElement element : findElementsToHighlight(caller, callee)) {
highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start, element.getTextRange().getEndOffset() - start, attributes, false, null);
}
}
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class ExtractIncludeFileBase method highlightInEditor.
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) {
final HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final int startOffset = pair.getStart().getTextRange().getStartOffset();
final int endOffset = pair.getEnd().getTextRange().getEndOffset();
highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null);
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class ExtractMethodHelper method highlightInEditor.
private static void highlightInEditor(@NotNull final Project project, @NotNull final SimpleMatch match, @NotNull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) {
final List<RangeHighlighter> highlighters = new ArrayList<>();
final HighlightManager highlightManager = HighlightManager.getInstance(project);
final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final int startOffset = match.getStartElement().getTextRange().getStartOffset();
final int endOffset = match.getEndElement().getTextRange().getEndOffset();
highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters);
highlighterMap.put(match, highlighters.get(0));
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class TempWithQueryHandler method invokeOnVariable.
private static void invokeOnVariable(final PsiFile file, final Project project, final PsiLocalVariable local, final Editor editor) {
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
return;
String localName = local.getName();
final PsiExpression initializer = local.getInitializer();
if (initializer == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.has.no.initializer", localName));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.REPLACE_TEMP_WITH_QUERY);
return;
}
final PsiReference[] refs = ReferencesSearch.search(local, GlobalSearchScope.projectScope(project), false).toArray(PsiReference.EMPTY_ARRAY);
if (refs.length == 0) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.never.used", localName));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.REPLACE_TEMP_WITH_QUERY);
return;
}
final HighlightManager highlightManager = HighlightManager.getInstance(project);
ArrayList<PsiReference> array = new ArrayList<>();
EditorColorsManager manager = EditorColorsManager.getInstance();
final TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
for (PsiReference ref : refs) {
PsiElement refElement = ref.getElement();
if (PsiUtil.isAccessedForWriting((PsiExpression) refElement)) {
array.add(ref);
}
if (!array.isEmpty()) {
PsiReference[] refsForWriting = array.toArray(new PsiReference[array.size()]);
highlightManager.addOccurrenceHighlights(editor, refsForWriting, attributes, true, null);
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.REPLACE_TEMP_WITH_QUERY);
WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
return;
}
}
final ExtractMethodProcessor processor = new ExtractMethodProcessor(project, editor, new PsiElement[] { initializer }, local.getType(), REFACTORING_NAME, localName, HelpID.REPLACE_TEMP_WITH_QUERY);
try {
if (!processor.prepare())
return;
} catch (PrepareFailedException e) {
CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), REFACTORING_NAME, HelpID.REPLACE_TEMP_WITH_QUERY);
ExtractMethodHandler.highlightPrepareError(e, file, editor, project);
return;
}
final PsiClass targetClass = processor.getTargetClass();
if (targetClass != null && targetClass.isInterface()) {
String message = RefactoringBundle.message("cannot.replace.temp.with.query.in.interface");
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.REPLACE_TEMP_WITH_QUERY);
return;
}
if (processor.showDialog()) {
CommandProcessor.getInstance().executeCommand(project, () -> {
final Runnable action = () -> {
try {
processor.doRefactoring();
local.normalizeDeclaration();
PsiExpression initializer1 = local.getInitializer();
PsiExpression[] exprs = new PsiExpression[refs.length];
for (int idx = 0; idx < refs.length; idx++) {
PsiElement ref = refs[idx].getElement();
exprs[idx] = (PsiExpression) ref.replace(initializer1);
}
PsiDeclarationStatement declaration = (PsiDeclarationStatement) local.getParent();
declaration.delete();
highlightManager.addOccurrenceHighlights(editor, exprs, attributes, true, null);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
};
PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(() -> {
ApplicationManager.getApplication().runWriteAction(action);
DuplicatesImpl.processDuplicates(processor, project, editor);
});
}, REFACTORING_NAME, null);
}
WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class DuplicatesImpl method highlightMatch.
public static void highlightMatch(final Project project, Editor editor, final Match match, final ArrayList<RangeHighlighter> highlighters) {
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
HighlightManager.getInstance(project).addRangeHighlight(editor, match.getTextRange().getStartOffset(), match.getTextRange().getEndOffset(), attributes, true, highlighters);
}
Aggregations