org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper. 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: AutoEditStrategyProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureMultilineComments(IEditStrategyAcceptor acceptor) {
	// To avoid JSDocEditStrategy handling /***+ multiline3andMoreAsterisks instance is added
	IAutoEditStrategy multiline3andMoreAsterisks = multiLineTerminals.newInstance("/***", " * ", " */");
	JSDocEditStrategy jsdoc = new JSDocEditStrategy();
	injector.injectMembers(jsdoc);
	IAutoEditStrategy multiline = multiLineTerminals.newInstance("/*", " * ", " */");
	IAutoEditStrategy singleline = singleLineTerminals.newInstance("/*", " */", new SupressingMLCommentPredicate());

	acceptor.accept(singleline, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(singleLineTerminals.newInstance("/*", " */"), REG_EX_PARTITION);

	acceptor.accept(multiline3andMoreAsterisks, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiline3andMoreAsterisks, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(multiline3andMoreAsterisks, REG_EX_PARTITION);

	acceptor.accept(jsdoc, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(jsdoc, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(jsdoc, JS_DOC_PARTITION);
	acceptor.accept(jsdoc, REG_EX_PARTITION);

	acceptor.accept(multiline, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiline, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(multiline, JS_DOC_PARTITION);
	acceptor.accept(multiline, REG_EX_PARTITION);
}
 
Example #2
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testSimple() throws Exception {
	XtextDocument document = getDocument("/* foo */ bar 345 grammar : so 'baz & so'");
	ITypedRegion partition = document.getPartition(0);
	assertEquals(0, partition.getOffset());
	assertEquals(9, partition.getLength());
	assertEquals(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION, partition.getType());

	partition = document.getPartition(9);
	assertEquals(9, partition.getOffset());
	assertEquals(22, partition.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());

	partition = document.getPartition(35);
	assertEquals(31, partition.getOffset());
	assertEquals(10, partition.getLength());
	assertEquals(TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION, partition.getType());
}
 
Example #3
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 #4
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 #5
Source File: SARLContentAssistFactory.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected void setContentAssistProcessor(ContentAssistant assistant, SourceViewerConfiguration configuration,
		ISourceViewer sourceViewer) {
	super.setContentAssistProcessor(assistant, configuration, sourceViewer);
	assistant.setContentAssistProcessor(this.javaDocContentAssistProcessor, TokenTypeToPartitionMapper.JAVA_DOC_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
}
 
Example #6
Source File: ContentAssistantFactory.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setContentAssistProcessor(ContentAssistant assistant, SourceViewerConfiguration configuration,
		ISourceViewer sourceViewer) {
	super.setContentAssistProcessor(assistant, configuration, sourceViewer);
	assistant.setContentAssistProcessor(jsDocContentAssistProcessor, TokenTypeToPartitionMapper.JS_DOC_PARTITION);
	assistant.setContentAssistProcessor(null, TokenTypeToPartitionMapper.REG_EX_PARTITION);
	assistant.setContentAssistProcessor(null, TokenTypeToPartitionMapper.TEMPLATE_LITERAL_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
}
 
Example #7
Source File: XtendContentAssistFactory.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void setContentAssistProcessor(ContentAssistant assistant, SourceViewerConfiguration configuration,
		ISourceViewer sourceViewer) {
	super.setContentAssistProcessor(assistant, configuration, sourceViewer);
	assistant.setContentAssistProcessor(javaDocContentAssistProcessor,TokenTypeToPartitionMapper.JAVA_DOC_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
}
 
Example #8
Source File: DefaultAutoEditStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void configureStringLiteral(IEditStrategyAcceptor acceptor) {
	acceptor.accept(partitionInsert.newInstance("\"","\""),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(partitionInsert.newInstance("'","'"),IDocument.DEFAULT_CONTENT_TYPE);
	// The following two are registered for the default content type, because on deletion 
	// the command.offset is cursor-1, which is outside the partition of terminals.length = 1.
	// How crude is that?
	// Note that in case you have two string literals following each other directly, the deletion strategy wouldn't apply.
	// One could add the same strategy for the STRING partition in addition to solve this
	acceptor.accept(partitionDeletion.newInstance("\"","\""),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(partitionDeletion.newInstance("'","'"),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(partitionEndSkippingEditStrategy.get(),TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION);
}
 
Example #9
Source File: DefaultAutoEditStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void configureMultilineComments(IEditStrategyAcceptor acceptor) {
	acceptor.accept(singleLineTerminals.newInstance("/*", " */"),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiLineTerminals.newInstance("/***"," * ", " ***/"),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiLineTerminals.newInstance("/***"," * ", " ***/"),TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(multiLineTerminals.newInstance("/*"," * ", " */"),IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiLineTerminals.newInstance("/*"," * ", " */"),TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
}
 
Example #10
Source File: DoubleClickStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ITextDoubleClickStrategy getStrategy(ISourceViewer sourceViewer, String contentType, String documentPartitioning) {
	if (TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION.equals(contentType))
		return new FixedCharCountPartitionDoubleClickSelector(documentPartitioning, 0, 0);
	if (TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION.equals(contentType))
		return new FixedCharCountPartitionDoubleClickSelector(documentPartitioning, 0, 0);
	if (TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION.equals(contentType))
		return new FixedCharCountPartitionDoubleClickSelector(documentPartitioning, 1, 1);
	return defaultDoubleClickStrategy;
}
 
Example #11
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug401433() throws Exception {
	XtextDocument document = getDocument("     /* */ ");
	document.replace(10, 1, "");
	ITypedRegion partition = document.getPartition(9);
	assertEquals(5, partition.getOffset());
	assertEquals(5, partition.getLength());
	assertEquals(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION, partition.getType());
	document.replace(9, 1, "");
	partition = document.getPartition(8);
	assertEquals(5, partition.getOffset());
	assertEquals(4, partition.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
	document.replace(8, 1, "");
	partition = document.getPartition(7);
	assertEquals(5, partition.getOffset());
	assertEquals(3, partition.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
	document.replace(7, 1, "");
	partition = document.getPartition(6);
	assertEquals(5, partition.getOffset());
	assertEquals(2, partition.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
	document.replace(6, 1, "");
	partition = document.getPartition(5);
	assertEquals(5, partition.getOffset());
	assertEquals(1, partition.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
}
 
Example #12
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testModification() throws Exception {
	XtextDocument document = getDocument("bar 345 grammar : so 'baz & so'");
	document.replace(8, 7, "/*grammar*/");
	ITypedRegion partition = document.getPartition(9);
	assertEquals(8, partition.getOffset());
	assertEquals(11, partition.getLength());
	assertEquals(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION, partition.getType());
}
 
Example #13
Source File: SupressingMLCommentPredicate.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean isInsertClosingBracket(IDocument doc, int offset) throws BadLocationException {
	if (offset >= 2) {
		ITypedRegion prevPartition = doc.getPartition(offset - 1);
		String prevPartitionType = prevPartition.getType();
		if (TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION.equals(prevPartitionType)) {
			return false;
		}
		if (TokenTypeToPartitionMapper.REG_EX_PARTITION.equals(prevPartitionType)) {
			return prevPartition.getLength() == 1;
		}
	}
	return SingleLineTerminalsStrategy.DEFAULT.isInsertClosingBracket(doc, offset);
}
 
Example #14
Source File: DefaultFoldingRegionProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Deprecated
public DefaultFoldingRegionProvider(ILocationInFileProvider locationInFileProvider) {
	this.locationInFileProvider = locationInFileProvider;
	this.tokenTypeToPartitionTypeMapperExtension = new TerminalsTokenTypeToPartitionMapper();
}
 
Example #15
Source File: DefaultAutoEditStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void configureIndentationEditStrategy(IEditStrategyAcceptor acceptor) {
	acceptor.accept(defaultIndentLineAutoEditStrategy.get(), IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(defaultIndentLineAutoEditStrategy.get(), TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(defaultIndentLineAutoEditStrategy.get(), TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
}
 
Example #16
Source File: XtendUiModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends TerminalsTokenTypeToPartitionMapper> bindTerminalsTokenTypeToPartitionMapper() {
	return TokenTypeToPartitionMapper.class;
}
 
Example #17
Source File: N4JSUiModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Configure the token to partition type mapper.
 */
public Class<? extends TerminalsTokenTypeToPartitionMapper> bindTerminalTokenTypeToPartitionMapper() {
	return TokenTypeToPartitionMapper.class;
}