private void raiseParseException(int start, SpelMessage msg, Object... inserts) { throw new InternalParseException(new SpelParseException(this.expressionString, start, msg, inserts)); }
if (ex.getMessageCode() != expectedMessage) { assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode()); assertEquals("Did not get correct position reported in error ", pos, ex.getPosition()); if (otherProperties.length > 1) { Object[] inserts = ex.getInserts(); if (inserts == null) { inserts = new Object[0];
@Test public void testRogueTrailingDotCausesNPE_SPR6866() { try { new SpelExpressionParser().parseExpression("placeOfBirth.foo."); fail("Should have failed to parse"); } catch (SpelParseException ex) { assertEquals(SpelMessage.OOD, ex.getMessageCode()); assertEquals(16, ex.getPosition()); } }
@Test public void testPropertiesNested03() throws ParseException { try { new SpelExpressionParser().parseRaw("placeOfBirth.23"); fail(); } catch (SpelParseException spe) { assertEquals(SpelMessage.UNEXPECTED_DATA_AFTER_DOT, spe.getMessageCode()); assertEquals("23", spe.getInserts()[0]); } }
private void checkNumberError(String expression, SpelMessage expectedMessage) { try { SpelExpressionParser parser = new SpelExpressionParser(); parser.parseRaw(expression); fail(); } catch (ParseException ex) { assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(expectedMessage, spe.getMessageCode()); } }
@Test public void testStringLiterals_DoubleQuotes_spr9620_2() { try { new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\""); fail("Should have failed"); } catch (SpelParseException spe) { assertEquals(17, spe.getPosition()); assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode()); } }
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE, spe.getMessageCode());
private InternalParseException internalException(int startPos, SpelMessage message, Object... inserts) { return new InternalParseException(new SpelParseException(this.expressionString, startPos, message, inserts)); }
@Test public void AccessingFactoryBean_spr9511() { StandardEvaluationContext context = new StandardEvaluationContext(); context.setBeanResolver(new MyBeanResolver()); Expression expr = new SpelExpressionParser().parseRaw("@foo"); assertEquals("custard", expr.getValue(context)); expr = new SpelExpressionParser().parseRaw("&foo"); assertEquals("foo factory",expr.getValue(context)); try { expr = new SpelExpressionParser().parseRaw("&@foo"); fail("Illegal syntax, error expected"); } catch (SpelParseException spe) { assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode()); assertEquals(0,spe.getPosition()); } try { expr = new SpelExpressionParser().parseRaw("@&foo"); fail("Illegal syntax, error expected"); } catch (SpelParseException spe) { assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode()); assertEquals(0,spe.getPosition()); } }
public static Literal getLongLiteral(String numberToken, int startPos, int endPos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, startPos, endPos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(SpelMessage.MISSING_CONSTRUCTOR_ARGS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING, spe.getMessageCode()); assertEquals(0, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString()));
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int startPos, int endPos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, startPos, endPos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
public static Literal getRealLiteral(String numberToken, int startPos, int endPos, boolean isFloat) { try { if (isFloat) { float value = Float.parseFloat(numberToken); return new FloatLiteral(numberToken, startPos, endPos, value); } else { double value = Double.parseDouble(numberToken); return new RealLiteral(numberToken, startPos, endPos, value); } } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_REAL, numberToken)); } }
private InternalParseException internalException(int pos, SpelMessage message, Object... inserts) { return new InternalParseException(new SpelParseException(this.expressionString, pos, message, inserts)); }
private void raiseParseException(int start, SpelMessage msg, Object... inserts) { throw new InternalParseException(new SpelParseException(this.expressionString, start, msg, inserts)); }
public static Literal getLongLiteral(String numberToken, int pos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
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); }
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int pos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
public static Literal getRealLiteral(String numberToken, int pos, boolean isFloat) { try { if (isFloat) { float value = Float.parseFloat(numberToken); return new FloatLiteral(numberToken, pos, value); } else { double value = Double.parseDouble(numberToken); return new RealLiteral(numberToken, pos, value); } } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_REAL, numberToken)); } }
@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(); } }