]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/SCLDocumentSetup.java
LabelDecorator.decorateLabel can return null
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor / SCLDocumentSetup.java
1 package org.simantics.scl.ui.editor;
2
3 import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
4 import org.eclipse.jface.text.IDocument;
5 import org.eclipse.jface.text.IDocumentExtension3;
6 import org.eclipse.jface.text.IDocumentPartitioner;
7 import org.eclipse.jface.text.rules.EndOfLineRule;
8 import org.eclipse.jface.text.rules.FastPartitioner;
9 import org.eclipse.jface.text.rules.IPredicateRule;
10 import org.eclipse.jface.text.rules.MultiLineRule;
11 import org.eclipse.jface.text.rules.PatternRule;
12 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
13 import org.eclipse.jface.text.rules.Token;
14
15 public class SCLDocumentSetup implements IDocumentSetupParticipant {
16     
17     public static final String COMMENT = "COMMENT";
18     public static final String STRING = "STRING";
19     
20     public static final String[] PARTITION_TYPES = new String[] {
21         COMMENT, STRING
22     };
23     
24     public static final String SCL_PARTIONING = "SCL_PARTIONING";
25     
26     
27     @Override
28     public void setup(final IDocument document) {
29         if(document instanceof IDocumentExtension3) {
30             RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner();
31             scanner.setPredicateRules(new IPredicateRule[] {
32                     new MultiLineRule("/*", "*/", new Token(COMMENT)),
33                     new EndOfLineRule("//", new Token(COMMENT)),
34                     new MultiLineRule("\"\"\"", "\"\"\"", new Token(STRING), '\\'),
35                     new PatternRule("\"", "\"", new Token(STRING), '\\', true),
36             });
37             IDocumentPartitioner partitioner = new FastPartitioner(scanner, PARTITION_TYPES);
38             ((IDocumentExtension3)document).setDocumentPartitioner(SCL_PARTIONING, partitioner);
39             partitioner.connect(document);
40         }
41     }
42
43 }