Package org.springframework.expression.spel.support

Examples of org.springframework.expression.spel.support.ReflectiveMethodResolver


    List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
    args.add(TypeDescriptor.forObject(new Integer(42)));

    ConversionPriority1 target = new ConversionPriority1();
    MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
    // MethodInvoker chooses getX(int i) when passing Integer
    final int actual = (Integer) me.execute(emptyEvalContext, target, new Integer(42)).getValue();
    // Compiler chooses getX(Number i) when passing Integer
    final int compiler = target.getX(INTEGER);
    // Fails!
    assertEquals(compiler, actual);

    ConversionPriority2 target2 = new ConversionPriority2();
    MethodExecutor me2 = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target2, "getX", args);
    // MethodInvoker chooses getX(int i) when passing Integer
    int actual2 = (Integer) me2.execute(emptyEvalContext, target2, new Integer(42)).getValue();
    // Compiler chooses getX(Number i) when passing Integer
    int compiler2 = target2.getX(INTEGER);
    // Fails!
View Full Code Here


    EvaluationContext emptyEvalContext = new StandardEvaluationContext();

    List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
    args.add(TypeDescriptor.forObject(INTEGER_VALUE));

    MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
    final int actual = (Integer) me.execute(emptyEvalContext, target, INTEGER_VALUE).getValue();

    final int compiler = target.getX(INTEGER_VALUE);
    assertEquals(compiler, actual);
  }
View Full Code Here

    EvaluationContext emptyEvalContext = new StandardEvaluationContext();
    List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();

    args.add(TypeDescriptor.forObject(34L));
    ReflectionUtil<Integer> ru = new ReflectionUtil<Integer>();
    MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args);

    args.set(0, TypeDescriptor.forObject(23));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, 45);

    args.set(0, TypeDescriptor.forObject(23f));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, 45f);

    args.set(0, TypeDescriptor.forObject(23d));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, 23d);

    args.set(0, TypeDescriptor.forObject((short) 23));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, (short) 23);

    args.set(0, TypeDescriptor.forObject(23L));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, 23L);

    args.set(0, TypeDescriptor.forObject((char) 65));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, (char) 65);

    args.set(0, TypeDescriptor.forObject((byte) 23));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, (byte) 23);

    args.set(0, TypeDescriptor.forObject(true));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
    me.execute(emptyEvalContext, ru, true);

    // trickier:
    args.set(0, TypeDescriptor.forObject(12));
    args.add(TypeDescriptor.forObject(23f));
    me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "bar", args);
    me.execute(emptyEvalContext, ru, 12, 23f);
  }
View Full Code Here

  @Test
  public void customStaticFunctions_SPR9038() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>();
    methodResolvers.add(new ReflectiveMethodResolver() {
      @Override
      protected Method[] getMethods(Class<?> type) {
        try {
          return new Method[] {
              Integer.class.getDeclaredMethod("parseInt", new Class[] { String.class, Integer.TYPE }) };
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.support.ReflectiveMethodResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.