Search in sources :

Example 66 with RangeHighlighter

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();
            }
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) DiffFragment(com.intellij.diff.fragments.DiffFragment) ArrayList(java.util.ArrayList) TextDiffType(com.intellij.diff.util.TextDiffType) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint)

Example 67 with RangeHighlighter

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);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException)

Example 68 with RangeHighlighter

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);
                }
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Editor(com.intellij.openapi.editor.Editor) Navigatable(com.intellij.pom.Navigatable)

Example 69 with RangeHighlighter

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;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) OccurrenceManager(com.intellij.refactoring.util.occurrences.OccurrenceManager) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) Result(com.intellij.openapi.application.Result) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 70 with RangeHighlighter

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);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) LightweightHint(com.intellij.ui.LightweightHint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)97 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 TextRange (com.intellij.openapi.util.TextRange)22 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)15 ArrayList (java.util.ArrayList)15 NotNull (org.jetbrains.annotations.NotNull)15 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 Project (com.intellij.openapi.project.Project)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 Document (com.intellij.openapi.editor.Document)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)7 PsiElement (com.intellij.psi.PsiElement)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4