use of freemarker.ext.beans.BeansWrapper.MethodAppearanceDecisionInput in project freemarker by apache.
the class ClassIntrospector method addBeanInfoToClassIntrospectionData.
private void addBeanInfoToClassIntrospectionData(Map<Object, Object> introspData, Class<?> clazz, Map<MethodSignature, List<Method>> accessibleMethods) throws IntrospectionException {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
List<PropertyDescriptor> pdas = getPropertyDescriptors(beanInfo, clazz);
int pdasLength = pdas.size();
// Reverse order shouldn't mater, but we keep it to not risk backward incompatibility.
for (int i = pdasLength - 1; i >= 0; --i) {
addPropertyDescriptorToClassIntrospectionData(introspData, pdas.get(i), clazz, accessibleMethods);
}
if (exposureLevel < BeansWrapper.EXPOSE_PROPERTIES_ONLY) {
final MethodAppearanceDecision decision = new MethodAppearanceDecision();
MethodAppearanceDecisionInput decisionInput = null;
List<MethodDescriptor> mds = getMethodDescriptors(beanInfo, clazz);
sortMethodDescriptors(mds);
int mdsSize = mds.size();
IdentityHashMap<Method, Void> argTypesUsedByIndexerPropReaders = null;
for (int i = mdsSize - 1; i >= 0; --i) {
final Method method = getMatchingAccessibleMethod(mds.get(i).getMethod(), accessibleMethods);
if (method != null && isAllowedToExpose(method)) {
decision.setDefaults(method);
if (methodAppearanceFineTuner != null) {
if (decisionInput == null) {
decisionInput = new MethodAppearanceDecisionInput();
}
decisionInput.setContainingClass(clazz);
decisionInput.setMethod(method);
methodAppearanceFineTuner.process(decisionInput, decision);
}
PropertyDescriptor propDesc = decision.getExposeAsProperty();
if (propDesc != null && (decision.getReplaceExistingProperty() || !(introspData.get(propDesc.getName()) instanceof FastPropertyDescriptor))) {
addPropertyDescriptorToClassIntrospectionData(introspData, propDesc, clazz, accessibleMethods);
}
String methodKey = decision.getExposeMethodAs();
if (methodKey != null) {
Object previous = introspData.get(methodKey);
if (previous instanceof Method) {
// Overloaded method - replace Method with a OverloadedMethods
OverloadedMethods overloadedMethods = new OverloadedMethods(bugfixed);
overloadedMethods.addMethod((Method) previous);
overloadedMethods.addMethod(method);
introspData.put(methodKey, overloadedMethods);
// Remove parameter type information (unless an indexed property reader needs it):
if (argTypesUsedByIndexerPropReaders == null || !argTypesUsedByIndexerPropReaders.containsKey(previous)) {
getArgTypesByMethod(introspData).remove(previous);
}
} else if (previous instanceof OverloadedMethods) {
// Already overloaded method - add new overload
((OverloadedMethods) previous).addMethod(method);
} else if (decision.getMethodShadowsProperty() || !(previous instanceof FastPropertyDescriptor)) {
// Simple method (this far)
introspData.put(methodKey, method);
Class<?>[] replaced = getArgTypesByMethod(introspData).put(method, method.getParameterTypes());
if (replaced != null) {
if (argTypesUsedByIndexerPropReaders == null) {
argTypesUsedByIndexerPropReaders = new IdentityHashMap<Method, Void>();
}
argTypesUsedByIndexerPropReaders.put(method, null);
}
}
}
}
}
// for each in mds
}
// end if (exposureLevel < EXPOSE_PROPERTIES_ONLY)
}
Aggregations