View Javadoc
1   /*
2    * Copyright 2002-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.expression.spel.standard;
18  
19  /**
20   * Token Kinds.
21   *
22   * @author Andy Clement
23   * @since 3.0
24   */
25  enum TokenKind {
26  
27  	// ordered by priority - operands first
28  
29  	LITERAL_INT,
30  
31  	LITERAL_LONG,
32  
33  	LITERAL_HEXINT,
34  
35  	LITERAL_HEXLONG,
36  
37  	LITERAL_STRING,
38  
39  	LITERAL_REAL,
40  
41  	LITERAL_REAL_FLOAT,
42  
43  	LPAREN("("),
44  
45  	RPAREN(")"),
46  
47  	COMMA(","),
48  
49  	IDENTIFIER,
50  
51  	COLON(":"),
52  
53  	HASH("#"),
54  
55  	RSQUARE("]"),
56  
57  	LSQUARE("["),
58  
59  	LCURLY("{"),
60  
61  	RCURLY("}"),
62  
63  	DOT("."),
64  
65  	PLUS("+"),
66  
67  	STAR("*"),
68  
69  	MINUS("-"),
70  
71  	SELECT_FIRST("^["),
72  
73  	SELECT_LAST("$["),
74  
75  	QMARK("?"),
76  
77  	PROJECT("!["),
78  
79  	DIV("/"),
80  
81  	GE(">="),
82  
83  	GT(">"),
84  
85  	LE("<="),
86  
87  	LT("<"),
88  
89  	EQ("=="),
90  
91  	NE("!="),
92  
93  	MOD("%"),
94  
95  	NOT("!"),
96  
97  	ASSIGN("="),
98  
99  	INSTANCEOF("instanceof"),
100 
101 	MATCHES("matches"),
102 
103 	BETWEEN("between"),
104 
105 	SELECT("?["),
106 
107 	POWER("^"),
108 
109 	ELVIS("?:"),
110 
111 	SAFE_NAVI("?."),
112 
113 	BEAN_REF("@"),
114 
115 	SYMBOLIC_OR("||"),
116 
117 	SYMBOLIC_AND("&&"),
118 
119 	INC("++"),
120 
121 	DEC("--");
122 
123 
124 	final char[] tokenChars;
125 
126 	final private boolean hasPayload;  // is there more to this token than simply the kind
127 
128 
129 	private TokenKind(String tokenString) {
130 		this.tokenChars = tokenString.toCharArray();
131 		this.hasPayload = (this.tokenChars.length == 0);
132 	}
133 
134 	private TokenKind() {
135 		this("");
136 	}
137 
138 
139 	@Override
140 	public String toString() {
141 		return (name() + (this.tokenChars.length !=0 ? "(" + new String(this.tokenChars) +")" : ""));
142 	}
143 
144 	public boolean hasPayload() {
145 		return this.hasPayload;
146 	}
147 
148 	public int getLength() {
149 		return this.tokenChars.length;
150 	}
151 
152 }