Java Code Examples for org.eclipse.xtext.ui.editor.model.DocumentTokenSource#setLexer()

The following examples show how to use org.eclipse.xtext.ui.editor.model.DocumentTokenSource#setLexer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtextDocumentModifyTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private IXtextDocument createDocument(String model) throws Exception {
	resource = getResource(new StringInputStream(model));
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	
	final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {
		@Override
		public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
			try {
				return work.exec((XtextResource) resource);
			}
			catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	};
	document.set(model);
	return document;
}
 
Example 2
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
Example 3
Source File: AbstractXtextDocumentTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, outdatedStateManager, operationCanceledManager);
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
Example 4
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
Example 5
Source File: BacktrackingLexerPresentationDamagerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new BacktrackingLexerDocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}
 
Example 6
Source File: DamagerRepairerPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.set(before);
	return document;
}
 
Example 7
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}
 
Example 8
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}
 
Example 9
Source File: DocumentLockerTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private DocumentTokenSource createTokenSource() {
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(() -> new InternalXtextLexer());
	return tokenSource;
}