private void throwIfNotNullSafe(List<TypeDescriptor> argumentTypes) { if (!this.nullSafe) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED, FormatHelper.formatMethodForMessage(this.name, argumentTypes)); } }
private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { AccessException accessException = null; List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, this.name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { accessException = ex; break; } } String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes); String className = FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()); if (accessException != null) { throw new SpelEvaluationException( getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, className); } }
/** * Produce a readable representation for a given method name with specified arguments. * @param name the name of the method * @param argumentTypes the types of the arguments to the method * @return a nicely formatted representation, e.g. {@code foo(String,int)} */ public static String formatMethodForMessage(String name, List<TypeDescriptor> argumentTypes) { StringBuilder sb = new StringBuilder(name); sb.append("("); for (int i = 0; i < argumentTypes.size(); i++) { if (i > 0) { sb.append(","); } TypeDescriptor typeDescriptor = argumentTypes.get(i); if (typeDescriptor != null) { sb.append(formatClassNameForMessage(typeDescriptor.getType())); } else { sb.append(formatClassNameForMessage(null)); } } sb.append(")"); return sb.toString(); }
/** * Produce a readable representation for a given method name with specified arguments. * @param name the name of the method * @param argumentTypes the types of the arguments to the method * @return a nicely formatted representation, e.g. {@code foo(String,int)} */ public static String formatMethodForMessage(String name, List<TypeDescriptor> argumentTypes) { StringBuilder sb = new StringBuilder(name); sb.append("("); for (int i = 0; i < argumentTypes.size(); i++) { if (i > 0) { sb.append(","); } TypeDescriptor typeDescriptor = argumentTypes.get(i); if (typeDescriptor != null) { sb.append(formatClassNameForMessage(typeDescriptor.getType())); } else { sb.append(formatClassNameForMessage(null)); } } sb.append(")"); return sb.toString(); }
private void throwIfNotNullSafe(List<TypeDescriptor> argumentTypes) { if (!this.nullSafe) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED, FormatHelper.formatMethodForMessage(this.name, argumentTypes)); } }
private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { AccessException accessException = null; List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, this.name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { accessException = ex; break; } } String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes); String className = FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()); if (accessException != null) { throw new SpelEvaluationException( getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, className); } }
FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
@Test public void formatMethodWithSingleArgumentForMessage() { String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"))); assertEquals("foo(java.lang.String)", message); }
private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { AccessException accessException = null; List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, this.name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { accessException = ex; break; } } String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes); String className = FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()); if (accessException != null) { throw new SpelEvaluationException( getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, className); } }
FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
@Test public void formatMethodWithMultipleArgumentsForMessage() { String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(Integer.valueOf(5)))); assertEquals("foo(java.lang.String,java.lang.Integer)", message); }
throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper.formatClassNameForMessage( intendedArrayType != null ? intendedArrayType.getClass() : null));
/** * Go through the list of registered constructor resolvers and see if any can find a * constructor that takes the specified set of arguments. * @param typeName the type trying to be constructed * @param argumentTypes the types of the arguments supplied that the constructor must take * @param state the current state of the expression * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null * @throws SpelEvaluationException if there is a problem locating the constructor */ private ConstructorExecutor findExecutorForConstructor(String typeName, List<TypeDescriptor> argumentTypes, ExpressionState state) throws SpelEvaluationException { EvaluationContext evalContext = state.getEvaluationContext(); List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers(); for (ConstructorResolver ctorResolver : ctorResolvers) { try { ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes); if (ce != null) { return ce; } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); } } throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); }
FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
throw new SpelEvaluationException(getStartPosition(), rootCause, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes));
FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
/** * Go through the list of registered constructor resolvers and see if any can find a * constructor that takes the specified set of arguments. * @param typeName the type trying to be constructed * @param argumentTypes the types of the arguments supplied that the constructor must take * @param state the current state of the expression * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null * @throws SpelEvaluationException if there is a problem locating the constructor */ private ConstructorExecutor findExecutorForConstructor(String typeName, List<TypeDescriptor> argumentTypes, ExpressionState state) throws SpelEvaluationException { EvaluationContext evalContext = state.getEvaluationContext(); List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers(); for (ConstructorResolver ctorResolver : ctorResolvers) { try { ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes); if (ce != null) { return ce; } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); } } throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); }
throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper.formatClassNameForMessage( intendedArrayType != null ? intendedArrayType.getClass() : null));
throw new SpelEvaluationException(getStartPosition(), rootCause, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes)); throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName, FormatHelper.formatMethodForMessage("", argumentTypes));
/** * Produce a readable representation for a given method name with specified arguments. * @param name the name of the method * @param argumentTypes the types of the arguments to the method * @return a nicely formatted representation, e.g. {@code foo(String,int)} */ public static String formatMethodForMessage(String name, List<TypeDescriptor> argumentTypes) { StringBuilder sb = new StringBuilder(name); sb.append("("); for (int i = 0; i < argumentTypes.size(); i++) { if (i > 0) { sb.append(","); } TypeDescriptor typeDescriptor = argumentTypes.get(i); if (typeDescriptor != null) { sb.append(formatClassNameForMessage(typeDescriptor.getType())); } else { sb.append(formatClassNameForMessage(null)); } } sb.append(")"); return sb.toString(); }