public List<StyleRange> getRanges(String expression) { final List<StyleRange> ranges = Lists.newArrayList(); DocumentEvent event = new DocumentEvent(); event.fDocument = new DummyDocument(expression); DocumentTokenSource tokenSource = tokenSourceProvider.get(); tokenSource.updateStructure(event); Iterator<ILexerTokenRegion> iterator = tokenSource.getTokenInfos().iterator(); while (iterator.hasNext()) { ILexerTokenRegion next = iterator.next(); TextAttribute attribute = attributeProvider.getAttribute(tokenTypeMapper.getId(next.getLexerTokenType())); StyleRange range = new StyleRange(next.getOffset(), next.getLength(), attribute.getForeground(), attribute.getBackground()); range.font = attribute.getFont(); range.fontStyle = attribute.getStyle(); ranges.add(range); } return ranges; }
/** * Configure the parser based token source for the coloring. */ public Class<? extends DocumentTokenSource> bindDocumentTokenSource() { return ParserBasedDocumentTokenSource.class; }
/** * Creates a new instance, delegates to {@link XtextDocument#XtextDocument(DocumentTokenSource, ITextEditComposer)}. */ @Inject public N4JSDocument(DocumentTokenSource tokenSource, ITextEditComposer composer) { super(tokenSource, composer); }
@Inject public ResponsiveXtextDocument(final DocumentTokenSource tokenSource, final ITextEditComposer composer) { super(tokenSource, composer); }
@Inject public XtextGMFDocument(final DocumentTokenSource tokenSource, final ITextEditComposer composer) { super(tokenSource, composer); }
@Inject public ParallelReadXtextDocument(DocumentTokenSource tokenSource, ITextEditComposer composer) { super(tokenSource, composer); }
@Inject public CooperateXtextDocument(DocumentTokenSource tokenSource, ITextEditComposer composer) { super(tokenSource, composer); }