use of com.intellij.openapi.editor.markup.RangeHighlighter 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.markup.RangeHighlighter in project intellij-community by JetBrains.
the class InplaceChangeSignature method detach.
public void detach() {
myEditor.getDocument().removeDocumentListener(this);
HighlightManager highlightManager = HighlightManager.getInstance(myProject);
for (RangeHighlighter highlighter : myHighlighters) {
highlightManager.removeSegmentHighlighter(myEditor, highlighter);
}
myHighlighters.clear();
myBalloon.hide();
myDetector = null;
FinishMarkAction.finish(myProject, myEditor, myMarkAction);
myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, null);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ExtractMethodHelper method replaceDuplicates.
/**
* Notifies user about found duplicates and then highlights each of them in the editor and asks user how to proceed.
*
* @param callElement generated expression or statement that contains invocation of the new method
* @param editor instance of editor where refactoring is performed
* @param replacer strategy of substituting each duplicate occurence with the replacement fragment
* @param duplicates discovered duplicates of extracted code fragment
* @see #collectDuplicates(SimpleDuplicatesFinder, List, PsiElement)
*/
public static void replaceDuplicates(@NotNull PsiElement callElement, @NotNull Editor editor, @NotNull Consumer<Pair<SimpleMatch, PsiElement>> replacer, @NotNull List<SimpleMatch> duplicates) {
if (!duplicates.isEmpty()) {
final String message = RefactoringBundle.message("0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method", ApplicationNamesInfo.getInstance().getProductName(), duplicates.size());
final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode();
final Project project = callElement.getProject();
final int exitCode = !isUnittest ? Messages.showYesNoDialog(project, message, RefactoringBundle.message("refactoring.extract.method.dialog.title"), Messages.getInformationIcon()) : Messages.YES;
if (exitCode == Messages.YES) {
boolean replaceAll = false;
final Map<SimpleMatch, RangeHighlighter> highlighterMap = new HashMap<>();
for (SimpleMatch match : duplicates) {
if (!match.getStartElement().isValid() || !match.getEndElement().isValid())
continue;
final Pair<SimpleMatch, PsiElement> replacement = Pair.create(match, callElement);
if (!replaceAll) {
highlightInEditor(project, match, editor, highlighterMap);
int promptResult = FindManager.PromptResult.ALL;
//noinspection ConstantConditions
if (!isUnittest) {
ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project);
promptDialog.show();
promptResult = promptDialog.getExitCode();
}
if (promptResult == FindManager.PromptResult.SKIP) {
final HighlightManager highlightManager = HighlightManager.getInstance(project);
final RangeHighlighter highlighter = highlighterMap.get(match);
if (highlighter != null)
highlightManager.removeSegmentHighlighter(editor, highlighter);
continue;
}
if (promptResult == FindManager.PromptResult.CANCEL)
break;
if (promptResult == FindManager.PromptResult.OK) {
replaceDuplicate(project, replacer, replacement);
} else if (promptResult == FindManager.PromptResult.ALL) {
replaceDuplicate(project, replacer, replacement);
replaceAll = true;
}
} else {
replaceDuplicate(project, replacer, replacement);
}
}
}
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ScopeHighlighter method addHighlighter.
private void addHighlighter(TextRange r, int level, TextAttributes attr) {
MarkupModel markupModel = myEditor.getMarkupModel();
RangeHighlighter highlighter = markupModel.addRangeHighlighter(r.getStartOffset(), r.getEndOffset(), level, attr, HighlighterTargetArea.EXACT_RANGE);
myActiveHighliters.add(highlighter);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class TemplateState method initTabStopHighlighters.
private void initTabStopHighlighters() {
final Set<String> vars = new HashSet<>();
for (int i = 0; i < myTemplate.getVariableCount(); i++) {
String variableName = myTemplate.getVariableNameAt(i);
if (!vars.add(variableName))
continue;
int segmentNumber = myTemplate.getVariableSegmentNumber(variableName);
if (segmentNumber < 0)
continue;
RangeHighlighter segmentHighlighter = getSegmentHighlighter(segmentNumber, false, false);
myTabStopHighlighters.add(segmentHighlighter);
}
int endSegmentNumber = myTemplate.getEndSegmentNumber();
if (endSegmentNumber >= 0) {
RangeHighlighter segmentHighlighter = getSegmentHighlighter(endSegmentNumber, false, true);
myTabStopHighlighters.add(segmentHighlighter);
}
}
Aggregations