private void checkLeftOperand(Token token, @Nullable SpelNodeImpl operandExpression) { if (operandExpression == null) { throw internalException(token.startPos, SpelMessage.LEFT_OPERAND_PROBLEM); } }
private void checkRightOperand(Token token, @Nullable SpelNodeImpl operandExpression) { if (operandExpression == null) { throw internalException(token.startPos, SpelMessage.RIGHT_OPERAND_PROBLEM); } }
private void checkRightOperand(Token token, @Nullable SpelNodeImpl operandExpression) { if (operandExpression == null) { throw internalException(token.startPos, SpelMessage.RIGHT_OPERAND_PROBLEM); } }
private void checkLeftOperand(Token token, @Nullable SpelNodeImpl operandExpression) { if (operandExpression == null) { throw internalException(token.startPos, SpelMessage.LEFT_OPERAND_PROBLEM); } }
private Token eatToken(TokenKind expectedKind) { Token t = nextToken(); if (t == null) { int pos = this.expressionString.length(); throw internalException(pos, SpelMessage.OOD); } if (t.kind != expectedKind) { throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase()); } return t; }
/** * 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); } }
private Token eatToken(TokenKind expectedKind) { Token t = nextToken(); if (t == null) { int pos = this.expressionString.length(); throw internalException(pos, SpelMessage.OOD); } if (t.kind != expectedKind) { throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase()); } return t; }
/** * 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(), node.startPos, node.endPos)); } 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()); } return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
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(t.startPos, SpelMessage.MISSING_SELECTION_EXPRESSION); } eatToken(TokenKind.RSQUARE); if (t.kind == TokenKind.SELECT_FIRST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, t.startPos, t.endPos, expr)); } else if (t.kind == TokenKind.SELECT_LAST) { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, t.startPos, t.endPos, expr)); } else { this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, t.startPos, t.endPos, expr)); } return true; }
private SpelNodeImpl eatDottedNode() { Token t = takeToken(); // 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 throw internalException(t.startPos, SpelMessage.OOD); } else { throw internalException(t.startPos, SpelMessage.UNEXPECTED_DATA_AFTER_DOT, toString(peekToken())); } }
/** * 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); } }
private boolean maybeEatBeanReference() { if (peekToken(TokenKind.BEAN_REF) || peekToken(TokenKind.FACTORY_BEAN_REF)) { Token beanRefToken = takeToken(); Token beanNameToken = null; String beanName = null; if (peekToken(TokenKind.IDENTIFIER)) { beanNameToken = eatToken(TokenKind.IDENTIFIER); beanName = beanNameToken.stringValue(); } else if (peekToken(TokenKind.LITERAL_STRING)) { beanNameToken = eatToken(TokenKind.LITERAL_STRING); beanName = beanNameToken.stringValue(); beanName = beanName.substring(1, beanName.length() - 1); } else { throw internalException(beanRefToken.startPos, SpelMessage.INVALID_BEAN_REFERENCE); } BeanReference beanReference; if (beanRefToken.getKind() == TokenKind.FACTORY_BEAN_REF) { String beanNameString = String.valueOf(TokenKind.FACTORY_BEAN_REF.tokenChars) + beanName; beanReference = new BeanReference(beanRefToken.startPos, beanNameToken.endPos, beanNameString); } else { beanReference = new BeanReference(beanNameToken.startPos, beanNameToken.endPos, beanName); } this.constructedNodes.push(beanReference); return true; } return false; }
throw internalException(t.startPos, SpelMessage.OOD);
/** * 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])); }
private SpelNodeImpl eatDottedNode() { Token t = takeToken(); // 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 throw internalException(t.startPos, SpelMessage.OOD); } else { throw internalException(t.startPos, SpelMessage.UNEXPECTED_DATA_AFTER_DOT, toString(peekToken())); } }
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; }
throw internalException(beanRefToken.startPos, SpelMessage.INVALID_BEAN_REFERENCE);
throw internalException(t.startPos, SpelMessage.OOD);
private void checkLeftOperand(Token token, @Nullable SpelNodeImpl operandExpression) { if (operandExpression == null) { throw internalException(token.startPos, SpelMessage.LEFT_OPERAND_PROBLEM); } }
private Token eatToken(TokenKind expectedKind) { Token t = nextToken(); if (t == null) { int pos = this.expressionString.length(); throw internalException(pos, SpelMessage.OOD); } if (t.kind != expectedKind) { throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase()); } return t; }