[hibernate-commits] Hibernate SVN: r20724 - jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/util.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Sep 27 13:30:21 EDT 2010


Author: hardy.ferentschik
Date: 2010-09-27 13:30:20 -0400 (Mon, 27 Sep 2010)
New Revision: 20724

Modified:
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java
Log:
METAGEN-30 Added a version of isAnnotationMirrorOfType which takes as parameter a fqcn instaead of a class. When using @Target we cannot reference the class itself

Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java	2010-09-27 17:29:03 UTC (rev 20723)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java	2010-09-27 17:30:20 UTC (rev 20724)
@@ -79,14 +79,17 @@
 
 	}
 
-	static public String toTypeString(TypeMirror type) {
+	private TypeUtils() {
+	}
+
+	public static String toTypeString(TypeMirror type) {
 		if ( type.getKind().isPrimitive() ) {
 			return PRIMITIVES.get( type.toString() );
 		}
 		return type.toString();
 	}
 
-	static public TypeElement getSuperclassTypeElement(TypeElement element) {
+	public static TypeElement getSuperclassTypeElement(TypeElement element) {
 		final TypeMirror superClass = element.getSuperclass();
 		//superclass of Object is of NoType which returns some other kind
 		if ( superClass.getKind() == TypeKind.DECLARED ) {
@@ -140,17 +143,30 @@
 	 * This method uses the string class names for comparison. See also {@link http://www.retep.org/2009/02/getting-class-values-from-annotations.html}.
 	 *
 	 * @param annotationMirror The annotation mirror
-	 * @param clazz the class name to check again
+	 * @param clazz the class name to check against
 	 *
 	 * @return {@code true} if the provided annotation type is of the same type as the provided class, {@code false} otherwise.
 	 */
 	public static boolean isAnnotationMirrorOfType(AnnotationMirror annotationMirror, Class<? extends Annotation> clazz) {
+		assert clazz != null;
+		return isAnnotationMirrorOfType( annotationMirror, clazz.getName() );
+	}
+
+	/**
+	 * Returns {@code true} if the provided annotation type is of the same type as the provided class, {@code false} otherwise.
+	 * This method uses the string class names for comparison. See also {@link http://www.retep.org/2009/02/getting-class-values-from-annotations.html}.
+	 *
+	 * @param annotationMirror The annotation mirror
+	 * @param fqcn the fully qualified class name to check against
+	 *
+	 * @return {@code true} if the provided annotation type is of the same type as the provided class, {@code false} otherwise.
+	 */
+	public static boolean isAnnotationMirrorOfType(AnnotationMirror annotationMirror, String fqcn) {
 		assert annotationMirror != null;
-		assert clazz != null;
+		assert fqcn != null;
 		String annotationClassName = annotationMirror.getAnnotationType().toString();
-		String className = clazz.getName();
 
-		return annotationClassName.equals( className );
+		return annotationClassName.equals( fqcn );
 	}
 
 	public static boolean isTypeElementOfType(TypeElement element, Class<?> clazz) {



More information about the hibernate-commits mailing list