Java Code Examples for org.springframework.expression.spel.CodeFlow#toDescriptor()
The following examples show how to use
org.springframework.expression.spel.CodeFlow#toDescriptor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyOrFieldReference.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public TypedValue getValue() { TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences); if (this.ref.cachedReadAccessor instanceof CompilablePropertyAccessor) { CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) this.ref.cachedReadAccessor; this.ref.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType()); } return value; }
Example 2
Source File: PropertyOrFieldReference.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); PropertyAccessor accessorToUse = this.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse; this.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType()); } return tv; }
Example 3
Source File: MethodReference.java From java-technology-stack with MIT License | 5 votes |
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); String descriptor = CodeFlow.toDescriptor(method.getReturnType()); if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } } }
Example 4
Source File: MethodReference.java From lams with GNU General Public License v2.0 | 5 votes |
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); } }
Example 5
Source File: FunctionReference.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Execute a function represented as a java.lang.reflect.Method. * @param state the expression evaluation state * @param method the method to invoke * @return the return value of the invoked Java method * @throws EvaluationException if there is any problem invoking the method */ private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException { this.method = null; Object[] functionArgs = getArguments(state); if (!method.isVarArgs() && method.getParameterTypes().length != functionArgs.length) { throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, functionArgs.length, method.getParameterTypes().length); } // Only static methods can be called in this way if (!Modifier.isStatic(method.getModifiers())) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name); } this.argumentConversionOccurred = false; // Convert arguments if necessary and remap them for varargs if required if (functionArgs != null) { TypeConverter converter = state.getEvaluationContext().getTypeConverter(); this.argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method); } if (method.isVarArgs()) { functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation( method.getParameterTypes(), functionArgs); } try { ReflectionUtils.makeAccessible(method); Object result = method.invoke(method.getClass(), functionArgs); if (!argumentConversionOccurred) { this.method = method; this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); } return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result)); } catch (Exception ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL, this.name, ex.getMessage()); } }
Example 6
Source File: MethodReference.java From spring-analysis-note with MIT License | 5 votes |
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); String descriptor = CodeFlow.toDescriptor(method.getReturnType()); if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } } }
Example 7
Source File: PropertyOrFieldReference.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); PropertyAccessor accessorToUse = this.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse; this.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType()); } return tv; }
Example 8
Source File: PropertyOrFieldReference.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public TypedValue getValue() { TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences); PropertyAccessor accessorToUse = this.ref.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { this.ref.exitTypeDescriptor = CodeFlow.toDescriptor(((CompilablePropertyAccessor) accessorToUse).getPropertyType()); } return value; }
Example 9
Source File: MethodReference.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); } }
Example 10
Source File: Indexer.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public TypedValue getValue() { Class<?> targetObjectRuntimeClass = getObjectClass(this.targetObject); try { if (Indexer.this.cachedReadName != null && Indexer.this.cachedReadName.equals(this.name) && Indexer.this.cachedReadTargetType != null && Indexer.this.cachedReadTargetType.equals(targetObjectRuntimeClass)) { // It is OK to use the cached accessor return Indexer.this.cachedReadAccessor.read(this.evaluationContext, this.targetObject, this.name); } List<PropertyAccessor> accessorsToTry = AstUtils.getPropertyAccessorsToTry( targetObjectRuntimeClass, this.evaluationContext.getPropertyAccessors()); if (accessorsToTry != null) { for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canRead(this.evaluationContext, this.targetObject, this.name)) { if (accessor instanceof ReflectivePropertyAccessor) { accessor = ((ReflectivePropertyAccessor) accessor).createOptimalAccessor( this.evaluationContext, this.targetObject, this.name); } Indexer.this.cachedReadAccessor = accessor; Indexer.this.cachedReadName = this.name; Indexer.this.cachedReadTargetType = targetObjectRuntimeClass; if (accessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) { ReflectivePropertyAccessor.OptimalPropertyAccessor optimalAccessor = (ReflectivePropertyAccessor.OptimalPropertyAccessor) accessor; Member member = optimalAccessor.member; Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(member instanceof Method ? ((Method) member).getReturnType() : ((Field) member).getType()); } return accessor.read(this.evaluationContext, this.targetObject, this.name); } } } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString()); } throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString()); }
Example 11
Source File: Indexer.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public TypedValue getValue() { Class<?> targetObjectRuntimeClass = getObjectClass(this.targetObject); try { if (Indexer.this.cachedReadName != null && Indexer.this.cachedReadName.equals(this.name) && Indexer.this.cachedReadTargetType != null && Indexer.this.cachedReadTargetType.equals(targetObjectRuntimeClass)) { // It is OK to use the cached accessor return Indexer.this.cachedReadAccessor.read(this.evaluationContext, this.targetObject, this.name); } List<PropertyAccessor> accessorsToTry = AstUtils.getPropertyAccessorsToTry( targetObjectRuntimeClass, this.evaluationContext.getPropertyAccessors()); if (accessorsToTry != null) { for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canRead(this.evaluationContext, this.targetObject, this.name)) { if (accessor instanceof ReflectivePropertyAccessor) { accessor = ((ReflectivePropertyAccessor) accessor).createOptimalAccessor( this.evaluationContext, this.targetObject, this.name); } Indexer.this.cachedReadAccessor = accessor; Indexer.this.cachedReadName = this.name; Indexer.this.cachedReadTargetType = targetObjectRuntimeClass; if (accessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) { ReflectivePropertyAccessor.OptimalPropertyAccessor optimalAccessor = (ReflectivePropertyAccessor.OptimalPropertyAccessor) accessor; Member member = optimalAccessor.member; Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(member instanceof Method ? ((Method) member).getReturnType() : ((Field) member).getType()); } return accessor.read(this.evaluationContext, this.targetObject, this.name); } } } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString()); } throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString()); }
Example 12
Source File: Indexer.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public TypedValue getValue() { Object value = this.map.get(this.key); exitTypeDescriptor = CodeFlow.toDescriptor(Object.class); return new TypedValue(value, this.mapEntryDescriptor.getMapValueTypeDescriptor(value)); }
Example 13
Source File: FunctionReference.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Execute a function represented as a java.lang.reflect.Method. * @param state the expression evaluation state * @param method the method to invoke * @return the return value of the invoked Java method * @throws EvaluationException if there is any problem invoking the method */ private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException { this.method = null; Object[] functionArgs = getArguments(state); if (!method.isVarArgs() && method.getParameterTypes().length != functionArgs.length) { throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, functionArgs.length, method.getParameterTypes().length); } // Only static methods can be called in this way if (!Modifier.isStatic(method.getModifiers())) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_MUST_BE_STATIC, method.getDeclaringClass().getName() + "." + method.getName(), this.name); } argumentConversionOccurred = false; // Convert arguments if necessary and remap them for varargs if required if (functionArgs != null) { TypeConverter converter = state.getEvaluationContext().getTypeConverter(); argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method); } if (method.isVarArgs()) { functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs); } try { ReflectionUtils.makeAccessible(method); Object result = method.invoke(method.getClass(), functionArgs); if (!argumentConversionOccurred) { this.method = method; this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); } return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result)); } catch (Exception ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL, this.name, ex.getMessage()); } }
Example 14
Source File: Indexer.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public TypedValue getValue() { Object value = this.map.get(this.key); exitTypeDescriptor = CodeFlow.toDescriptor(Object.class); return new TypedValue(value, this.mapEntryDescriptor.getMapValueTypeDescriptor(value)); }
Example 15
Source File: Indexer.java From java-technology-stack with MIT License | 4 votes |
@Override public TypedValue getValue() { Object value = this.map.get(this.key); exitTypeDescriptor = CodeFlow.toDescriptor(Object.class); return new TypedValue(value, this.mapEntryDescriptor.getMapValueTypeDescriptor(value)); }
Example 16
Source File: FunctionReference.java From java-technology-stack with MIT License | 4 votes |
/** * Execute a function represented as a {@code java.lang.reflect.Method}. * @param state the expression evaluation state * @param method the method to invoke * @return the return value of the invoked Java method * @throws EvaluationException if there is any problem invoking the method */ private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException { Object[] functionArgs = getArguments(state); if (!method.isVarArgs()) { int declaredParamCount = method.getParameterCount(); if (declaredParamCount != functionArgs.length) { throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, functionArgs.length, declaredParamCount); } } if (!Modifier.isStatic(method.getModifiers())) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name); } // Convert arguments if necessary and remap them for varargs if required TypeConverter converter = state.getEvaluationContext().getTypeConverter(); boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method); if (method.isVarArgs()) { functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation( method.getParameterTypes(), functionArgs); } boolean compilable = false; try { ReflectionUtils.makeAccessible(method); Object result = method.invoke(method.getClass(), functionArgs); compilable = !argumentConversionOccurred; return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result)); } catch (Exception ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL, this.name, ex.getMessage()); } finally { if (compilable) { this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); this.method = method; } else { this.exitTypeDescriptor = null; this.method = null; } } }
Example 17
Source File: Indexer.java From spring-analysis-note with MIT License | 4 votes |
@Override public TypedValue getValue() { Object value = this.map.get(this.key); exitTypeDescriptor = CodeFlow.toDescriptor(Object.class); return new TypedValue(value, this.mapEntryDescriptor.getMapValueTypeDescriptor(value)); }
Example 18
Source File: FunctionReference.java From spring-analysis-note with MIT License | 4 votes |
/** * Execute a function represented as a {@code java.lang.reflect.Method}. * @param state the expression evaluation state * @param method the method to invoke * @return the return value of the invoked Java method * @throws EvaluationException if there is any problem invoking the method */ private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException { Object[] functionArgs = getArguments(state); if (!method.isVarArgs()) { int declaredParamCount = method.getParameterCount(); if (declaredParamCount != functionArgs.length) { throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, functionArgs.length, declaredParamCount); } } if (!Modifier.isStatic(method.getModifiers())) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name); } // Convert arguments if necessary and remap them for varargs if required TypeConverter converter = state.getEvaluationContext().getTypeConverter(); boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method); if (method.isVarArgs()) { functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation( method.getParameterTypes(), functionArgs); } boolean compilable = false; try { ReflectionUtils.makeAccessible(method); Object result = method.invoke(method.getClass(), functionArgs); compilable = !argumentConversionOccurred; return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result)); } catch (Exception ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL, this.name, ex.getMessage()); } finally { if (compilable) { this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType()); this.method = method; } else { this.exitTypeDescriptor = null; this.method = null; } } }