use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.
the class InplaceIntroduceParameterPopup method updateTitle.
@Override
protected void updateTitle(@Nullable final PsiVariable variable, final String value) {
final PsiElement declarationScope = variable != null ? ((PsiParameter) variable).getDeclarationScope() : null;
if (declarationScope instanceof PsiMethod) {
final PsiMethod psiMethod = (PsiMethod) declarationScope;
final StringBuilder buf = new StringBuilder();
buf.append(psiMethod.getName()).append(" (");
boolean frst = true;
final List<TextRange> ranges2Remove = new ArrayList<>();
TextRange addedRange = null;
for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
if (frst) {
frst = false;
} else {
buf.append(", ");
}
int startOffset = buf.length();
if (myMustBeFinal || myPanel.isGenerateFinal()) {
buf.append("final ");
}
buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
int endOffset = buf.length();
if (variable == parameter) {
addedRange = new TextRange(startOffset, endOffset);
} else if (myPanel.isParamToRemove(parameter)) {
ranges2Remove.add(new TextRange(startOffset, endOffset));
}
}
buf.append(")");
setPreviewText(buf.toString());
final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
markupModel.removeAllHighlighters();
for (TextRange textRange : ranges2Remove) {
markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
}
markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
revalidate();
}
}
use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testRangeHighlightersDoNotGetStuckForever.
public void testRangeHighlightersDoNotGetStuckForever() throws Throwable {
configureByText(StdFileTypes.JAVA, "class S { void ffffff() {fff<caret>fff();}}");
List<HighlightInfo> infos = highlightErrors();
assertEmpty(infos);
MarkupModel markup = DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true);
final TextRange[] highlightersBefore = getHighlightersTextRange(markup);
type("%%%%");
highlightErrors();
backspace();
backspace();
backspace();
backspace();
infos = highlightErrors();
assertEmpty(infos);
final TextRange[] highlightersAfter = getHighlightersTextRange(markup);
assertEquals(highlightersBefore.length, highlightersAfter.length);
for (int i = 0; i < highlightersBefore.length; i++) {
TextRange before = highlightersBefore[i];
TextRange after = highlightersAfter[i];
assertEquals(before.getStartOffset(), after.getStartOffset());
assertEquals(before.getEndOffset(), after.getEndOffset());
}
}
use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-code-outline by sitano.
the class CodeOutlinePanel method highlightCurrentLine.
/**
* Highlights the line specified by <code>lastMousePoint</code>. This method
* does nothing if <code>lastMousePoint</code> is <code>null</code>.
*/
private void highlightCurrentLine() {
if (lastMousePoint == null)
return;
clearHighlightedLine();
MarkupModel mm = editor.getMarkupModel();
int line = getLineFromMousePointY(lastMousePoint.y);
if (line >= 0 && line < editor.getDocument().getLineCount()) {
highlighter = mm.addLineHighlighter(line, 100, CURRENTLINE_ATTRIBUTES);
}
}
Aggregations