Search in sources :

Example 1 with PropertyGroup

use of org.jkiss.dbeaver.model.meta.PropertyGroup in project dbeaver by serge-rider.

the class ObjectAttributeDescriptor method extractAnnotations.

static void extractAnnotations(DBPPropertySource source, ObjectPropertyGroupDescriptor parent, Class<?> theClass, List<ObjectPropertyDescriptor> annoProps, IPropertyFilter filter) {
    Method[] methods = theClass.getMethods();
    Map<String, Method> passedNames = new HashMap<>();
    for (Method method : methods) {
        String methodFullName = method.getDeclaringClass().getName() + "." + method.getName();
        final Method prevMethod = passedNames.get(methodFullName);
        if (prevMethod != null) {
            // The same method but probably with another return type
            final Class<?> prevReturnType = prevMethod.getReturnType();
            final Class<?> newReturnType = method.getReturnType();
            if (newReturnType == null || prevReturnType == null || newReturnType == prevReturnType || !prevReturnType.isAssignableFrom(newReturnType)) {
                continue;
            }
        // Let it another chance. New return types seems to be subclass of previous
        }
        final PropertyGroup propGroupInfo = method.getAnnotation(PropertyGroup.class);
        if (propGroupInfo != null && method.getReturnType() != null) {
            // Property group
            ObjectPropertyGroupDescriptor groupDescriptor = new ObjectPropertyGroupDescriptor(source, parent, method, propGroupInfo, filter);
            annoProps.addAll(groupDescriptor.getChildren());
        } else {
            final Property propInfo = method.getAnnotation(Property.class);
            if (propInfo == null || !BeanUtils.isGetterName(method.getName()) || method.getReturnType() == null) {
                continue;
            }
            // Single property
            ObjectPropertyDescriptor desc = new ObjectPropertyDescriptor(source, parent, propInfo, method);
            if (filter != null && !filter.select(desc)) {
                continue;
            }
            if (prevMethod != null) {
                // Remove previous anno
                for (Iterator<ObjectPropertyDescriptor> iter = annoProps.iterator(); iter.hasNext(); ) {
                    if (iter.next().getId().equals(desc.getId())) {
                        iter.remove();
                    }
                }
            }
            annoProps.add(desc);
            passedNames.put(methodFullName, method);
        }
    }
    Collections.sort(annoProps, ATTRIBUTE_DESCRIPTOR_COMPARATOR);
}
Also used : PropertyGroup(org.jkiss.dbeaver.model.meta.PropertyGroup) Method(java.lang.reflect.Method) Property(org.jkiss.dbeaver.model.meta.Property) LazyProperty(org.jkiss.dbeaver.model.meta.LazyProperty)

Aggregations

Method (java.lang.reflect.Method)1 LazyProperty (org.jkiss.dbeaver.model.meta.LazyProperty)1 Property (org.jkiss.dbeaver.model.meta.Property)1 PropertyGroup (org.jkiss.dbeaver.model.meta.PropertyGroup)1