@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])); }
@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 boolean isWritable(ExpressionState state) throws EvaluationException { return getValueRef(state).isWritable(); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { if (getChildCount() == 1) { return this.children[0].getValueRef(state); try { TypedValue result = nextNode.getValueInternal(state); int cc = getChildCount(); for (int i = 1; i < cc - 1; i++) { try {
@Test public void mixingItUp_propertyAccessIndexerOpLtTernaryRootNull() throws Exception { Payload payload = new Payload(); expression = parser.parseExpression("DR[0].three"); Object v = expression.getValue(payload); assertEquals("Lorg/springframework/expression/spel/SpelCompilationCoverageTests$Three", getAst().getExitDescriptor()); Expression expression = parser.parseExpression("DR[0].three.four lt 0.1d?#root:null"); v = expression.getValue(payload); SpelExpression sExpr = (SpelExpression) expression; Ternary ternary = (Ternary) sExpr.getAST(); OpLT oplt = (OpLT) ternary.getChild(0); CompoundExpression cExpr = (CompoundExpression) oplt.getLeftOperand(); String cExprExitDescriptor = cExpr.getExitDescriptor(); assertEquals("D", cExprExitDescriptor); assertEquals("Z", oplt.getExitDescriptor()); assertCanCompile(expression); Object vc = expression.getValue(payload); assertEquals(payload, v); assertEquals(payload,vc); payload.DR[0].three.four = 0.13d; vc = expression.getValue(payload); assertNull(vc); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { if (getChildCount() == 1) { return this.children[0].getValueRef(state); try { TypedValue result = nextNode.getValueInternal(state); int cc = getChildCount(); for (int i = 1; i < cc - 1; i++) { try {
@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(); }
/** * Evaluates a compound expression. This involves evaluating each piece in turn and the * return value from each piece is the active context object for the subsequent piece. * @param state the state in which the expression is being evaluated * @return the final value from the last piece of the compound expression */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { ValueRef ref = getValueRef(state); TypedValue result = ref.getValue(); this.exitTypeDescriptor = this.children[this.children.length - 1].exitTypeDescriptor; return result; }
@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])); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { if (getChildCount() == 1) { return this.children[0].getValueRef(state); try { TypedValue result = nextNode.getValueInternal(state); int cc = getChildCount(); for (int i = 1; i < cc - 1; i++) { try {
@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 void setValue(ExpressionState state, @Nullable Object value) throws EvaluationException { getValueRef(state).setValue(value); }
@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])); }
/** * Evaluates a compound expression. This involves evaluating each piece in turn and the * return value from each piece is the active context object for the subsequent piece. * @param state the state in which the expression is being evaluated * @return the final value from the last piece of the compound expression */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { ValueRef ref = getValueRef(state); TypedValue result = ref.getValue(); this.exitTypeDescriptor = this.children[this.children.length - 1].exitTypeDescriptor; return result; }
@Override public void setValue(ExpressionState state, @Nullable Object value) throws EvaluationException { getValueRef(state).setValue(value); }
@Override public boolean isWritable(ExpressionState state) throws EvaluationException { return getValueRef(state).isWritable(); }
/** * Evaluates a compound expression. This involves evaluating each piece in turn and the * return value from each piece is the active context object for the subsequent piece. * @param state the state in which the expression is being evaluated * @return the final value from the last piece of the compound expression */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { ValueRef ref = getValueRef(state); TypedValue result = ref.getValue(); this.exitTypeDescriptor = this.children[this.children.length - 1].exitTypeDescriptor; return result; }
@Override public void setValue(ExpressionState state, @Nullable Object value) throws EvaluationException { getValueRef(state).setValue(value); }
@Override public boolean isWritable(ExpressionState state) throws EvaluationException { return getValueRef(state).isWritable(); }