ExtendedTypeFactory.visitDeclared throws IllegalArgumentException when generic type is an annotation type #153

Closed
eerichmond opened this Issue May 24, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@eerichmond

If an entity inherits from a generic object where T is NOT of type enum, class or interface it throws an IllegalArgumentException. I was wondering if we might be able to modify the com.mysema.query.apt.ExtendedTypeFactory class to allow annotations as a generic type T. The annotation is already a enum value in TypeElement but I'm not sure what would be involed in creating a "createAnnotationType()" method in ExtendedTypeFactory.

Thanks,
Eli

Below is an example of what I was trying to accomplish with the generic type. Unfortunately when I ran mvn generate-sources it threw an IllegalArgumentException.

@MappedSuperclass
public abstract class BaseObject<T extends Annotation> {
    private Class<T> getAnnotationType() {
        if (this.businessKeyType == null) {
            Type genericSuperclass = getClass().getGenericSuperclass();
            Class<?> superClass = getClass().getSuperclass();

            while(!superClass.equals(BaseObject.class)) {
                genericSuperclass = superClass.getGenericSuperclass();
                superClass = superClass.getSuperclass();
            }

            ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
            this.businessKeyType = (Class<T>) parameterizedType.getActualTypeArguments()[0];
        }

        return this.businessKeyType;
    }

    public boolean equals() {
         List<AccessibleObject> businessKeys = new ArrayList<AccessibleObject>();

        for (Field field : clazz.getDeclaredFields()) {
            T businessKey = field.getAnnotation(getAnnotationType());
            if (businessKey != null) {
                field.setAccessible(true);
                businessKeys.add(method);
            }
        }

        ...
    }
}

@Entity
public class Person extends BaseObject<javax.persistence.Id> {
    @Id
    private Long id;
    ...
}

@Embeddable
public class Address extends BaseObject<javax.persistence.EmbeddedId> {
    @EmbeddedId
    private String street;
    ....
}

timowest added a commit that referenced this issue May 24, 2012

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 25, 2012

Member

Released in 2.6.0

Member

timowest commented May 25, 2012

Released in 2.6.0

@timowest timowest closed this May 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment