Search in sources :

Example 6 with MultiLineRule

use of org.eclipse.jface.text.rules.MultiLineRule in project titan.EclipsePlug-ins by eclipse.

the class CodeScanner method getTTCNRules.

public static List<IRule> getTTCNRules(final ColorManager colorManager) {
    IToken singleLineComment = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_COMMENTS);
    IToken multiLineComment = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_COMMENTS);
    IToken keyword = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TTCN3_KEYWORDS);
    IToken templateMatch = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TEMPLATE_MATCH);
    IToken types = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TYPE);
    IToken timerOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TIMER_OP);
    IToken portOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PORT_OP);
    IToken configOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_CONFIG_OP);
    IToken verdictOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_VERDICT_OP);
    IToken sutOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_SUT_OP);
    IToken functionOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_FUNCTION_OP);
    IToken predefinedOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PREDEFINED_OP);
    IToken booleanConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_BOOLEAN_CONST);
    IToken verdictConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TTCN3_VERDICT_CONST);
    IToken otherConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_OTHER_CONST);
    IToken macro = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PREPROCESSOR);
    IToken visibility = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_VISIBILITY_OP);
    IToken string = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_STRINGS);
    IToken other = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_NORMAL_TEXT);
    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new EndOfLineRule("//", singleLineComment));
    rules.add(new MultiLineRule("/*", "*/", multiLineComment, '\0', true));
    rules.add(new WhitespaceRule(new WhiteSpaceDetector()));
    rules.add(new TTCN3StringDetectionPatternRule(string));
    rules.add(new StringDetectionPatternRule("'", new char[][] { { '\'', 'B' }, { '\'', 'H' }, { '\'', 'O' } }, string));
    WordRule wordRule = new WordRule(new WordDetector(), other);
    for (String element : CodeScanner.KEYWORDS) {
        wordRule.addWord(element, keyword);
    }
    for (String element : CodeScanner.TEMPLATE_MATCH) {
        wordRule.addWord(element, templateMatch);
    }
    for (String element : CodeScanner.TYPES) {
        wordRule.addWord(element, types);
    }
    for (String element : CodeScanner.TIMER_OPERATIONS) {
        wordRule.addWord(element, timerOp);
    }
    for (String element : CodeScanner.PORT_OPERATIONS) {
        wordRule.addWord(element, portOp);
    }
    for (String element : CodeScanner.CONFIGURATION_OPERATIONS) {
        wordRule.addWord(element, configOp);
    }
    for (String element : CodeScanner.VERDICT_OPERATIONS) {
        wordRule.addWord(element, verdictOp);
    }
    for (String element : CodeScanner.SUT_OPERATION) {
        wordRule.addWord(element, sutOp);
    }
    for (String element : CodeScanner.FUNCTION_OPERATIONS) {
        wordRule.addWord(element, functionOp);
    }
    for (String element : CodeScanner.PREDEFINED_OPERATIONS) {
        wordRule.addWord(element, predefinedOp);
    }
    for (String element : CodeScanner.BOOLEAN_CONSTANTS) {
        wordRule.addWord(element, booleanConst);
    }
    for (String element : CodeScanner.VERDICT_CONSTANT) {
        wordRule.addWord(element, verdictConst);
    }
    for (String element : CodeScanner.OTHER_CONSTANT) {
        wordRule.addWord(element, otherConst);
    }
    for (String element : CodeScanner.VISIBILITY_MODIFIERS) {
        wordRule.addWord(element, visibility);
    }
    rules.add(wordRule);
    WordRule macroRule = new WordRule(new MacroDetector(), other);
    for (String element : CodeScanner.MACROS) {
        macroRule.addWord(element, macro);
    }
    rules.add(macroRule);
    WordRule titanSpecificKeywordsRule = new WordRule(new TitanSpecificKeywordDetector(), other);
    for (String element : CodeScanner.TITANSPECIFICKEYWORDS) {
        // looks like a standard keyword
        titanSpecificKeywordsRule.addWord(element, keyword);
    }
    rules.add(titanSpecificKeywordsRule);
    return rules;
}
Also used : ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) StringDetectionPatternRule(org.eclipse.titan.designer.editors.StringDetectionPatternRule) WhitespaceRule(org.eclipse.jface.text.rules.WhitespaceRule) WordRule(org.eclipse.jface.text.rules.WordRule) IRule(org.eclipse.jface.text.rules.IRule) WhiteSpaceDetector(org.eclipse.titan.designer.editors.WhiteSpaceDetector) IToken(org.eclipse.jface.text.rules.IToken) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Example 7 with MultiLineRule

use of org.eclipse.jface.text.rules.MultiLineRule in project webtools.sourceediting by eclipse.

the class DefaultPartitionerZeroLengthTest method setUp.

