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 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);
}
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;
}
Aggregations