Skip to main content
summaryrefslogtreecommitdiffstats
blob: abcc0fffb69fa2cad54650aedbf502f79c9284a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*****************************************************************************
 * Copyright (c) 2008 CEA LIST.
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Remi Schnekenburger (CEA LIST) Remi.Schnekenburger@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.parsers.texteditor.propertylabel;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.papyrus.parsers.texteditor.WhitespaceDetector;
import org.eclipse.papyrus.parsers.texteditor.completionproposals.DerivedPropertyCompletionProposal;
import org.eclipse.papyrus.parsers.texteditor.completionproposals.PropertyModifierProposal;
import org.eclipse.papyrus.parsers.texteditor.completionproposals.VisibilityCompletionProposal;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

/**
 * Scanner for the action language.<BR>
 * It implements the interface IALKeywords, which contains the different keywords available in the
 * action language
 *
 * @author Remi SCHNEKENBURGER
 * @see org.eclipse.jface.text.rules.RuleBasedScanner
 * @see com.cea.actionlanguage.sharedresources.texteditor.IRTActionKeywords
 */
public class PropertyLabelScanner extends RuleBasedScanner implements IPropertyLabelColorConstants {

	// Color for the default token
	/**
     *
     */
	private Color defaultColor;

	// Color for keywords
	/**
     *
     */
	private Color keywordColor;

	// Color for special chars
	/**
     *
     */
	private Color symbolColor;

	/**
	 * Creates a new rule based scanner.
	 */
	public PropertyLabelScanner() {
		defaultColor = PropertyLabelColorProvider.getDefault().getColor(DEFAULT);
		keywordColor = PropertyLabelColorProvider.getDefault().getColor(KEYWORD);
		symbolColor = PropertyLabelColorProvider.getDefault().getColor(SYMBOL);

		IToken other = new Token(new TextAttribute(defaultColor));
		IToken keyword = new Token(new TextAttribute(keywordColor, null, SWT.BOLD));
		IToken symbol = new Token(new TextAttribute(symbolColor, null, SWT.BOLD));

		IRule[] rules = new IRule[2];

		WordRule wordRule = new WordRule(new PropertyWordDetector(), other);
		for (int i = 0; i < VisibilityCompletionProposal.visibilityStrings.length; i++) {
			// wordRule.addWord(getWordWithoutQuotes(visibilityStrings[i]), keyword);
		}
		for (int i = 0; i < DerivedPropertyCompletionProposal.derivedPropertyStrings.length; i++) {
			// wordRule.addWord(getWordWithoutQuotes(isDerivedStrings[i]), keyword);
		}
		for (int i = 0; i < PropertyModifierProposal.modifiersStrings.length; i++) {
			wordRule.addWord(PropertyModifierProposal.modifiersStrings[i].trim(), keyword);
		}

		wordRule.addWord("+", symbol);
		wordRule.addWord("-", symbol);
		wordRule.addWord("#", symbol);
		wordRule.addWord("~", symbol);
		wordRule.addWord("/", symbol);
		wordRule.addWord("+/", symbol);
		wordRule.addWord("-/", symbol);
		wordRule.addWord("#/", symbol);
		wordRule.addWord(":", symbol);

		rules[0] = wordRule;
		rules[1] = new WhitespaceRule(new WhitespaceDetector());

		setRules(rules);
	}

	/**
	 * returns the word for the scanner, without quotes.
	 *
	 * @param word
	 *
	 * @return
	 */
	public static String getWordWithoutQuotes(String word) {
		String tmp = "";
		tmp = word.replaceAll("'", "");
		return tmp;
	}
}

Back to the top