public void setUp() {
    fDoc = new Document();
    IPartitionTokenScanner scanner = new RuleBasedPartitionScanner() {

        {
            IToken comment = new Token(COMMENT);
            IPredicateRule[] rules = new IPredicateRule[] { new MultiLineRule("/*", "*/", comment) };
            setPredicateRules(rules);
        }
    };
    fPartitioner = new FastPartitioner(scanner, new String[] { DEFAULT, COMMENT });
    fDoc.setDocumentPartitioner(fPartitioner);
    fPartitioner.connect(fDoc);
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) IToken(org.eclipse.jface.text.rules.IToken) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IPartitionTokenScanner(org.eclipse.jface.text.rules.IPartitionTokenScanner) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IPredicateRule(org.eclipse.jface.text.rules.IPredicateRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 8 with MultiLineRule

use of org.eclipse.jface.text.rules.MultiLineRule in project webtools.sourceediting by eclipse.

the class JSDTCodeScanner method initializeRules.

public void initializeRules() {
    List rules = new ArrayList();
    // Add rule for multiple line comments.
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", fMultiLineCommentToken));
    // Add rule for single line comments.
    // $NON-NLS-1$ //$NON-NLS-2$s
    rules.add(new SingleLineRule("//", "\n", fSingleLineCommentToken));
    // Add rule for strings and character constants.
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));
    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken);
    for (int i = 0; i < JSDTCodeScanner.fgKeywords.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgKeywords[i], fKeywordToken);
    }
    for (int i = 0; i < JSDTCodeScanner.fgTypes.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgTypes[i], fTypeToken);
    }
    for (int i = 0; i < JSDTCodeScanner.fgConstants.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgConstants[i], fTypeToken);
    }
    rules.add(wordRule);
    // add word rule for HTML style comment delimiters
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("<!--", "-->", fHTMLCommentBorderToken));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) ArrayList(java.util.ArrayList) List(java.util.List) WordRule(org.eclipse.jface.text.rules.WordRule) IRule(org.eclipse.jface.text.rules.IRule)

Example 9 with MultiLineRule

use of org.eclipse.jface.text.rules.MultiLineRule in project webtools.sourceediting by eclipse.

the class FastPartitionerTest method setUp.

public void setUp() {
    fDoc = new Document();
    IPartitionTokenScanner scanner = new RuleBasedPartitionScanner() {

        {
            IToken comment = new Token(COMMENT);
            IPredicateRule[] rules = new IPredicateRule[] { new MultiLineRule("/*", "*/", comment) };
            setPredicateRules(rules);
        }
    };
    fPartitioner = createPartitioner(scanner);
    fDoc.setDocumentPartitioner(fPartitioner);
    fPartitioner.connect(fDoc);
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) IToken(org.eclipse.jface.text.rules.IToken) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IPartitionTokenScanner(org.eclipse.jface.text.rules.IPartitionTokenScanner) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IPredicateRule(org.eclipse.jface.text.rules.IPredicateRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 10 with MultiLineRule

use of org.eclipse.jface.text.rules.MultiLineRule in project webtools.sourceediting by eclipse.

the class JavaCodeScanner method initializeRules.

public void initializeRules() {
    List rules = new ArrayList();
    // Add rule for multiple line comments.
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", fSingleLineCommentToken));
    // Add rule for single line comments.
    // $NON-NLS-1$
    rules.add(new EndOfLineRule("//", fSingleLineCommentToken));
    // Add rule for strings and character constants.
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));
    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken);
    for (int i = 0; i < fgKeywords.length; i++) wordRule.addWord(fgKeywords[i], fKeywordToken);
    for (int i = 0; i < fgTypes.length; i++) wordRule.addWord(fgTypes[i], fTypeToken);
    for (int i = 0; i < fgConstants.length; i++) wordRule.addWord(fgConstants[i], fTypeToken);
    rules.add(wordRule);
    // Add the double-quoted string rule
    rules.add(new DoubleQuotedStringRule(fStringToken));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) List(java.util.List) ArrayList(java.util.ArrayList) WordRule(org.eclipse.jface.text.rules.WordRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule) IRule(org.eclipse.jface.text.rules.IRule)

Aggregations

MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)15 IToken (org.eclipse.jface.text.rules.IToken)13 Token (org.eclipse.jface.text.rules.Token)11 IPartitionTokenScanner (org.eclipse.jface.text.rules.IPartitionTokenScanner)8 IPredicateRule (org.eclipse.jface.text.rules.IPredicateRule)8 RuleBasedPartitionScanner (org.eclipse.jface.text.rules.RuleBasedPartitionScanner)8 IRule (org.eclipse.jface.text.rules.IRule)7 ArrayList (java.util.ArrayList)6 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)5 Document (org.eclipse.jface.text.Document)4 IDocument (org.eclipse.jface.text.IDocument)4 TextAttribute (org.eclipse.jface.text.TextAttribute)4 EndOfLineRule (org.eclipse.jface.text.rules.EndOfLineRule)4 Test (org.junit.Test)4 WordRule (org.eclipse.jface.text.rules.WordRule)3 Color (org.eclipse.swt.graphics.Color)3 List (java.util.List)2 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)2 RGB (org.eclipse.swt.graphics.RGB)2 Before (org.junit.Before)2