org.springframework.expression.spel.ast.SpelNodeImpl Java Examples
The following examples show how to use
org.springframework.expression.spel.ast.SpelNodeImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
@Nullable private SpelNodeImpl eatStartNode() { if (maybeEatLiteral()) { return pop(); } else if (maybeEatParenExpression()) { return pop(); } else if (maybeEatTypeReference() || maybeEatNullReference() || maybeEatConstructorReference() || maybeEatMethodOrProperty(false) || maybeEatFunctionOrVar()) { return pop(); } else if (maybeEatBeanReference()) { return pop(); } else if (maybeEatProjection(false) || maybeEatSelection(false) || maybeEatIndexer()) { return pop(); } else if (maybeEatInlineListOrMap()) { return pop(); } else { return null; } }
Example #2
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); if (moreTokens()) { throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #3
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
private boolean maybeEatNode() { SpelNodeImpl expr = null; if (peekToken(TokenKind.DOT, TokenKind.SAFE_NAVI)) { expr = eatDottedNode(); } else { expr = maybeEatNonDottedNode(); } if (expr == null) { return false; } else { push(expr); return true; } }
Example #4
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private SpelNodeImpl eatStartNode() { if (maybeEatLiteral()) { return pop(); } else if (maybeEatParenExpression()) { return pop(); } else if (maybeEatTypeReference() || maybeEatNullReference() || maybeEatConstructorReference() || maybeEatMethodOrProperty(false) || maybeEatFunctionOrVar()) { return pop(); } else if (maybeEatBeanReference()) { return pop(); } else if (maybeEatProjection(false) || maybeEatSelection(false) || maybeEatIndexer()) { return pop(); } else if (maybeEatInlineListOrMap()) { return pop(); } else { return null; } }
Example #5
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { LinkedList<SpelNodeImpl> qualifiedIdPieces = new LinkedList<SpelNodeImpl>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(),toPos(node))); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { raiseInternalException( this.expressionString.length(), SpelMessage.OOD); } raiseInternalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition()); return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[qualifiedIdPieces.size()])); }
Example #6
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
private SpelNodeImpl eatDottedNode() { Token t = nextToken(); // it was a '.' or a '?.' boolean nullSafeNavigation = (t.kind == TokenKind.SAFE_NAVI); if (maybeEatMethodOrProperty(nullSafeNavigation) || maybeEatFunctionOrVar() || maybeEatProjection(nullSafeNavigation) || maybeEatSelection(nullSafeNavigation)) { return pop(); } if (peekToken() == null) { // unexpectedly ran out of data raiseInternalException(t.startPos, SpelMessage.OOD); } else { raiseInternalException(t.startPos, SpelMessage.UNEXPECTED_DATA_AFTER_DOT, toString(peekToken())); } return null; }
Example #7
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
private boolean maybeEatFunctionOrVar() { if (!peekToken(TokenKind.HASH)) { return false; } Token t = takeToken(); Token functionOrVariableName = eatToken(TokenKind.IDENTIFIER); SpelNodeImpl[] args = maybeEatMethodArgs(); if (args == null) { push(new VariableReference(functionOrVariableName.stringValue(), t.startPos, functionOrVariableName.endPos)); return true; } push(new FunctionReference(functionOrVariableName.stringValue(), t.startPos, functionOrVariableName.endPos, args)); return true; }
Example #8
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
private boolean maybeEatSelection(boolean nullSafeNavigation) { Token t = peekToken(); if (!peekSelectToken()) { return false; } nextToken(); SpelNodeImpl expr = eatExpression(); if (expr == null) { raiseInternalException(toPos(t), SpelMessage.MISSING_SELECTION_EXPRESSION); } eatToken(TokenKind.RSQUARE); if (t.kind == TokenKind.SELECT_FIRST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, toPos(t), expr)); } else if (t.kind == TokenKind.SELECT_LAST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, toPos(t), expr)); } else { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, toPos(t), expr)); } return true; }
Example #9
Source File: SpelCompiler.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Attempt compilation of the supplied expression. A check is made to see * if it is compilable before compilation proceeds. The check involves * visiting all the nodes in the expression Ast and ensuring enough state * is known about them that bytecode can be generated for them. * @param expression the expression to compile * @return an instance of the class implementing the compiled expression, * or {@code null} if compilation is not possible */ public CompiledExpression compile(SpelNodeImpl expression) { if (expression.isCompilable()) { if (logger.isDebugEnabled()) { logger.debug("SpEL: compiling " + expression.toStringAST()); } Class<? extends CompiledExpression> clazz = createExpressionClass(expression); if (clazz != null) { try { return clazz.newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Failed to instantiate CompiledExpression", ex); } } } if (logger.isDebugEnabled()) { logger.debug("SpEL: unable to compile " + expression.toStringAST()); } return null; }
Example #10
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private SpelNodeImpl eatPrimaryExpression() { SpelNodeImpl start = eatStartNode(); // always a start node List<SpelNodeImpl> nodes = null; SpelNodeImpl node = eatNode(); while (node != null) { if (nodes == null) { nodes = new ArrayList<>(4); nodes.add(start); } nodes.add(node); node = eatNode(); } if (start == null || nodes == null) { return start; } return new CompoundExpression(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition(), nodes.toArray(new SpelNodeImpl[0])); }
Example #11
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); Assert.state(ast != null, "No node"); Token t = peekToken(); if (t != null) { throw new SpelParseException(t.startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #12
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
/** * Used for consuming arguments for either a method or a constructor call. */ private void consumeArguments(List<SpelNodeImpl> accumulatedArguments) { Token t = peekToken(); Assert.state(t != null, "Expected token"); int pos = t.startPos; Token next; do { nextToken(); // consume (first time through) or comma (subsequent times) t = peekToken(); if (t == null) { throw internalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } if (t.kind != TokenKind.RPAREN) { accumulatedArguments.add(eatExpression()); } next = peekToken(); } while (next != null && next.kind == TokenKind.COMMA); if (next == null) { throw internalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } }
Example #13
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
private boolean maybeEatMethodOrProperty(boolean nullSafeNavigation) { if (peekToken(TokenKind.IDENTIFIER)) { Token methodOrPropertyName = takeToken(); SpelNodeImpl[] args = maybeEatMethodArgs(); if (args == null) { // property push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.stringValue(), methodOrPropertyName.startPos, methodOrPropertyName.endPos)); return true; } // method reference push(new MethodReference(nullSafeNavigation, methodOrPropertyName.stringValue(), methodOrPropertyName.startPos, methodOrPropertyName.endPos, args)); // TODO what is the end position for a method reference? the name or the last arg? return true; } return false; }
Example #14
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Used for consuming arguments for either a method or a constructor call */ private void consumeArguments(List<SpelNodeImpl> accumulatedArguments) { int pos = peekToken().startPos; Token next; do { nextToken(); // consume (first time through) or comma (subsequent times) Token t = peekToken(); if (t == null) { raiseInternalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } if (t.kind != TokenKind.RPAREN) { accumulatedArguments.add(eatExpression()); } next = peekToken(); } while (next != null && next.kind == TokenKind.COMMA); if (next == null) { raiseInternalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } }
Example #15
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Used for consuming arguments for either a method or a constructor call */ private void consumeArguments(List<SpelNodeImpl> accumulatedArguments) { int pos = peekToken().startPos; Token next; do { nextToken(); // consume ( (first time through) or comma (subsequent times) Token t = peekToken(); if (t == null) { raiseInternalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } if (t.kind != TokenKind.RPAREN) { accumulatedArguments.add(eatExpression()); } next = peekToken(); } while (next != null && next.kind == TokenKind.COMMA); if (next == null) { raiseInternalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } }
Example #16
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); tokenizer.process(); this.tokenStream = tokenizer.getTokens(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); if (moreTokens()) { throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty()); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #17
Source File: SpelCompiler.java From spring-analysis-note with MIT License | 6 votes |
/** * Attempt compilation of the supplied expression. A check is made to see * if it is compilable before compilation proceeds. The check involves * visiting all the nodes in the expression Ast and ensuring enough state * is known about them that bytecode can be generated for them. * @param expression the expression to compile * @return an instance of the class implementing the compiled expression, * or {@code null} if compilation is not possible */ @Nullable public CompiledExpression compile(SpelNodeImpl expression) { if (expression.isCompilable()) { if (logger.isDebugEnabled()) { logger.debug("SpEL: compiling " + expression.toStringAST()); } Class<? extends CompiledExpression> clazz = createExpressionClass(expression); if (clazz != null) { try { return ReflectionUtils.accessibleConstructor(clazz).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Failed to instantiate CompiledExpression", ex); } } } if (logger.isDebugEnabled()) { logger.debug("SpEL: unable to compile " + expression.toStringAST()); } return null; }
Example #18
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
private boolean maybeEatMethodOrProperty(boolean nullSafeNavigation) { if (peekToken(TokenKind.IDENTIFIER)) { Token methodOrPropertyName = takeToken(); SpelNodeImpl[] args = maybeEatMethodArgs(); if (args == null) { // property push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.stringValue(), toPos(methodOrPropertyName))); return true; } // method reference push(new MethodReference(nullSafeNavigation, methodOrPropertyName.stringValue(), toPos(methodOrPropertyName), args)); // TODO what is the end position for a method reference? the name or the last arg? return true; } return false; }
Example #19
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); Assert.state(ast != null, "No node"); Token t = peekToken(); if (t != null) { throw new SpelParseException(t.startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #20
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
private boolean maybeEatMethodOrProperty(boolean nullSafeNavigation) { if (peekToken(TokenKind.IDENTIFIER)) { Token methodOrPropertyName = nextToken(); SpelNodeImpl[] args = maybeEatMethodArgs(); if (args == null) { // property push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.data, toPos(methodOrPropertyName))); return true; } // method reference push(new MethodReference(nullSafeNavigation, methodOrPropertyName.data, toPos(methodOrPropertyName), args)); // TODO what is the end position for a method reference? the name or the last arg? return true; } return false; }
Example #21
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
@Nullable private SpelNodeImpl eatPrimaryExpression() { SpelNodeImpl start = eatStartNode(); // always a start node List<SpelNodeImpl> nodes = null; SpelNodeImpl node = eatNode(); while (node != null) { if (nodes == null) { nodes = new ArrayList<>(4); nodes.add(start); } nodes.add(node); node = eatNode(); } if (start == null || nodes == null) { return start; } return new CompoundExpression(toPos(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition()), nodes.toArray(new SpelNodeImpl[0])); }
Example #22
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { LinkedList<SpelNodeImpl> qualifiedIdPieces = new LinkedList<SpelNodeImpl>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node))); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { raiseInternalException( this.expressionString.length(), SpelMessage.OOD); } raiseInternalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition()); return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[qualifiedIdPieces.size()])); }
Example #23
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node))); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { throw internalException( this.expressionString.length(), SpelMessage.OOD); } throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition()); return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
Example #24
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
private boolean maybeEatSelection(boolean nullSafeNavigation) { Token t = peekToken(); if (!peekSelectToken()) { return false; } Assert.state(t != null, "No token"); nextToken(); SpelNodeImpl expr = eatExpression(); if (expr == null) { throw internalException(toPos(t), SpelMessage.MISSING_SELECTION_EXPRESSION); } eatToken(TokenKind.RSQUARE); if (t.kind == TokenKind.SELECT_FIRST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, toPos(t), expr)); } else if (t.kind == TokenKind.SELECT_LAST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, toPos(t), expr)); } else { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, toPos(t), expr)); } return true; }
Example #25
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
private boolean maybeEatFunctionOrVar() { if (!peekToken(TokenKind.HASH)) { return false; } Token t = takeToken(); Token functionOrVariableName = eatToken(TokenKind.IDENTIFIER); SpelNodeImpl[] args = maybeEatMethodArgs(); if (args == null) { push(new VariableReference(functionOrVariableName.stringValue(), toPos(t.startPos, functionOrVariableName.endPos))); return true; } push(new FunctionReference(functionOrVariableName.stringValue(), toPos(t.startPos, functionOrVariableName.endPos), args)); return true; }
Example #26
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
/** * Used for consuming arguments for either a method or a constructor call. */ private void consumeArguments(List<SpelNodeImpl> accumulatedArguments) { Token t = peekToken(); Assert.state(t != null, "Expected token"); int pos = t.startPos; Token next; do { nextToken(); // consume (first time through) or comma (subsequent times) t = peekToken(); if (t == null) { throw internalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } if (t.kind != TokenKind.RPAREN) { accumulatedArguments.add(eatExpression()); } next = peekToken(); } while (next != null && next.kind == TokenKind.COMMA); if (next == null) { throw internalException(pos, SpelMessage.RUN_OUT_OF_ARGUMENTS); } }
Example #27
Source File: SpelCompiler.java From java-technology-stack with MIT License | 6 votes |
/** * Attempt compilation of the supplied expression. A check is made to see * if it is compilable before compilation proceeds. The check involves * visiting all the nodes in the expression Ast and ensuring enough state * is known about them that bytecode can be generated for them. * @param expression the expression to compile * @return an instance of the class implementing the compiled expression, * or {@code null} if compilation is not possible */ @Nullable public CompiledExpression compile(SpelNodeImpl expression) { if (expression.isCompilable()) { if (logger.isDebugEnabled()) { logger.debug("SpEL: compiling " + expression.toStringAST()); } Class<? extends CompiledExpression> clazz = createExpressionClass(expression); if (clazz != null) { try { return ReflectionUtils.accessibleConstructor(clazz).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Failed to instantiate CompiledExpression", ex); } } } if (logger.isDebugEnabled()) { logger.debug("SpEL: unable to compile " + expression.toStringAST()); } return null; }
Example #28
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 5 votes |
private boolean maybeEatProjection(boolean nullSafeNavigation) { Token t = peekToken(); if (!peekToken(TokenKind.PROJECT, true)) { return false; } Assert.state(t != null, "No token"); SpelNodeImpl expr = eatExpression(); Assert.state(expr != null, "No node"); eatToken(TokenKind.RSQUARE); this.constructedNodes.push(new Projection(nullSafeNavigation, toPos(t), expr)); return true; }
Example #29
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) { if (!peekToken(TokenKind.LPAREN)) { throw new InternalParseException(new SpelParseException(this.expressionString, positionOf(peekToken()), SpelMessage.MISSING_CONSTRUCTOR_ARGS)); } consumeArguments(accumulatedArguments); eatToken(TokenKind.RPAREN); }
Example #30
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 5 votes |
private boolean maybeEatIndexer() { Token t = peekToken(); if (!peekToken(TokenKind.LSQUARE, true)) { return false; } Assert.state(t != null, "No token"); SpelNodeImpl expr = eatExpression(); Assert.state(expr != null, "No node"); eatToken(TokenKind.RSQUARE); this.constructedNodes.push(new Indexer(toPos(t), expr)); return true; }