use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LineStatusMarkerPopup method installMasterEditorHighlighters.
private void installMasterEditorHighlighters(@Nullable List<DiffFragment> wordDiff, @NotNull Disposable parentDisposable) {
if (wordDiff == null)
return;
final List<RangeHighlighter> highlighters = new ArrayList<>();
int currentStartShift = myTracker.getCurrentTextRange(myRange).getStartOffset();
for (DiffFragment fragment : wordDiff) {
int currentStart = currentStartShift + fragment.getStartOffset2();
int currentEnd = currentStartShift + fragment.getEndOffset2();
TextDiffType type = getDiffType(fragment);
highlighters.addAll(DiffDrawUtil.createInlineHighlighter(myEditor, currentStart, currentEnd, type));
}
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
for (RangeHighlighter highlighter : highlighters) {
highlighter.dispose();
}
}
});
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LineStatusTrackerBase method disposeHighlighter.
@CalledInAwt
private void disposeHighlighter(@NotNull Range range) {
try {
RangeHighlighter highlighter = range.getHighlighter();
if (highlighter != null) {
range.setHighlighter(null);
highlighter.dispose();
}
} catch (Exception e) {
LOG.error(e);
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class CallHierarchyNodeDescriptor method navigate.
public void navigate(boolean requestFocus) {
if (!myNavigateToReference) {
PsiElement element = getPsiElement();
if (element instanceof Navigatable && ((Navigatable) element).canNavigate()) {
((Navigatable) element).navigate(requestFocus);
}
return;
}
final PsiReference firstReference = myReferences.get(0);
final PsiElement element = firstReference.getElement();
if (element == null)
return;
final PsiElement callElement = element.getParent();
if (callElement instanceof Navigatable && ((Navigatable) callElement).canNavigate()) {
((Navigatable) callElement).navigate(requestFocus);
} else {
final PsiFile psiFile = callElement.getContainingFile();
if (psiFile == null || psiFile.getVirtualFile() == null)
return;
FileEditorManager.getInstance(myProject).openFile(psiFile.getVirtualFile(), requestFocus);
}
Editor editor = PsiUtilBase.findEditor(callElement);
if (editor != null) {
HighlightManager highlightManager = HighlightManager.getInstance(myProject);
EditorColorsManager colorManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
for (PsiReference psiReference : myReferences) {
final PsiElement eachElement = psiReference.getElement();
if (eachElement != null) {
final PsiElement eachMethodCall = eachElement.getParent();
if (eachMethodCall != null) {
final TextRange textRange = eachMethodCall.getTextRange();
highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, false, highlighters);
}
}
}
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class BaseExpressionToFieldHandler method convertExpressionToField.
private boolean convertExpressionToField(PsiExpression selectedExpr, @Nullable Editor editor, PsiFile file, final Project project, PsiType tempType) {
if (myParentClass == null) {
if (FileTypeUtils.isInServerPageFile(file)) {
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.message("error.not.supported.for.jsp", getRefactoringName()), getRefactoringName(), getHelpID());
return true;
} else if ("package-info.java".equals(file.getName())) {
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.message("error.not.supported.for.package.info", getRefactoringName()), getRefactoringName(), getHelpID());
return true;
} else {
LOG.error(file);
return true;
}
}
if (!validClass(myParentClass, editor)) {
return true;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
return true;
final OccurrenceManager occurrenceManager = createOccurrenceManager(selectedExpr, myParentClass);
final PsiExpression[] occurrences = occurrenceManager.getOccurrences();
final PsiElement anchorStatementIfAll = occurrenceManager.getAnchorStatementForAll();
List<RangeHighlighter> highlighters = null;
if (editor != null) {
highlighters = RefactoringUtil.highlightAllOccurrences(project, occurrences, editor);
}
PsiElement tempAnchorElement = RefactoringUtil.getParentExpressionAnchorElement(selectedExpr);
if (!Comparing.strEqual(IntroduceConstantHandler.REFACTORING_NAME, getRefactoringName()) && IntroduceVariableBase.checkAnchorBeforeThisOrSuper(project, editor, tempAnchorElement, getRefactoringName(), getHelpID()))
return true;
final Settings settings = showRefactoringDialog(project, editor, myParentClass, selectedExpr, tempType, occurrences, tempAnchorElement, anchorStatementIfAll);
if (settings == null)
return true;
if (settings.getForcedType() != null) {
tempType = settings.getForcedType();
}
final PsiType type = tempType;
if (editor != null) {
HighlightManager highlightManager = HighlightManager.getInstance(project);
for (RangeHighlighter highlighter : highlighters) {
highlightManager.removeSegmentHighlighter(editor, highlighter);
}
}
final Runnable runnable = new ConvertToFieldRunnable(settings.getSelectedExpr(), settings, type, settings.getOccurrences(), occurrenceManager, anchorStatementIfAll, tempAnchorElement, editor, myParentClass);
new WriteCommandAction(project, getRefactoringName()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
runnable.run();
}
}.execute();
return false;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method getHighlightersTextRange.
@NotNull
private static TextRange[] getHighlightersTextRange(@NotNull MarkupModel markup) {
final RangeHighlighter[] highlighters = markup.getAllHighlighters();
final TextRange[] result = new TextRange[highlighters.length];
for (int i = 0; i < highlighters.length; i++) {
result[i] = ProperTextRange.create(highlighters[i]);
}
// markup.getAllHighlighters returns unordered array
return orderByHashCode(result);
}
Aggregations