Search in sources :

Example 76 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 77 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 78 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 79 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)

Example 80 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class ExternalAnnotationsManagerImpl method chooseAnnotationsPlace.

@Override
@NotNull
public AnnotationPlace chooseAnnotationsPlace(@NotNull final PsiElement element) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    //element just created
    if (!element.isPhysical())
        return AnnotationPlace.IN_CODE;
    if (!element.getManager().isInProject(element))
        return AnnotationPlace.EXTERNAL;
    final Project project = myPsiManager.getProject();
    //otherwise external annotations should be read-only
    if (CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS) {
        final PsiFile containingFile = element.getContainingFile();
        final VirtualFile virtualFile = containingFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
        if (!entries.isEmpty()) {
            for (OrderEntry entry : entries) {
                if (!(entry instanceof ModuleOrderEntry)) {
                    if (AnnotationOrderRootType.getUrls(entry).length > 0) {
                        return AnnotationPlace.EXTERNAL;
                    }
                    break;
                }
            }
        }
        final MyExternalPromptDialog dialog = ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment() ? null : new MyExternalPromptDialog(project);
        if (dialog != null && dialog.isToBeShown()) {
            final PsiElement highlightElement = element instanceof PsiNameIdentifierOwner ? ((PsiNameIdentifierOwner) element).getNameIdentifier() : element.getNavigationElement();
            LOG.assertTrue(highlightElement != null);
            final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
            final List<RangeHighlighter> highlighters = new ArrayList<>();
            final boolean highlight = editor != null && editor.getDocument() == PsiDocumentManager.getInstance(project).getDocument(containingFile);
            try {
                if (highlight) {
                    //do not highlight for batch inspections
                    final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
                    final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
                    final TextRange textRange = highlightElement.getTextRange();
                    HighlightManager.getInstance(project).addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters);
                    final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
                    editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.CENTER);
                }
                dialog.show();
                if (dialog.getExitCode() == 2) {
                    return AnnotationPlace.EXTERNAL;
                } else if (dialog.getExitCode() == 1) {
                    return AnnotationPlace.NOWHERE;
                }
            } finally {
                if (highlight) {
                    HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0));
                }
            }
        } else if (dialog != null) {
            dialog.close(DialogWrapper.OK_EXIT_CODE);
        }
    }
    return AnnotationPlace.IN_CODE;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Project(com.intellij.openapi.project.Project) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) 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