@Test public void SPR10091_simpleTestValueType() { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder()); Class<?> valueType = parser.parseExpression("simpleProperty").getValueType(evaluationContext); assertNotNull(valueType); }
assertFalse(ex.isWritable(new StandardEvaluationContext(), new Rooty())); assertEquals(String.class,ex.getValueType()); assertEquals(String.class,ex.getValueType(ctx)); assertEquals(String.class,ex.getValueTypeDescriptor().getType()); assertEquals(String.class,ex.getValueTypeDescriptor(ctx).getType()); assertEquals(String.class,ex.getValueType(new Rooty())); assertEquals(String.class,ex.getValueType(ctx, new Rooty())); assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType()); assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
@Test public void SPR10091_primitiveTestValueType() { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder()); Class<?> valueType = parser.parseExpression("primitiveProperty").getValueType(evaluationContext); assertNotNull(valueType); }
public Class<?> getValueType() throws EvaluationException { return this.resolveExpression().getValueType(); }
public Class<?> getValueType(EvaluationContext context) throws EvaluationException { return this.resolveExpression().getValueType(context); }
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException { return this.resolveExpression().getValueType(context, rootObject); }
public Class<?> getValueType(Object rootObject) throws EvaluationException { return this.resolveExpression().getValueType(rootObject); }
/** * Returns the type of the expression target based on the given root. * * @param root must not be {@literal null}. * @return */ public Class<?> getType(Object root) { Assert.notNull(root, "Root object must not be null!"); try { return expression.getValueType(CONTEXT, root); } catch (SpelEvaluationException o_O) { if (!SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS.equals(o_O.getMessageCode())) { throw o_O; } Object collectionOrArray = getParent().getValue(root); if (Collection.class.isInstance(collectionOrArray)) { return CollectionUtils.findCommonElementType(Collection.class.cast(collectionOrArray)); } } throw new IllegalArgumentException(String.format("Cannot obtain type for path %s on %s!", path, root)); }
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException { return this.resolveExpression().getValueType(context, rootObject); }
public Class<?> getValueType() throws EvaluationException { return this.resolveExpression().getValueType(); }
public Class<?> getValueType(EvaluationContext context) throws EvaluationException { return this.resolveExpression().getValueType(context); }
public Class<?> getValueType(Object rootObject) throws EvaluationException { return this.resolveExpression().getValueType(rootObject); }
/** * Returns the type of the expression target based on the given root. * * @param root must not be {@literal null}. * @return */ public Class<?> getType(Object root) { Assert.notNull(root, "Root object must not be null!"); try { return expression.getValueType(CONTEXT, root); } catch (SpelEvaluationException o_O) { if (!SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS.equals(o_O.getMessageCode())) { throw o_O; } Object collectionOrArray = getParent().getValue(root); if (Collection.class.isInstance(collectionOrArray)) { return CollectionUtils.findCommonElementType(Collection.class.cast(collectionOrArray)); } } throw new IllegalArgumentException(String.format("Cannot obtain type for path %s on %s!", path, root)); }
Class<?> valueType = expression.getValueType(evaluationContext);
Class<?> valueType = expression.getValueType(evaluationContext);
@SuppressWarnings("deprecation") public Class<?> getValueType(Object rootObject) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } return expression.getValueType(context); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } throw new EvaluationException(rootObject.getClass(), getExpressionString(), "An ELException occurred getting the value type for expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "]", e); } }
@SuppressWarnings("deprecation") public Class<?> getValueType(Object rootObject) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } return expression.getValueType(context); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } throw new EvaluationException(rootObject.getClass(), getExpressionString(), "An ELException occurred getting the value type for expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "]", e); } }