Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 7534b9bfd92e583101ddfcebfc032a116485727f (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
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsp.ui.internal.style.jspel;



import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;

/**
 * A Java code scanner.
 */
public class JSPELCodeScanner extends org.eclipse.jface.text.rules.RuleBasedScanner {
	private IToken fKeywordToken;
	private IToken fTypeToken;
	private IToken fDefaultToken;
	
	private static String[] fgKeywords = {
				"and", //$NON-NLS-1$
				"did", //$NON-NLS-1$
				"div", //$NON-NLS-1$
				"empty", //$NON-NLS-1$
				"eq", //$NON-NLS-1$
				"ge", //$NON-NLS-1$
				"gt", //$NON-NLS-1$
				"or", //$NON-NLS-1$
				"le", //$NON-NLS-1$
				"lt", //$NON-NLS-1$
				"mod", //$NON-NLS-1$
 				"ne", //$NON-NLS-1$
 				"not"  //$NON-NLS-1$
	};
	private static String[] fgConstants = {"false", "true"};//$NON-NLS-2$//$NON-NLS-1$

	/**
	 * Creates a Java code scanner
	 */
	public JSPELCodeScanner() {
		super();
	}
	
	public void initializeRules() {
		List rules = new ArrayList();

		// Add generic whitespace rule.
		rules.add(new WhitespaceRule(new JSPELWhitespaceDetector()));

		// Add word rule for keywords, types, and constants.
		WordRule wordRule = new WordRule(new JSPELWordDetector(), fDefaultToken);
		for (int i = 0; i < fgKeywords.length; i++)
			wordRule.addWord(fgKeywords[i], fKeywordToken);
		for (int i = 0; i < fgConstants.length; i++)
			wordRule.addWord(fgConstants[i], fTypeToken);
		rules.add(wordRule);

		IRule[] result = new IRule[rules.size()];
		rules.toArray(result);
		setRules(result);
	}
	
	public void setTokenData(String tokenKey, Object data) {
		if (tokenKey == IStyleConstantsJSPEL.EL_KEYWORD) {
			fKeywordToken = new Token(data);
			fTypeToken = new Token(data);
		} else if (tokenKey == IStyleConstantsJSPEL.EL_DEFAULT) {
			fDefaultToken = new Token(data);
		}
	}
}

Back to the top