本文整理汇总了Java中com.intellij.openapi.editor.markup.MarkupModel.addRangeHighlighter方法的典型用法代码示例。如果您正苦于以下问题:Java MarkupModel.addRangeHighlighter方法的具体用法?Java MarkupModel.addRangeHighlighter怎么用?Java MarkupModel.addRangeHighlighter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.markup.MarkupModel
的用法示例。
在下文中一共展示了MarkupModel.addRangeHighlighter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void apply(@Nullable Project project, @NotNull Document document) {
MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);
for (Element piece : myPieces) {
RangeHighlighterEx delegate = piece.getDelegate();
if (!delegate.isValid()) continue;
RangeHighlighter highlighter = model
.addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
highlighter.setEditorFilter(delegate.getEditorFilter());
highlighter.setCustomRenderer(delegate.getCustomRenderer());
highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
}
}
示例2: syntaxError
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
protected void syntaxError(String annotation, Token offendingToken) {
// Annotation annot = new Annotation(20, 30, HighlightSeverity.ERROR, "Test!", "Test Message!");
// HighlightInfo info = HighlightInfo.fromAnnotation(annot);
// List<HighlightInfo> al = new ArrayList<HighlightInfo>();
// al.add(info);
// UpdateHighlightersUtil.setHighlightersToEditor(project, doc, 20, 30, al, null, 0)
final TextAttributes attr = new TextAttributes();
attr.setForegroundColor(JBColor.RED);
attr.setEffectColor(JBColor.RED);
attr.setEffectType(EffectType.WAVE_UNDERSCORE);
MarkupModel markupModel = editor.getMarkupModel();
RangeHighlighter h =
markupModel.addRangeHighlighter(startIndex+offendingToken.getStartIndex(),
startIndex+offendingToken.getStopIndex()+1,
HighlighterLayer.ERROR, // layer
attr,
HighlighterTargetArea.EXACT_RANGE);
h.putUserData(SYNTAX_HIGHLIGHTING_TAG, offendingToken); // store any non-null value to tag it
}
示例3: addDecisionEventHighlighter
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public Token addDecisionEventHighlighter(PreviewState previewState, MarkupModel markupModel,
DecisionEventInfo info, Color errorStripeColor,
EffectType effectType) {
TokenStream tokens = previewState.parsingResult.parser.getInputStream();
Token startToken = tokens.get(info.startIndex);
Token stopToken = tokens.get(info.stopIndex);
TextAttributes textAttributes =
new TextAttributes(JBColor.BLACK, JBColor.WHITE, errorStripeColor,
effectType, Font.PLAIN);
textAttributes.setErrorStripeColor(errorStripeColor);
final RangeHighlighter rangeHighlighter =
markupModel.addRangeHighlighter(
startToken.getStartIndex(), stopToken.getStopIndex()+1,
HighlighterLayer.ADDITIONAL_SYNTAX, textAttributes,
HighlighterTargetArea.EXACT_RANGE);
rangeHighlighter.putUserData(DECISION_EVENT_INFO_KEY, info);
rangeHighlighter.setErrorStripeMarkColor(errorStripeColor);
return startToken;
}
示例4: highlightAndOfferHint
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void highlightAndOfferHint(Editor editor, int offset,
Interval sourceInterval,
JBColor color,
EffectType effectType, String hintText) {
CaretModel caretModel = editor.getCaretModel();
final TextAttributes attr = new TextAttributes();
attr.setForegroundColor(color);
attr.setEffectColor(color);
attr.setEffectType(effectType);
MarkupModel markupModel = editor.getMarkupModel();
markupModel.addRangeHighlighter(
sourceInterval.a,
sourceInterval.b,
InputPanel.TOKEN_INFO_LAYER, // layer
attr,
HighlighterTargetArea.EXACT_RANGE
);
if ( hintText.contains("<") ) {
hintText = hintText.replaceAll("<", "<");
}
// HINT
caretModel.moveToOffset(offset); // info tooltip only shows at cursor :(
HintManager.getInstance().showInformationHint(editor, hintText);
}
示例5: apply
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void apply(@Nullable Project project, @Nonnull Document document) {
MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);
for (Element piece : myPieces) {
RangeHighlighterEx delegate = piece.getDelegate();
if (!delegate.isValid()) continue;
RangeHighlighter highlighter = model
.addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
highlighter.setEditorFilter(delegate.getEditorFilter());
highlighter.setCustomRenderer(delegate.getCustomRenderer());
highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
}
}
示例6: testRangeHighlightersRecreateBug
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void testRangeHighlightersRecreateBug() throws Exception {
Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
for (int i=0; i<2; i++) {
RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE);
RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
markupModel.removeAllHighlighters();
}
}
示例7: testRangeHighlighterDisposeVsRemoveAllConflict
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void testRangeHighlighterDisposeVsRemoveAllConflict() throws Exception {
Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
assertTrue(m.isValid());
markupModel.removeAllHighlighters();
assertFalse(m.isValid());
assertEmpty(markupModel.getAllHighlighters());
m.dispose();
assertFalse(m.isValid());
}
示例8: createHighlighter
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
@NotNull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
final RangeHighlighter highlighter =
mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
highlighter.setCustomRenderer(RENDERER);
return highlighter;
}
示例9: highlightToken
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
protected void highlightToken(Token t, TextAttributesKey[] keys) {
MarkupModel markupModel = getEditor().getMarkupModel();
EditorColorsScheme scheme = editorColorsManager.getGlobalScheme();
TextAttributes attr = merge(scheme, keys);
RangeHighlighter h =
markupModel.addRangeHighlighter(
startIndex+t.getStartIndex(),
startIndex+t.getStopIndex()+1,
HighlighterLayer.SYNTAX, // layer
attr,
HighlighterTargetArea.EXACT_RANGE);
h.putUserData(SYNTAX_HIGHLIGHTING_TAG, t); // store any non-null value to tag it
}
示例10: annotateErrorsInPreviewInputEditor
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void annotateErrorsInPreviewInputEditor(SyntaxError e) {
Editor editor = getInputEditor();
if ( editor==null ) return;
MarkupModel markupModel = editor.getMarkupModel();
int a, b; // Start and stop index
RecognitionException cause = e.getException();
if ( cause instanceof LexerNoViableAltException ) {
a = ((LexerNoViableAltException) cause).getStartIndex();
b = ((LexerNoViableAltException) cause).getStartIndex()+1;
}
else {
Token offendingToken = (Token) e.getOffendingSymbol();
a = offendingToken.getStartIndex();
b = offendingToken.getStopIndex()+1;
}
final TextAttributes attr = new TextAttributes();
attr.setForegroundColor(JBColor.RED);
attr.setEffectColor(JBColor.RED);
attr.setEffectType(EffectType.WAVE_UNDERSCORE);
RangeHighlighter highlighter =
markupModel.addRangeHighlighter(a,
b,
ERROR_LAYER, // layer
attr,
HighlighterTargetArea.EXACT_RANGE);
highlighter.putUserData(SYNTAX_ERROR, e);
}
示例11: createOrReuseLineMarker
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
@Nonnull
private static RangeHighlighter createOrReuseLineMarker(@Nonnull LineMarkerInfo info,
@Nonnull MarkupModel markupModel,
@Nullable HighlightersRecycler toReuse) {
RangeHighlighter highlighter = toReuse == null ? null : toReuse.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX);
if (highlighter == null) {
highlighter = markupModel.addRangeHighlighter(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
}
highlighter.putUserData(LINE_MARKER_INFO, info);
LineMarkerInfo.LineMarkerGutterIconRenderer newRenderer = (LineMarkerInfo.LineMarkerGutterIconRenderer)info.createGutterRenderer();
LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer)highlighter.getGutterIconRenderer() : null;
boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
boolean lineSeparatorColorChanged = !Comparing.equal(highlighter.getLineSeparatorColor(), info.separatorColor);
boolean lineSeparatorPlacementChanged = !Comparing.equal(highlighter.getLineSeparatorPlacement(), info.separatorPlacement);
if (rendererChanged || lineSeparatorColorChanged || lineSeparatorPlacementChanged) {
((MarkupModelEx)markupModel).changeAttributesInBatch((RangeHighlighterEx)highlighter, markerEx -> {
if (rendererChanged) {
markerEx.setGutterIconRenderer(newRenderer);
}
if (lineSeparatorColorChanged) {
markerEx.setLineSeparatorColor(info.separatorColor);
}
if (lineSeparatorPlacementChanged) {
markerEx.setLineSeparatorPlacement(info.separatorPlacement);
}
});
}
info.highlighter = highlighter;
return highlighter;
}
示例12: createHighlighter
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
@NotNull
private static RangeHighlighter createHighlighter(final MarkupModel mm, @NotNull final TextRange range, final Color color)
{
final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.LINES_IN_RANGE);
highlighter.setLineMarkerRenderer((editor, g, r) ->
{
g.setColor(color);
g.fillRect(r.x - 1, r.y, 2, r.height);
});
return highlighter;
}
示例13: updateTitle
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
@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>();
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();
}
}
示例14: selectDecisionInGrammar
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
public void selectDecisionInGrammar(PreviewState previewState, int decision) {
final ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(previewState.project);
if ( controller==null ) return;
final Editor grammarEditor = controller.getEditor(previewState.grammarFile);
if ( grammarEditor==null ) return;
DecisionState decisionState = previewState.g.atn.getDecisionState(decision);
Interval region = previewState.g.getStateToGrammarRegion(decisionState.stateNumber);
if ( region==null ) {
System.err.println("decision "+decision+" has state "+decisionState.stateNumber+" but no region");
return;
}
InputPanel.removeHighlighters(grammarEditor, ProfilerPanel.DECISION_INFO_KEY);
org.antlr.runtime.TokenStream tokens = previewState.g.tokenStream;
if ( region.a>=tokens.size() || region.b>=tokens.size() ) {
// System.out.println("out of range: " + region + " tokens.size()=" + tokens.size());
return;
}
CommonToken startToken = (CommonToken) tokens.get(region.a);
CommonToken stopToken = (CommonToken) tokens.get(region.b);
JBColor effectColor = JBColor.darkGray;
DecisionInfo decisionInfo = previewState.parsingResult.parser.getParseInfo().getDecisionInfo()[decision];
if ( decisionInfo.predicateEvals.size()>0 ) {
effectColor = new JBColor(PREDEVAL_COLOR, AMBIGUITY_COLOR);
}
if ( decisionInfo.contextSensitivities.size()>0 ) {
effectColor = new JBColor(FULLCTX_COLOR, AMBIGUITY_COLOR);
}
if ( decisionInfo.ambiguities.size()>0 ) {
effectColor = new JBColor(AMBIGUITY_COLOR, AMBIGUITY_COLOR);
}
TextAttributes attr =
new TextAttributes(JBColor.BLACK, JBColor.WHITE, effectColor,
EffectType.ROUNDED_BOX, Font.PLAIN);
MarkupModel markupModel = grammarEditor.getMarkupModel();
final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(
startToken.getStartIndex(),
stopToken.getStopIndex()+1,
HighlighterLayer.SELECTION, // layer
attr,
HighlighterTargetArea.EXACT_RANGE
);
rangeHighlighter.putUserData(DECISION_INFO_KEY, decisionInfo);
// System.out.println("dec " + decision + " from " + startToken + " to " + stopToken);
ScrollingModel scrollingModel = grammarEditor.getScrollingModel();
CaretModel caretModel = grammarEditor.getCaretModel();
caretModel.moveToOffset(startToken.getStartIndex());
scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
}
示例15: createHighlighter
import com.intellij.openapi.editor.markup.MarkupModel; //导入方法依赖的package包/类
@Nonnull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
highlighter.setCustomRenderer(RENDERER);
return highlighter;
}