Search in sources :

Example 1 with ITokenTypeToPartitionTypeMapper

use of org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper in project xtext-eclipse by eclipse.

the class PartitionTokenScannerTest method getPartitionTokenScanner.

public PartitionTokenScanner getPartitionTokenScanner(ILexerTokenRegion... tokenDescs) throws Exception {
    final List<ILexerTokenRegion> tokens = Arrays.asList(tokenDescs);
    int offset = 0;
    for (ILexerTokenRegion token : tokens) {
        ((LexerTokenRegion) token).setOffset(offset);
        offset += token.getLength();
    }
    PartitionTokenScanner tokenScanner = new PartitionTokenScanner() {

        @Override
        protected Iterable<ILexerTokenRegion> getTokens(IDocument document) {
            return tokens;
        }

        @Override
        protected boolean shouldMergePartitions(String contentType) {
            return "3".equals(contentType);
        }
    };
    tokenScanner.setMapper(new ITokenTypeToPartitionTypeMapper() {

        @Override
        public String[] getSupportedPartitionTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getPartitionType(int antlrTokenType) {
            return "" + antlrTokenType;
        }
    });
    return tokenScanner;
}
Also used : ILexerTokenRegion(org.eclipse.xtext.ui.editor.model.ILexerTokenRegion) PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) ITokenTypeToPartitionTypeMapper(org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper) ILexerTokenRegion(org.eclipse.xtext.ui.editor.model.ILexerTokenRegion) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1 ILexerTokenRegion (org.eclipse.xtext.ui.editor.model.ILexerTokenRegion)1 ITokenTypeToPartitionTypeMapper (org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper)1 PartitionTokenScanner (org.eclipse.xtext.ui.editor.model.PartitionTokenScanner)1