@Override @Nullable public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (targetObject instanceof Class) { throw new IllegalArgumentException("DataBindingMethodResolver does not support Class targets"); } return super.resolve(context, targetObject, name, argumentTypes); }
MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, 45); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, 45f); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, 23d); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, (short) 23); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, 23L); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, (char) 65); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, (byte) 23); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args); me.execute(emptyEvalContext, ru, true); me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "bar", args); me.execute(emptyEvalContext, ru, 12, 23f);
Set<Method> result = new LinkedHashSet<>(); Method[] methods = getMethods(type); for (Method method : methods) { if (Modifier.isStatic(method.getModifiers())) { Collections.addAll(result, getMethods(Class.class)); return result; Method[] methods = getMethods(ifc); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method); Method[] methods = getMethods(type); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method);
TypeConverter typeConverter = context.getTypeConverter(); Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass()); ArrayList<Method> methods = new ArrayList<>(getMethods(type, targetObject));
private List<MethodResolver> initMethodResolvers() { List<MethodResolver> resolvers = this.methodResolvers; if (resolvers == null) { resolvers = new ArrayList<>(1); this.reflectiveMethodResolver = new ReflectiveMethodResolver(); resolvers.add(this.reflectiveMethodResolver); this.methodResolvers = resolvers; } return resolvers; }
/** * Register a {@code MethodFilter} which will be called during method resolution * for the specified type. * <p>The {@code MethodFilter} may remove methods and/or sort the methods which * will then be used by SpEL as the candidates to look through for a match. * @param type the type for which the filter should be called * @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type * @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use */ public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException { initMethodResolvers(); ReflectiveMethodResolver resolver = this.reflectiveMethodResolver; if (resolver == null) { throw new IllegalStateException( "Method filter cannot be set as the reflective method resolver is not in use"); } resolver.registerMethodFilter(type, filter); }
TypeConverter typeConverter = context.getTypeConverter(); Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass()); ArrayList<Method> methods = new ArrayList<>(getMethods(type, targetObject));
private List<MethodResolver> initMethodResolvers() { List<MethodResolver> resolvers = this.methodResolvers; if (resolvers == null) { resolvers = new ArrayList<>(1); this.reflectiveMethodResolver = new ReflectiveMethodResolver(); resolvers.add(this.reflectiveMethodResolver); this.methodResolvers = resolvers; } return resolvers; }
/** * Register a {@code MethodFilter} which will be called during method resolution * for the specified type. * <p>The {@code MethodFilter} may remove methods and/or sort the methods which * will then be used by SpEL as the candidates to look through for a match. * @param type the type for which the filter should be called * @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type * @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use */ public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException { initMethodResolvers(); ReflectiveMethodResolver resolver = this.reflectiveMethodResolver; if (resolver == null) { throw new IllegalStateException( "Method filter cannot be set as the reflective method resolver is not in use"); } resolver.registerMethodFilter(type, filter); }
@Override @Nullable public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (targetObject instanceof Class) { throw new IllegalArgumentException("DataBindingMethodResolver does not support Class targets"); } return super.resolve(context, targetObject, name, argumentTypes); }
@Ignore @Test public void repro() throws Exception { AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy(); BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter(); StandardEvaluationContext context = new StandardEvaluationContext(); context.setTypeConverter(converter); List<Foo> arguments = new ArrayList<>(); // !!!! With the below line commented you'll get NPE. Uncomment and everything is OK! //arguments.add(new Foo()); List<TypeDescriptor> paramDescriptors = new ArrayList<>(); Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class); paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0))); List<TypeDescriptor> argumentTypes = new ArrayList<>(); argumentTypes.add(TypeDescriptor.forObject(arguments)); ReflectiveMethodResolver resolver = new ReflectiveMethodResolver(); MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes); Object result = executor.execute(context, target, arguments); System.out.println("Result: " + result); }
Set<Method> result = new LinkedHashSet<>(); Method[] methods = getMethods(type); for (Method method : methods) { if (Modifier.isStatic(method.getModifiers())) { Collections.addAll(result, getMethods(Class.class)); return result; Method[] methods = getMethods(ifc); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method); Method[] methods = getMethods(type); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method);
@Override protected Method[] getMethods(Class<?> type) { Method[] methods = super.getMethods(type); List<Method> m = new ArrayList<>(asList(methods)); m.removeAll(rejectedMethods); m = m.stream() .filter(it -> ReturnTypeRestrictor.supports(it.getReturnType())) .collect(toList()); return m.toArray(new Method[m.size()]); } }
private List<MethodResolver> initMethodResolvers() { List<MethodResolver> resolvers = this.methodResolvers; if (resolvers == null) { resolvers = new ArrayList<>(1); this.reflectiveMethodResolver = new ReflectiveMethodResolver(); resolvers.add(this.reflectiveMethodResolver); this.methodResolvers = resolvers; } return resolvers; }
/** * Register a {@code MethodFilter} which will be called during method resolution * for the specified type. * <p>The {@code MethodFilter} may remove methods and/or sort the methods which * will then be used by SpEL as the candidates to look through for a match. * @param type the type for which the filter should be called * @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type * @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use */ public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException { initMethodResolvers(); ReflectiveMethodResolver resolver = this.reflectiveMethodResolver; if (resolver == null) { throw new IllegalStateException( "Method filter cannot be set as the reflective method resolver is not in use"); } resolver.registerMethodFilter(type, filter); }
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { this.validateMethod(targetObject, name, (argumentTypes != null ? argumentTypes.size() : 0)); return super.resolve(context, targetObject, name, argumentTypes); }
/** * Test whether {@link ReflectiveMethodResolver} handles Widening Primitive Conversion. That's passing an 'int' to a * method accepting 'long' is ok. */ @Test public void wideningPrimitiveConversion_SPR8224() throws Exception { class WideningPrimitiveConversion { public int getX(long i) { return 10; } } final Integer INTEGER_VALUE = Integer.valueOf(7); WideningPrimitiveConversion target = new WideningPrimitiveConversion(); EvaluationContext emptyEvalContext = new StandardEvaluationContext(); List<TypeDescriptor> args = new ArrayList<>(); 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); }
Set<Method> result = new LinkedHashSet<>(); Method[] methods = getMethods(type); for (Method method : methods) { if (Modifier.isStatic(method.getModifiers())) { Collections.addAll(result, getMethods(Class.class)); return result; Method[] methods = getMethods(ifc); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method); Method[] methods = getMethods(type); for (Method method : methods) { if (isCandidateForInvocation(method, type)) { result.add(method);
@Override protected Method[] getMethods(Class<?> type) { Method[] methods = super.getMethods(type); List<Method> m = new ArrayList<>(asList(methods)); m.removeAll(rejectedMethods); m = m.stream() .filter(it -> returnTypeRestrictor.supports(it.getReturnType())) .collect(toList()); return m.toArray(new Method[0]); } }
@Override @Nullable public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (targetObject instanceof Class) { throw new IllegalArgumentException("DataBindingMethodResolver does not support Class targets"); } return super.resolve(context, targetObject, name, argumentTypes); }