diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java index b94d6d6438..2517781d13 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java @@ -135,6 +135,7 @@ public class MetadataBuildingProcess { // prep to start handling binding in earnest final MappingDefaultsImpl mappingDefaults = new MappingDefaultsImpl( options ); final JavaTypeDescriptorRepository javaTypeDescriptorRepository = new JavaTypeDescriptorRepositoryImpl( + jandexView, options.getTempClassLoader(), options.getServiceRegistry() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/ClassDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/ClassDescriptorImpl.java index 7b283a055f..b5355cf35b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/ClassDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/ClassDescriptorImpl.java @@ -24,6 +24,8 @@ package org.hibernate.metamodel.reflite.internal; import java.util.Collection; +import java.util.Collections; +import java.util.Map; import org.hibernate.metamodel.reflite.spi.ClassDescriptor; import org.hibernate.metamodel.reflite.spi.FieldDescriptor; @@ -31,6 +33,9 @@ import org.hibernate.metamodel.reflite.spi.InterfaceDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor; import org.hibernate.metamodel.reflite.spi.Name; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + /** * Implementation of a type descriptor * @@ -41,6 +46,7 @@ public class ClassDescriptorImpl implements ClassDescriptor { private final int modifiers; private final boolean hasDefaultConstructor; + private final Map annotationMap; private ClassDescriptor superType; private Collection interfaces; @@ -48,10 +54,17 @@ public class ClassDescriptorImpl implements ClassDescriptor { private Collection fieldDescriptors; private Collection methodDescriptors; - public ClassDescriptorImpl(Name name, int modifiers, boolean hasDefaultConstructor) { + public ClassDescriptorImpl( + Name name, + int modifiers, + boolean hasDefaultConstructor, + Map annotationMap) { this.name = name; this.modifiers = modifiers; this.hasDefaultConstructor = hasDefaultConstructor; + this.annotationMap = annotationMap != null + ? annotationMap + : Collections.emptyMap(); } @Override @@ -74,6 +87,11 @@ public class ClassDescriptorImpl implements ClassDescriptor { return interfaces; } + @Override + public Map getAnnotations() { + return annotationMap; + } + @Override public boolean hasDefaultConstructor() { return hasDefaultConstructor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/DotNameAdapter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/DotNameAdapter.java index dd6c31a113..e414f10d67 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/DotNameAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/DotNameAdapter.java @@ -63,6 +63,10 @@ class DotNameAdapter implements Name { return dotName.toString(); } + DotName jandexName() { + return dotName; + } + @Override public String toString() { return "DotNameAdapter{dotName=" + dotName.toString() + '}'; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/FieldDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/FieldDescriptorImpl.java index 2dae8ff1b0..d13c1d4e3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/FieldDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/FieldDescriptorImpl.java @@ -23,9 +23,15 @@ */ package org.hibernate.metamodel.reflite.internal; +import java.util.Collections; +import java.util.Map; + import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + /** * @author Steve Ebersole */ @@ -36,12 +42,21 @@ public class FieldDescriptorImpl implements FieldDescriptor { private final int modifiers; private final JavaTypeDescriptor declaringType; + private final Map annotationMap; - public FieldDescriptorImpl(String name, JavaTypeDescriptor fieldType, int modifiers, JavaTypeDescriptor declaringType) { + public FieldDescriptorImpl( + String name, + JavaTypeDescriptor fieldType, + int modifiers, + JavaTypeDescriptor declaringType, + Map annotationMap) { this.name = name; this.fieldType = fieldType; this.modifiers = modifiers; this.declaringType = declaringType; + this.annotationMap = annotationMap != null + ? annotationMap + : Collections.emptyMap(); } @Override @@ -64,6 +79,11 @@ public class FieldDescriptorImpl implements FieldDescriptor { return declaringType; } + @Override + public Map getAnnotations() { + return annotationMap; + } + @Override public String toString() { return "FieldDescriptorImpl{" + declaringType.getName().toString() + '#' + name + '}'; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/InterfaceDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/InterfaceDescriptorImpl.java index 6dfd94d701..c20b4a0329 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/InterfaceDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/InterfaceDescriptorImpl.java @@ -24,27 +24,39 @@ package org.hibernate.metamodel.reflite.internal; import java.util.Collection; +import java.util.Collections; +import java.util.Map; import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.InterfaceDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor; import org.hibernate.metamodel.reflite.spi.Name; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + /** * @author Steve Ebersole */ public class InterfaceDescriptorImpl implements InterfaceDescriptor { private final Name name; private final int modifiers; + private final Map annotationMap; private Collection extendedInterfaceTypes; - private Collection declaredFields; - private Collection declaredMethods; + private Collection fields; + private Collection methods; - public InterfaceDescriptorImpl(Name name, int modifiers) { + public InterfaceDescriptorImpl( + Name name, + int modifiers, + Map annotationMap) { this.name = name; this.modifiers = modifiers; + this.annotationMap = annotationMap != null + ? annotationMap + : Collections.emptyMap(); } @Override @@ -62,14 +74,19 @@ public class InterfaceDescriptorImpl implements InterfaceDescriptor { return extendedInterfaceTypes; } + @Override + public Map getAnnotations() { + return annotationMap; + } + @Override public Collection getDeclaredFields() { - return declaredFields; + return fields; } @Override public Collection getDeclaredMethods() { - return declaredMethods; + return methods; } @Override @@ -81,11 +98,11 @@ public class InterfaceDescriptorImpl implements InterfaceDescriptor { this.extendedInterfaceTypes = extendedInterfaceTypes; } - void setDeclaredFields(Collection declaredFields) { - this.declaredFields = declaredFields; + void setFields(Collection fields) { + this.fields = fields; } - void setDeclaredMethods(Collection declaredMethods) { - this.declaredMethods = declaredMethods; + void setMethods(Collection methods) { + this.methods = methods; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/JavaTypeDescriptorRepositoryImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/JavaTypeDescriptorRepositoryImpl.java index f2701e043c..3cc191c757 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/JavaTypeDescriptorRepositoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/JavaTypeDescriptorRepositoryImpl.java @@ -31,7 +31,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.internal.util.collections.CollectionHelper; @@ -45,6 +44,13 @@ import org.hibernate.metamodel.reflite.spi.Name; import org.hibernate.metamodel.reflite.spi.VoidDescriptor; import org.hibernate.service.ServiceRegistry; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.FieldInfo; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.MethodInfo; +import org.jboss.jandex.MethodParameterInfo; import org.jboss.logging.Logger; /** @@ -59,14 +65,22 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos private ClassLoader jpaTempClassLoader; private final ClassLoaderService classLoaderService; + private final IndexView jandexIndex; private Map typeDescriptorMap = new HashMap(); - public JavaTypeDescriptorRepositoryImpl(ClassLoader jpaTempClassLoader, ServiceRegistry serviceRegistry) { - this( jpaTempClassLoader, serviceRegistry.getService( ClassLoaderService.class ) ); + public JavaTypeDescriptorRepositoryImpl( + IndexView jandexIndex, + ClassLoader jpaTempClassLoader, + ServiceRegistry serviceRegistry) { + this( jandexIndex, jpaTempClassLoader, serviceRegistry.getService( ClassLoaderService.class ) ); } - public JavaTypeDescriptorRepositoryImpl(ClassLoader jpaTempClassLoader, ClassLoaderService classLoaderService) { + public JavaTypeDescriptorRepositoryImpl( + IndexView jandexIndex, + ClassLoader jpaTempClassLoader, + ClassLoaderService classLoaderService) { + this.jandexIndex = jandexIndex; this.jpaTempClassLoader = jpaTempClassLoader; this.classLoaderService = classLoaderService; } @@ -76,27 +90,6 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos return new DotNameAdapter( name ); } - private JavaTypeDescriptor arrayOfType(Class type) { - if ( type.isArray() ) { - return new ArrayDescriptorImpl( - buildName( "[" + type.getName() ), - type.getModifiers(), - arrayOfType( type.getComponentType() ) - ); - } - - if ( type.isPrimitive() ) { - return Primitives.primitiveArrayDescriptor( type ); - } - else { - return new ArrayDescriptorImpl( - buildName( "[" + type.getName() ), - type.getModifiers(), - getType( buildName( type.getName() ) ) - ); - } - } - @Override public JavaTypeDescriptor getType(Name typeName) { if ( typeName == null ) { @@ -164,22 +157,27 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos private boolean isSafeClass(Name className) { final String classNameString = className.fullName(); + // classes in any of these packages are safe to load through the "live" ClassLoader return classNameString.startsWith( "java." ) || classNameString.startsWith( "javax." ) || classNameString.startsWith( "org.hibernate" ); } - - private JavaTypeDescriptor makeTypeDescriptor(Name typeName, Class clazz) { + final JandexPivot jandexPivot = pivotAnnotations( toJandexName( typeName ) ); + if ( clazz.isInterface() ) { - final InterfaceDescriptorImpl typeDescriptor = new InterfaceDescriptorImpl( typeName, clazz.getModifiers() ); + final InterfaceDescriptorImpl typeDescriptor = new InterfaceDescriptorImpl( + typeName, + clazz.getModifiers(), + jandexPivot.typeAnnotations + ); typeDescriptorMap.put( typeName, typeDescriptor ); - typeDescriptor.setExtendedInterfaceTypes( fromInterfaces( clazz ) ); - typeDescriptor.setDeclaredFields( fromFields( clazz, typeDescriptor ) ); - typeDescriptor.setDeclaredMethods( fromMethods( clazz, typeDescriptor ) ); + typeDescriptor.setExtendedInterfaceTypes( extractInterfaces( clazz ) ); + typeDescriptor.setFields( extractFields( clazz, typeDescriptor, jandexPivot ) ); + typeDescriptor.setMethods( extractMethods( clazz, typeDescriptor, jandexPivot ) ); return typeDescriptor; } @@ -187,20 +185,127 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos final ClassDescriptorImpl typeDescriptor = new ClassDescriptorImpl( typeName, clazz.getModifiers(), - hasDefaultCtor( clazz ) + hasDefaultCtor( clazz ), + jandexPivot.typeAnnotations ); typeDescriptorMap.put( typeName, typeDescriptor ); - typeDescriptor.setSuperType( fromSuper( clazz ) ); - typeDescriptor.setInterfaces( fromInterfaces( clazz ) ); - typeDescriptor.setFields( fromFields( clazz, typeDescriptor ) ); - typeDescriptor.setMethods( fromMethods( clazz, typeDescriptor ) ); + typeDescriptor.setSuperType( extractSuper( clazz ) ); + typeDescriptor.setInterfaces( extractInterfaces( clazz ) ); + typeDescriptor.setFields( extractFields( clazz, typeDescriptor, jandexPivot ) ); + typeDescriptor.setMethods( extractMethods( clazz, typeDescriptor, jandexPivot ) ); return typeDescriptor; } } - private ClassDescriptor fromSuper(Class clazz) { + private DotName toJandexName(Name typeName) { + if ( DotNameAdapter.class.isInstance( typeName ) ) { + return ( (DotNameAdapter) typeName ).jandexName(); + } + else { + return DotName.createSimple( typeName.fullName() ); + } + } + + private static final JandexPivot NO_JANDEX_PIVOT = new JandexPivot(); + + private JandexPivot pivotAnnotations(DotName typeName) { + if ( jandexIndex == null ) { + return NO_JANDEX_PIVOT; + } + + final ClassInfo jandexClassInfo = jandexIndex.getClassByName( typeName ); + if ( jandexClassInfo == null ) { + return NO_JANDEX_PIVOT; + } + + final Map> annotations = jandexClassInfo.annotations(); + final JandexPivot pivot = new JandexPivot(); + for ( Map.Entry> annotationInstances : annotations.entrySet() ) { + for ( AnnotationInstance annotationInstance : annotationInstances.getValue() ) { + if ( MethodParameterInfo.class.isInstance( annotationInstance.target() ) ) { + continue; + } + + if ( FieldInfo.class.isInstance( annotationInstance.target() ) ) { + final FieldInfo fieldInfo = (FieldInfo) annotationInstance.target(); + Map fieldAnnotations = pivot.fieldAnnotations.get( fieldInfo.name() ); + if ( fieldAnnotations == null ) { + fieldAnnotations = new HashMap(); + pivot.fieldAnnotations.put( fieldInfo.name(), fieldAnnotations ); + fieldAnnotations.put( annotationInstance.name(), annotationInstance ); + } + else { + final Object oldEntry = fieldAnnotations.put( annotationInstance.name(), annotationInstance ); + if ( oldEntry != null ) { + log.debugf( + "Encountered duplicate annotation [%s] on field [%s]", + annotationInstance.name(), + fieldInfo.name() + ); + } + } + } + else if ( MethodInfo.class.isInstance( annotationInstance.target() ) ) { + final MethodInfo methodInfo = (MethodInfo) annotationInstance.target(); + final String methodKey = buildBuildKey( methodInfo ); + Map methodAnnotations = pivot.methodAnnotations.get( methodKey ); + if ( methodAnnotations == null ) { + methodAnnotations = new HashMap(); + pivot.methodAnnotations.put( methodKey, methodAnnotations ); + methodAnnotations.put( annotationInstance.name(), annotationInstance ); + } + else { + final Object oldEntry = methodAnnotations.put( annotationInstance.name(), annotationInstance ); + if ( oldEntry != null ) { + log.debugf( + "Encountered duplicate annotation [%s] on method [%s -> %s]", + annotationInstance.name(), + jandexClassInfo.name(), + methodKey + ); + } + } + } + else if ( ClassInfo.class.isInstance( annotationInstance.target() ) ) { + // todo : validate its the type we are processing? + final Object oldEntry = pivot.typeAnnotations.put( annotationInstance.name(), annotationInstance ); + if ( oldEntry != null ) { + log.debugf( + "Encountered duplicate annotation [%s] on type [%s]", + annotationInstance.name(), + jandexClassInfo.name() + ); + } + } + } + } + + return pivot; + } + + private String buildBuildKey(MethodInfo methodInfo) { + final StringBuilder buff = new StringBuilder(); + buff.append( methodInfo.returnType().toString() ) + .append( ' ' ) + .append( methodInfo.name() ) + .append( '(' ); + for ( int i = 0; i < methodInfo.args().length; i++ ) { + if ( i > 0 ) { + buff.append( ',' ); + } + buff.append( methodInfo.args()[i].toString() ); + } + + return buff.append( ')' ).toString(); + } + + private Collection getAnnotations(DotName dotName) { + return jandexIndex.getAnnotations( dotName ); + } + + private ClassDescriptor extractSuper(Class clazz) { final Class superclass = clazz.getSuperclass(); if ( superclass == null ) { return null; @@ -209,7 +314,7 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos return (ClassDescriptor) getType( buildName( superclass.getName() ) ); } - private Collection fromInterfaces(Class clazz) { + private Collection extractInterfaces(Class clazz) { final Class[] interfaces = clazz.getInterfaces(); if ( interfaces == null || interfaces.length <= 0 ) { return Collections.emptyList(); @@ -222,21 +327,44 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos return interfaceTypes; } - private Collection fromFields(Class clazz, JavaTypeDescriptor declaringType) { - final Field[] fields = clazz.getDeclaredFields(); - if ( fields == null || fields.length <= 0 ) { + private Collection extractFields( + Class clazz, + JavaTypeDescriptor declaringType, + JandexPivot jandexPivot) { + final Field[] declaredFields = clazz.getDeclaredFields(); + final Field[] fields = clazz.getFields(); + + if ( declaredFields.length <= 0 && fields.length <= 0 ) { return Collections.emptyList(); } final List fieldDescriptors = CollectionHelper.arrayList( fields.length ); - for ( Field field : fields ) { - final Class fieldType = field.getType(); + + for ( Field field : declaredFields ) { fieldDescriptors.add( new FieldDescriptorImpl( field.getName(), - toTypeDescriptor( fieldType ), + toTypeDescriptor( field.getType() ), field.getModifiers(), - declaringType + declaringType, + jandexPivot.fieldAnnotations.get( field.getName() ) + ) + ); + } + + for ( Field field : fields ) { + if ( clazz.equals( field.getDeclaringClass() ) ) { + continue; + } + + final JavaTypeDescriptor fieldDeclarer = getType( buildName( field.getDeclaringClass().getName() ) ); + fieldDescriptors.add( + new FieldDescriptorImpl( + field.getName(), + toTypeDescriptor( field.getType() ), + field.getModifiers(), + fieldDeclarer, + jandexPivot.fieldAnnotations.get( field.getName() ) ) ); } @@ -254,38 +382,96 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos return fieldTypeDescriptor; } - private Collection fromMethods(Class clazz, JavaTypeDescriptor declaringType) { - final Method[] methods = clazz.getDeclaredMethods(); - if ( methods == null || methods.length <= 0 ) { + private JavaTypeDescriptor arrayOfType(Class type) { + if ( type.isArray() ) { + return new ArrayDescriptorImpl( + buildName( "[" + type.getName() ), + type.getModifiers(), + arrayOfType( type.getComponentType() ) + ); + } + + if ( type.isPrimitive() ) { + return Primitives.primitiveArrayDescriptor( type ); + } + else { + return new ArrayDescriptorImpl( + buildName( "[" + type.getName() ), + type.getModifiers(), + getType( buildName( type.getName() ) ) + ); + } + } + + private Collection extractMethods( + Class clazz, + JavaTypeDescriptor declaringType, + JandexPivot jandexPivot) { + final Method[] declaredMethods = clazz.getDeclaredMethods(); + final Method[] methods = clazz.getMethods(); + + if ( declaredMethods.length <= 0 && methods.length <= 0 ) { return Collections.emptyList(); } final List methodDescriptors = CollectionHelper.arrayList( methods.length ); - for ( Method method : methods ) { - final Class[] parameterTypes = method.getParameterTypes(); - final Collection argumentTypes; - if ( parameterTypes.length == 0 ) { - argumentTypes = Collections.emptyList(); - } - else { - argumentTypes = CollectionHelper.arrayList( parameterTypes.length ); - for ( Class parameterType : parameterTypes ) { - argumentTypes.add( toTypeDescriptor( parameterType ) ); - } - } - methodDescriptors.add( - new MethodDescriptorImpl( - method.getName(), - declaringType, - method.getModifiers(), - toTypeDescriptor( method.getReturnType() ), - argumentTypes - ) - ); + + for ( Method method : declaredMethods ) { + methodDescriptors.add( fromMethod( method, declaringType, jandexPivot ) ); } + + for ( Method method : methods ) { + if ( clazz.equals( method.getDeclaringClass() ) ) { + continue; + } + + final JavaTypeDescriptor methodDeclarer = getType( buildName( method.getDeclaringClass().getName() ) ); + methodDescriptors.add( fromMethod( method, methodDeclarer, jandexPivot ) ); + } + return methodDescriptors; } + private MethodDescriptor fromMethod( + Method method, + JavaTypeDescriptor declaringType, + JandexPivot jandexPivot) { + final Class[] parameterTypes = method.getParameterTypes(); + final Collection argumentTypes; + if ( parameterTypes.length == 0 ) { + argumentTypes = Collections.emptyList(); + } + else { + argumentTypes = CollectionHelper.arrayList( parameterTypes.length ); + for ( Class parameterType : parameterTypes ) { + argumentTypes.add( toTypeDescriptor( parameterType ) ); + } + } + + return new MethodDescriptorImpl( + method.getName(), + declaringType, + method.getModifiers(), + toTypeDescriptor( method.getReturnType() ), + argumentTypes, + jandexPivot.methodAnnotations.get( buildMethodAnnotationsKey( method ) ) + ); + } + + private String buildMethodAnnotationsKey(Method method) { + StringBuilder buff = new StringBuilder(); + buff.append( method.getReturnType().getName() ) + .append( method.getName() ) + .append( '(' ); + for ( int i = 0; i < method.getParameterTypes().length; i++ ) { + if ( i > 0 ) { + buff.append( ',' ); + } + buff.append( method.getParameterTypes()[i].getName() ); + } + return buff.append( ')' ).toString(); + } + @SuppressWarnings("unchecked") private static boolean hasDefaultCtor(Class clazz) { @@ -297,16 +483,6 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos } } - public static void main(String... args) { - JavaTypeDescriptorRepositoryImpl repo = new JavaTypeDescriptorRepositoryImpl( - JavaTypeDescriptorRepositoryImpl.class.getClassLoader(), - new BootstrapServiceRegistryBuilder().build() - ); - - JavaTypeDescriptor td = repo.getType( repo.buildName( JavaTypeDescriptorRepositoryImpl.class.getName() ) ); - assert ClassDescriptorImpl.class.isInstance( td ); - } - private static class NoSuchClassTypeDescriptor implements JavaTypeDescriptor { private final Name name; @@ -334,4 +510,14 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos return Collections.emptyList(); } } + + private static class JandexPivot { + private Map typeAnnotations + = new HashMap(); + private Map> fieldAnnotations + = new HashMap>(); + private Map> methodAnnotations + = new HashMap>(); + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/MethodDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/MethodDescriptorImpl.java index b08d398e6f..a6beb26aa3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/MethodDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/MethodDescriptorImpl.java @@ -24,10 +24,15 @@ package org.hibernate.metamodel.reflite.internal; import java.util.Collection; +import java.util.Collections; +import java.util.Map; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + /** * @author Steve Ebersole */ @@ -37,18 +42,23 @@ public class MethodDescriptorImpl implements MethodDescriptor { private final int modifiers; private final JavaTypeDescriptor returnType; private final Collection parameterTypes; + private final Map annotationMap; public MethodDescriptorImpl( String name, JavaTypeDescriptor declaringType, int modifiers, JavaTypeDescriptor returnType, - Collection parameterTypes) { + Collection parameterTypes, + Map annotationMap) { this.name = name; this.declaringType = declaringType; this.modifiers = modifiers; this.returnType = returnType; this.parameterTypes = parameterTypes; + this.annotationMap = annotationMap != null + ? annotationMap + : Collections.emptyMap(); } @Override @@ -76,6 +86,11 @@ public class MethodDescriptorImpl implements MethodDescriptor { return parameterTypes; } + @Override + public Map getAnnotations() { + return annotationMap; + } + @Override public String toString() { return "MethodDescriptorImpl{" + declaringType.getName().toString() + '#' + name + '}'; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/ClassDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/ClassDescriptor.java index 0755ee408b..3adc868a0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/ClassDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/ClassDescriptor.java @@ -24,6 +24,10 @@ package org.hibernate.metamodel.reflite.spi; import java.util.Collection; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; /** * Describes a java type that represents a class definition. @@ -51,4 +55,11 @@ public interface ClassDescriptor extends JavaTypeDescriptor { * @return The implemented interfaces */ public Collection getInterfaceTypes(); + + /** + * Get the annotations defined on this type. + * + * @return The annotations. + */ + public Map getAnnotations(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/FieldDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/FieldDescriptor.java index 8069c54ca3..3ac01f4c90 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/FieldDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/FieldDescriptor.java @@ -23,6 +23,11 @@ */ package org.hibernate.metamodel.reflite.spi; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + /** * Describes a field in a java type * @@ -51,4 +56,11 @@ public interface FieldDescriptor { * @return */ public JavaTypeDescriptor getDeclaringType(); + + /** + * Get the annotations defined on this field. + * + * @return The annotations. + */ + public Map getAnnotations(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/InterfaceDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/InterfaceDescriptor.java index 74760f45bc..2d14145652 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/InterfaceDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/InterfaceDescriptor.java @@ -24,6 +24,10 @@ package org.hibernate.metamodel.reflite.spi; import java.util.Collection; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; /** * Describes a java type that represents an interface definition. @@ -37,4 +41,11 @@ public interface InterfaceDescriptor extends JavaTypeDescriptor { * @return The implemented interfaces */ public Collection getExtendedInterfaceTypes(); + + /** + * Get the annotations defined on this type. + * + * @return The annotations. + */ + public Map getAnnotations(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/MethodDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/MethodDescriptor.java index 571c4d6708..426ce2bd39 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/MethodDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/MethodDescriptor.java @@ -24,6 +24,10 @@ package org.hibernate.metamodel.reflite.spi; import java.util.Collection; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; /** * Describes a method in a java type @@ -65,4 +69,12 @@ public interface MethodDescriptor { * @return The descriptor of the method's argument types */ public Collection getParameterTypes(); + + /** + * Get the annotations defined on this method. + * + * @return The annotations. + */ + public Map getAnnotations(); + } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/RootBindingContextBuilder.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/RootBindingContextBuilder.java index c2bd653879..20bb7b253d 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/RootBindingContextBuilder.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/RootBindingContextBuilder.java @@ -44,7 +44,11 @@ public class RootBindingContextBuilder { final MetadataBuildingProcess.MappingDefaultsImpl mappingDefaults = new MetadataBuildingProcess.MappingDefaultsImpl( options ); - final JavaTypeDescriptorRepository javaTypeDescriptorRepository = new JavaTypeDescriptorRepositoryImpl( null, serviceRegistry ); + final JavaTypeDescriptorRepository javaTypeDescriptorRepository = new JavaTypeDescriptorRepositoryImpl( + null, + null, + serviceRegistry + ); final MetadataBuildingProcess.InFlightMetadataCollectorImpl metadataCollector = new MetadataBuildingProcess.InFlightMetadataCollectorImpl( options, new TypeResolver( basicTypeRegistry, new TypeFactory() ) diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java index 47cda55306..e329c9ac6c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java @@ -109,6 +109,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { } private final JavaTypeDescriptorRepository javaTypeDescriptorRepository = new JavaTypeDescriptorRepositoryImpl( + null, null, classLoaderService ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java b/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java index f9c854c57a..e8f8ea4bfa 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java @@ -162,7 +162,6 @@ public class StatsTest extends BaseUnitTestCase { // } @Test - @FailureExpectedWithNewMetamodel( jiraKey = "HHH-8962" ) public void testQueryStatGathering() { SessionFactory sf = buildBaseConfiguration() .setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" )