Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@101 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
13 changed files with 1764 additions and 2804 deletions
@ -1,69 +0,0 @@
@@ -1,69 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.expression.spel.ast; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
import org.antlr.runtime.Token; |
||||
import org.springframework.expression.spel.SpelException; |
||||
import org.springframework.expression.spel.SpelMessages; |
||||
import org.springframework.expression.spel.ExpressionState; |
||||
|
||||
/** |
||||
* Represents the list of arguments supplied to a lambda expression. For an expression "{|x,y| $x > $y ? $x : $y }" the |
||||
* argument list is x,y |
||||
* |
||||
* @author Andy Clement |
||||
* |
||||
*/ |
||||
public class ArgList extends SpelNode { |
||||
|
||||
public ArgList(Token payload) { |
||||
super(payload); |
||||
} |
||||
|
||||
/** |
||||
* @return a list of the argument names captured in this ArgList |
||||
*/ |
||||
public List<String> getArgumentNames() { |
||||
if (getChildCount() == 0) |
||||
return Collections.emptyList(); |
||||
List<String> result = new ArrayList<String>(); |
||||
for (int i = 0; i < getChildCount(); i++) { |
||||
result.add(getChild(i).getText()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public String toStringAST() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < getChildCount(); i++) { |
||||
if (i > 0) |
||||
sb.append(","); |
||||
sb.append(getChild(i).toStringAST()); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getValue(ExpressionState state) throws SpelException { |
||||
throw new SpelException(SpelMessages.ARGLIST_SHOULD_NOT_BE_EVALUATED); |
||||
} |
||||
|
||||
} |
||||
@ -1,83 +0,0 @@
@@ -1,83 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.expression.spel.ast; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
import org.antlr.runtime.Token; |
||||
import org.springframework.expression.spel.SpelException; |
||||
import org.springframework.expression.spel.ExpressionState; |
||||
|
||||
/** |
||||
* Represent a Lambda expression, eg. "{|x,y| $x > $y ? $x : $y }". It is possible for an expression to have zero |
||||
* arguments in which case this expression node only has one child. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class Lambda extends SpelNode { |
||||
|
||||
public Lambda(Token payload) { |
||||
super(payload); |
||||
// payload.setText("LambdaExpression");
|
||||
} |
||||
|
||||
@Override |
||||
public Object getValue(ExpressionState state) throws SpelException { |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public String toStringAST() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
if (getChildCount() == 1) { // there are no arguments
|
||||
sb.append("{|| "); |
||||
sb.append(getChild(0).toStringAST()); |
||||
sb.append(" }"); |
||||
} else { |
||||
sb.append("{|"); |
||||
sb.append(getChild(0).toStringAST()); |
||||
sb.append("| "); |
||||
sb.append(getChild(1).toStringAST()); |
||||
sb.append(" }"); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return toStringAST(); |
||||
} |
||||
|
||||
public List<String> getArguments() { |
||||
// Only one child means there are no arguments
|
||||
if (getChildCount() < 2) { |
||||
return Collections.emptyList(); |
||||
} |
||||
ArgList args = (ArgList) getChild(0); |
||||
return args.getArgumentNames(); |
||||
} |
||||
|
||||
public Object getExpression() { |
||||
return (getChildCount() > 1 ? getChild(1) : getChild(0)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isWritable(ExpressionState expressionState) throws SpelException { |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -1,88 +0,0 @@
@@ -1,88 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.expression.spel.ast; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.antlr.runtime.Token; |
||||
import org.springframework.expression.EvaluationException; |
||||
import org.springframework.expression.spel.SpelException; |
||||
import org.springframework.expression.spel.SpelMessages; |
||||
import org.springframework.expression.spel.ExpressionState; |
||||
|
||||
/** |
||||
* Local functions are references like $fn() where fn is the 'local' to lookup in the local scope Example: "(#sqrt={|n| |
||||
* T(Math).sqrt($n)};#delegate={|f,n| $f($n)};#delegate(#sqrt,4))" |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class LocalFunctionReference extends SpelNode { |
||||
|
||||
private final String name; |
||||
|
||||
public LocalFunctionReference(Token payload) { |
||||
super(payload); |
||||
name = payload.getText(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getValue(ExpressionState state) throws EvaluationException { |
||||
Object o = state.lookupLocalVariable(name); |
||||
if (o == null) { |
||||
throw new SpelException(SpelMessages.FUNCTION_NOT_DEFINED, name); |
||||
} |
||||
if (!(o instanceof Lambda)) { |
||||
throw new SpelException(SpelMessages.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, name, o.getClass().getName()); |
||||
} |
||||
|
||||
Object[] arguments = new Object[getChildCount()]; |
||||
for (int i = 0; i < arguments.length; i++) { |
||||
arguments[i] = getChild(i).getValue(state); |
||||
} |
||||
Lambda lambdaExpression = (Lambda) o; |
||||
List<String> args = lambdaExpression.getArguments(); |
||||
Map<String, Object> argMap = new HashMap<String, Object>(); |
||||
if (args.size() != arguments.length) { |
||||
throw new SpelException(getCharPositionInLine(), SpelMessages.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, |
||||
arguments.length, args.size()); |
||||
} |
||||
for (int i = 0; i < args.size(); i++) { |
||||
argMap.put(args.get(i), arguments[i]); |
||||
} |
||||
try { |
||||
state.enterScope(argMap); |
||||
return ((SpelNode) lambdaExpression.getExpression()).getValue(state); |
||||
} finally { |
||||
state.exitScope(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String toStringAST() { |
||||
StringBuilder sb = new StringBuilder("$").append(name); |
||||
sb.append("("); |
||||
for (int i = 0; i < getChildCount(); i++) { |
||||
if (i > 0) |
||||
sb.append(","); |
||||
sb.append(getChild(i).toStringAST()); |
||||
} |
||||
sb.append(")"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.expression.spel.ast; |
||||
|
||||
import org.antlr.runtime.Token; |
||||
import org.springframework.expression.spel.SpelException; |
||||
import org.springframework.expression.spel.SpelMessages; |
||||
import org.springframework.expression.spel.ExpressionState; |
||||
|
||||
/** |
||||
* A variable reference such as $someVar. Local variables are only visible at the current scoping level or below within |
||||
* an expression. Calling a function introduces a new nested scope. |
||||
* |
||||
* @author Andy Clement |
||||
* |
||||
*/ |
||||
public class LocalVariableReference extends SpelNode { |
||||
|
||||
private final String name; |
||||
|
||||
public LocalVariableReference(Token payload) { |
||||
super(payload); |
||||
name = payload.getText(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getValue(ExpressionState state) throws SpelException { |
||||
Object result = state.lookupLocalVariable(name); |
||||
if (result == null) { |
||||
throw new SpelException(getCharPositionInLine(), SpelMessages.LOCAL_VARIABLE_NOT_DEFINED, name); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public void setValue(ExpressionState state, Object value) throws SpelException { |
||||
// Object oldValue = state.lookupVariable(name);
|
||||
state.setLocalVariable(name, value); |
||||
} |
||||
|
||||
@Override |
||||
public String toStringAST() { |
||||
return new StringBuilder("$").append(name).toString(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isWritable(ExpressionState expressionState) throws SpelException { |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
@ -1,87 +1,83 @@
@@ -1,87 +1,83 @@
|
||||
GREATER_THAN_OR_EQUAL=77 |
||||
SELECT_FIRST=56 |
||||
COMMA=49 |
||||
HOLDER=13 |
||||
GREATER_THAN=76 |
||||
TYPE=58 |
||||
GREATER_THAN_OR_EQUAL=71 |
||||
SELECT_FIRST=52 |
||||
COMMA=45 |
||||
HOLDER=12 |
||||
GREATER_THAN=70 |
||||
TYPE=54 |
||||
EXPRESSIONLIST=4 |
||||
MINUS=39 |
||||
MAP_ENTRY=24 |
||||
SELECT_LAST=57 |
||||
NUMBER=28 |
||||
LESS_THAN=74 |
||||
BANG=44 |
||||
ARGLIST=11 |
||||
FALSE=68 |
||||
METHOD=25 |
||||
MINUS=36 |
||||
MAP_ENTRY=21 |
||||
SELECT_LAST=53 |
||||
NUMBER=25 |
||||
LESS_THAN=68 |
||||
BANG=41 |
||||
FALSE=62 |
||||
METHOD=22 |
||||
PROPERTY_OR_FIELD=9 |
||||
LBRACKET=51 |
||||
LBRACKET=47 |
||||
INDEXER=10 |
||||
MOD=42 |
||||
CONSTRUCTOR_ARRAY=14 |
||||
FUNCTIONREF=16 |
||||
NULL_LITERAL=64 |
||||
NAMED_ARGUMENT=15 |
||||
OR=36 |
||||
PIPE=60 |
||||
DOT=45 |
||||
RCURLY=54 |
||||
MOD=39 |
||||
CONSTRUCTOR_ARRAY=13 |
||||
FUNCTIONREF=15 |
||||
NULL_LITERAL=58 |
||||
NAMED_ARGUMENT=14 |
||||
OR=33 |
||||
PIPE=77 |
||||
DOT=42 |
||||
RCURLY=50 |
||||
EXPRESSION=6 |
||||
AND=37 |
||||
LCURLY=61 |
||||
REAL_TYPE_SUFFIX=88 |
||||
STRING_LITERAL=62 |
||||
SELECT=55 |
||||
AND=34 |
||||
LCURLY=55 |
||||
REAL_TYPE_SUFFIX=84 |
||||
STRING_LITERAL=56 |
||||
SELECT=51 |
||||
QUALIFIED_IDENTIFIER=7 |
||||
RBRACKET=52 |
||||
SUBTRACT=27 |
||||
ASSIGN=30 |
||||
BETWEEN=80 |
||||
RPAREN=35 |
||||
SIGN=89 |
||||
LPAREN=34 |
||||
HEX_DIGIT=71 |
||||
PLUS=38 |
||||
LIST_INITIALIZER=20 |
||||
APOS=83 |
||||
RBRACKET=48 |
||||
SUBTRACT=24 |
||||
ASSIGN=27 |
||||
BETWEEN=74 |
||||
RPAREN=32 |
||||
SIGN=85 |
||||
LPAREN=31 |
||||
HEX_DIGIT=65 |
||||
PLUS=35 |
||||
LIST_INITIALIZER=19 |
||||
APOS=78 |
||||
INTEGER_LITERAL=5 |
||||
AT=50 |
||||
ID=47 |
||||
NOT_EQUAL=73 |
||||
RANGE=18 |
||||
POWER=43 |
||||
TYPEREF=17 |
||||
DECIMAL_DIGIT=69 |
||||
WS=85 |
||||
IS=79 |
||||
DOLLAR=48 |
||||
LESS_THAN_OR_EQUAL=75 |
||||
SEMIRPAREN=29 |
||||
DQ_STRING_LITERAL=63 |
||||
HEXADECIMAL_INTEGER_LITERAL=65 |
||||
MAP_INITIALIZER=21 |
||||
LAMBDA=59 |
||||
LOCALFUNC=23 |
||||
IN=78 |
||||
SEMI=82 |
||||
CONSTRUCTOR=12 |
||||
INTEGER_TYPE_SUFFIX=70 |
||||
EQUAL=72 |
||||
MATCHES=81 |
||||
DOT_ESCAPED=84 |
||||
UPTO=86 |
||||
QMARK=32 |
||||
AT=46 |
||||
ID=44 |
||||
NOT_EQUAL=67 |
||||
RANGE=17 |
||||
POWER=40 |
||||
TYPEREF=16 |
||||
DECIMAL_DIGIT=63 |
||||
WS=80 |
||||
IS=73 |
||||
DOLLAR=81 |
||||
LESS_THAN_OR_EQUAL=69 |
||||
SEMIRPAREN=26 |
||||
DQ_STRING_LITERAL=57 |
||||
HEXADECIMAL_INTEGER_LITERAL=59 |
||||
MAP_INITIALIZER=20 |
||||
IN=72 |
||||
SEMI=76 |
||||
CONSTRUCTOR=11 |
||||
INTEGER_TYPE_SUFFIX=64 |
||||
EQUAL=66 |
||||
MATCHES=75 |
||||
DOT_ESCAPED=79 |
||||
UPTO=82 |
||||
QMARK=29 |
||||
REFERENCE=8 |
||||
PROJECT=53 |
||||
DEFAULT=31 |
||||
COLON=33 |
||||
DIV=41 |
||||
LOCALVAR=22 |
||||
STAR=40 |
||||
REAL_LITERAL=66 |
||||
VARIABLEREF=19 |
||||
EXPONENT_PART=87 |
||||
TRUE=67 |
||||
ADD=26 |
||||
POUND=46 |
||||
'new'=90 |
||||
PROJECT=49 |
||||
DEFAULT=28 |
||||
COLON=30 |
||||
DIV=38 |
||||
STAR=37 |
||||
REAL_LITERAL=60 |
||||
VARIABLEREF=18 |
||||
EXPONENT_PART=83 |
||||
TRUE=61 |
||||
ADD=23 |
||||
POUND=43 |
||||
'new'=86 |
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue