}
if (property) {
ITypeBinding fieldType = field.getType();
String fieldTypeName = new TypeResolver(fieldType).resolve();
Property prop = new Property(getVisibility(field.getModifiers()), field.getDeclaringClass().getQualifiedName(),
fieldTypeName, field.getName());
prop.setDeprecated(deprecated);
prop.setFieldName(field.getName());
bean.addProperty(prop);
}
}
// discover getters that can be properties
for (IMethodBinding method : type.getDeclaredMethods()) {
String name = method.getName();
// we are only interested in getters
if (method.getParameterTypes().length > 0) {
continue;
}
boolean set = name.length() > 3 && name.startsWith("get") && Character.isUpperCase(name.charAt(3));
boolean is = name.length() > 2 && name.startsWith("is") && Character.isUpperCase(name.charAt(2));
if (!set && !is) {
continue;
}
name = set ? Character.toLowerCase(name.charAt(3)) + name.substring(4) : Character.toLowerCase(name.charAt(2))
+ name.substring(3);
// scan annotations of the method
boolean property = false;
boolean deprecated = false;
for (IAnnotationBinding annotation : method.getAnnotations()) {
String annot = annotation.getAnnotationType().getQualifiedName();
if (Constants.PROPERTY.equals(annot)) {
property = true;
} else if (Constants.DEPRECATED.equals(annot)) {
deprecated = true;
}
}
if (autobean || property) {
// add a property for this method
Property prop = bean.getProperty(name);
ITypeBinding returnType = method.getReturnType();
String typeName = new TypeResolver(returnType).resolve();
if (prop == null) {
prop = new Property(getVisibility(method.getModifiers()), method.getDeclaringClass().getQualifiedName(), typeName,
name);
bean.addProperty(prop);
} else {
prop.relaxVisibility(getVisibility(method.getModifiers()));
// prefer type of the getter
prop.setType(typeName);
}
prop.setDeprecated(deprecated);
prop.setGetterName(method.getName());
}
}
// discover property setters
for (IMethodBinding method : type.getDeclaredMethods()) {
String name = method.getName();
// we are only interested in setters
if (!(name.length() > 3 && name.startsWith("set") && Character.isUpperCase(name.charAt(3)))) {
continue;
}
if (method.getParameterTypes().length != 1) {
continue;
}
name = Character.toLowerCase(name.charAt(3)) + name.substring(4);
Property property = bean.getProperty(name);
if (property != null) {
String typeName = new TypeResolver(method.getParameterTypes()[0]).resolve();
if (typeName.equals(property.getType())) {
property.setSetterName(method.getName());
property.relaxVisibility(getVisibility(method.getModifiers()));
}
}
}
return true;