Package: VdmPartitionScanner

VdmPartitionScanner

nameinstructionbranchcomplexitylinemethod
VdmPartitionScanner()
M: 75 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.ui.editor.partitioning;
23:
24: import java.util.ArrayList;
25: import java.util.List;
26:
27: import org.eclipse.jface.text.rules.EndOfLineRule;
28: import org.eclipse.jface.text.rules.ICharacterScanner;
29: import org.eclipse.jface.text.rules.IPredicateRule;
30: import org.eclipse.jface.text.rules.IToken;
31: import org.eclipse.jface.text.rules.IWordDetector;
32: import org.eclipse.jface.text.rules.MultiLineRule;
33: import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
34: import org.eclipse.jface.text.rules.SingleLineRule;
35: import org.eclipse.jface.text.rules.Token;
36: import org.eclipse.jface.text.rules.WordRule;
37:
38: public class VdmPartitionScanner extends RuleBasedPartitionScanner implements IVdmPartitions{
39:
40:         /**
41:          * Detector for empty comments.
42:          */
43:         static class EmptyCommentDetector implements IWordDetector {
44:
45:                 /*
46:                  * @see IWordDetector#isWordStart
47:                  */
48:                 public boolean isWordStart(char c) {
49:                         return (c == '/');
50:                 }
51:
52:                 /*
53:                  * @see IWordDetector#isWordPart
54:                  */
55:                 public boolean isWordPart(char c) {
56:                         return (c == '*' || c == '/');
57:                 }
58:         }
59:
60:
61:         /**
62:          * Word rule for empty comments.
63:          */
64:         static class EmptyCommentRule extends WordRule implements IPredicateRule {
65:
66:                 private IToken fSuccessToken;
67:                 /**
68:                  * Constructor for EmptyCommentRule.
69:                  * @param successToken the token returned for success
70:                  */
71:                 public EmptyCommentRule(IToken successToken) {
72:                         super(new EmptyCommentDetector());
73:                         fSuccessToken= successToken;
74:                         addWord("/**/", fSuccessToken); //$NON-NLS-1$
75:                 }
76:
77:                 /*
78:                  * @see IPredicateRule#evaluate(ICharacterScanner, boolean)
79:                  */
80:                 public IToken evaluate(ICharacterScanner scanner, boolean resume) {
81:                         return evaluate(scanner);
82:                 }
83:
84:                 /*
85:                  * @see IPredicateRule#getSuccessToken()
86:                  */
87:                 public IToken getSuccessToken() {
88:                         return fSuccessToken;
89:                 }
90:         }
91:
92:         
93:         public final static String[] PARTITION_TYPES = new String[] {
94:                         MULTILINE_COMMENT, SINGLELINE_COMMENT, STRING };
95:
96:         /**
97:          * Creates the partitioner and sets up the appropriate rules.
98:          */
99:         public VdmPartitionScanner() {
100:                 super();
101:                 IToken multilinecomment= new Token(MULTILINE_COMMENT);
102:                 IToken singlelinecomment= new Token(SINGLELINE_COMMENT);
103:                 IToken string = new Token(STRING);
104: //                IToken latex = new Token(LATEX);
105:                 
106:                 List<IPredicateRule> rules= new ArrayList<IPredicateRule>();
107:                 // Add rule for single line comments.
108:                 rules.add(new EndOfLineRule("--", singlelinecomment));
109:                 // Add rule for strings and character constants.
110:                 rules.add(new SingleLineRule("\"", "\"", string, '\\'));
111:                 //rules.add(new SingleLineRule("'", "'", string, '\\'));
112:                 rules.add(new VdmCharRule());
113:                 // Add rules for multi-line comments and javadoc.
114:                 rules.add(new MultiLineRule("/*", "*/", multilinecomment));
115:                 
116:                 
117:                 // Add special case word rule.
118:                 EmptyCommentRule wordRule= new EmptyCommentRule(multilinecomment);
119:                 rules.add(wordRule);
120:                 
121:
122:                 IPredicateRule[] result= new IPredicateRule[rules.size()];
123:                 rules.toArray(result);
124:                 setPredicateRules(result);
125:         }
126:         
127: }