/** * Returns the name of the {@link ExpressionNode}. * * @return */ public String getName() { return node.toStringAST(); }
/** * Returns the value of the current node. * * @return */ @Nullable public Object getValue() { return node.getValue(state); }
private static void printAST(PrintStream out, SpelNode t, String indent) { if (t != null) { StringBuilder sb = new StringBuilder(); sb.append(indent).append(t.getClass().getSimpleName()); sb.append(" value:").append(t.toStringAST()); sb.append(t.getChildCount() < 2 ? "" : " #children:" + t.getChildCount()); out.println(sb.toString()); for (int i = 0; i < t.getChildCount(); i++) { printAST(out, t.getChild(i), indent + " "); } } }
private Operator findOperator(SpelNode node) { if (node instanceof Operator) { return (Operator) node; } int childCount = node.getChildCount(); for (int i = 0; i < childCount; i++) { Operator possible = findOperator(node.getChild(i)); if (possible != null) { return possible; } } return null; }
Object intendedArrayType = getChild(0).getValue(state); if (!(intendedArrayType instanceof String)) { throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper.formatClassNameForMessage(
private void populateBooleanArray(ExpressionState state, Object newArray, TypeConverter typeConverter, InlineList initializer) { boolean[] newBooleanArray = (boolean[]) newArray; for (int i = 0; i < newBooleanArray.length; i++) { TypedValue typedValue = initializer.getChild(i).getTypedValue(state); newBooleanArray[i] = ExpressionUtils.toBoolean(typeConverter, typedValue); } }
/** * {@inheritDoc} */ @Override public Iterable<Node> getAll(GraphDatabaseService database) { //In simple cases, we can fetch nodes using more efficient native syntax if(expressionNode.toStringAST().startsWith("hasLabel")) { String labelName = stripWrappingQuotes(expressionNode.getChild(0).toStringAST()); return () -> database.findNodes(Label.label(labelName)); } return new FilteringIterable<>(database.getAllNodes(), this::include); }
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { try { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } return BooleanTypedValue.forValue(!value); } catch (SpelEvaluationException ex) { ex.setPosition(getChild(0).getStartPosition()); throw ex; } }
/** * Returns whether the {@link ExpressionNode} has a first child node that is not of the given type. * * @param type must not be {@literal null}. * @return */ public boolean hasfirstChildNotOfType(Class<?> type) { Assert.notNull(type, "Type must not be null!"); return hasChildren() && !node.getChild(0).getClass().equals(type); }
/** * Returns whether the current node has child nodes. * * @return */ public boolean hasChildren() { return node.getChildCount() != 0; }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue newValue = this.children[1].getValueInternal(state); getChild(0).setValue(state, newValue.getValue()); return newValue; }
@Test public void positionalInformation() { SpelExpression expr = new SpelExpressionParser().parseRaw("true and true or false"); SpelNode rootAst = expr.getAST(); OpOr operatorOr = (OpOr) rootAst; OpAnd operatorAnd = (OpAnd) operatorOr.getLeftOperand(); SpelNode rightOrOperand = operatorOr.getRightOperand(); // check position for final 'false' assertEquals(17, rightOrOperand.getStartPosition()); assertEquals(22, rightOrOperand.getEndPosition()); // check position for first 'true' assertEquals(0, operatorAnd.getLeftOperand().getStartPosition()); assertEquals(4, operatorAnd.getLeftOperand().getEndPosition()); // check position for second 'true' assertEquals(9, operatorAnd.getRightOperand().getStartPosition()); assertEquals(13, operatorAnd.getRightOperand().getEndPosition()); // check position for OperatorAnd assertEquals(5, operatorAnd.getStartPosition()); assertEquals(8, operatorAnd.getEndPosition()); // check position for OperatorOr assertEquals(14, operatorOr.getStartPosition()); assertEquals(16, operatorOr.getEndPosition()); }
Object intendedArrayType = getChild(0).getValue(state); if (!(intendedArrayType instanceof String)) { throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper.formatClassNameForMessage(
private void populateByteArray(ExpressionState state, Object newArray, TypeConverter typeConverter, InlineList initializer) { byte[] newByteArray = (byte[]) newArray; for (int i = 0; i < newByteArray.length; i++) { TypedValue typedValue = initializer.getChild(i).getTypedValue(state); newByteArray[i] = ExpressionUtils.toByte(typeConverter, typedValue); } }
/** * Evaluate the condition and if true evaluate the first alternative, otherwise * evaluate the second alternative. * @param state the expression state * @throws EvaluationException if the condition does not evaluate correctly to * a boolean or there is a problem executing the chosen alternative */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } TypedValue result = this.children[value ? 1 : 2].getValueInternal(state); computeExitTypeDescriptor(); return result; }
/** * Returns the child {@link ExpressionNode} with the given index. * * @param index must not be negative. * @return */ public ExpressionNode getChild(int index) { Assert.isTrue(index >= 0, "Index must be greater or equal to zero!"); return from(node.getChild(index), state); }
@Override public boolean hasNext() { return index < node.getChildCount(); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue newValue = this.children[1].getValueInternal(state); getChild(0).setValue(state, newValue.getValue()); return newValue; }
@Override public String toStringAST() { StringBuilder sb = new StringBuilder("T("); sb.append(getChild(0).toStringAST()); for (int d = 0; d < this.dimensions; d++) { sb.append("[]"); } sb.append(")"); return sb.toString(); }
private List<String> findPermissions(SpelNode node) { List<String> list = new ArrayList<>(node.getChildCount()); if (startsWithIgnoreCase(node.toStringAST(), "hasRole") || startsWithIgnoreCase(node.toStringAST(), "hasAnyRole")) { for (int i = 0; i < node.getChildCount(); ++i) { list.add(remove(node.getChild(i).toStringAST(), '\'')); } } else { for (int i = 0; i < node.getChildCount(); ++i) { list.addAll(findPermissions(node.getChild(i))); } } LOGGER.debug("Found permissions: {}", list); return list; }