From 0f1cc39d9c17d3713657e84759151631a4bcdc48 Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Mon, 16 Jan 2012 12:45:49 +0100 Subject: [PATCH] METAGEN-78 Replacing @SupportedSourceVersion(RELEASE_6) with 'public SourceVersion getSupportedSourceVersion()' --- tooling/metamodel-generator/pom.xml | 70 +++++++++---------- .../JPAMetaModelEntityProcessor.java | 13 ++-- .../jpamodelgen/test/arraytype/ArrayTest.java | 2 - .../jpamodelgen/test/util/TestUtil.java | 26 +++++-- 4 files changed, 65 insertions(+), 46 deletions(-) diff --git a/tooling/metamodel-generator/pom.xml b/tooling/metamodel-generator/pom.xml index 51fbfcf53d..179eec7079 100644 --- a/tooling/metamodel-generator/pom.xml +++ b/tooling/metamodel-generator/pom.xml @@ -12,41 +12,6 @@ 2009 - - - org.hibernate.javax.persistence - hibernate-jpa-2.0-api - 1.0.0.Final - - - - - org.testng - testng - 5.8 - jdk15 - test - - - org.slf4j - slf4j-api - 1.5.6 - test - - - org.slf4j - slf4j-log4j12 - 1.5.6 - test - - - org.hibernate - hibernate-core - 3.6.0.Beta1 - test - - - Apache License, Version 2.0 @@ -99,6 +64,41 @@ http://in.relation.to/Bloggers/Max + + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + 1.0.0.Final + + + + + org.testng + testng + 5.8 + jdk15 + test + + + org.slf4j + slf4j-api + 1.5.6 + test + + + org.slf4j + slf4j-log4j12 + 1.5.6 + test + + + org.hibernate + hibernate-core + 3.6.0.Beta1 + test + + test diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java index 35c8e29ac0..ad94c02118 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java @@ -27,7 +27,7 @@ import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedOptions; -import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -51,8 +51,6 @@ import org.hibernate.jpamodelgen.util.StringUtil; import org.hibernate.jpamodelgen.util.TypeUtils; import org.hibernate.jpamodelgen.xml.XmlParser; -import static javax.lang.model.SourceVersion.RELEASE_6; - /** * Main annotation processor. * @@ -63,7 +61,6 @@ import static javax.lang.model.SourceVersion.RELEASE_6; @SupportedAnnotationTypes({ "javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable" }) -@SupportedSourceVersion(RELEASE_6) @SupportedOptions({ JPAMetaModelEntityProcessor.DEBUG_OPTION, JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION, @@ -84,6 +81,7 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor { private Context context; + @Override public void init(ProcessingEnvironment env) { super.init( env ); context = new Context( env ); @@ -107,10 +105,15 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor { } } + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + @Override public boolean process(final Set annotations, final RoundEnvironment roundEnvironment) { // see also METAGEN-45 - if ( roundEnvironment.processingOver() || annotations.size() == 0) { + if ( roundEnvironment.processingOver() || annotations.size() == 0 ) { return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS; } diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java index d468c73d7a..a4412437d1 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java @@ -14,8 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.hibernate.jpamodelgen.test.arraytype; import org.testng.annotations.Test; diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java index 70c5b5011c..929731c945 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java @@ -167,11 +167,11 @@ public class TestUtil { public static void assertAttributeTypeInMetaModelFor(Class clazz, String fieldName, Class expectedType, String errorString) { Field field = getFieldFromMetamodelFor( clazz, fieldName ); assertNotNull( field, "Cannot find field '" + fieldName + "' in " + clazz.getName() ); - ParameterizedType type = ( ParameterizedType ) field.getGenericType(); + ParameterizedType type = (ParameterizedType) field.getGenericType(); Type actualType = type.getActualTypeArguments()[1]; if ( expectedType.isArray() ) { expectedType = expectedType.getComponentType(); - actualType = ( ( GenericArrayType ) actualType ).getGenericComponentType(); + actualType = getComponentType( actualType ); } assertEquals( actualType, @@ -183,7 +183,7 @@ public class TestUtil { public static void assertMapAttributesInMetaModelFor(Class clazz, String fieldName, Class expectedMapKey, Class expectedMapValue, String errorString) { Field field = getFieldFromMetamodelFor( clazz, fieldName ); assertNotNull( field ); - ParameterizedType type = ( ParameterizedType ) field.getGenericType(); + ParameterizedType type = (ParameterizedType) field.getGenericType(); Type actualMapKeyType = type.getActualTypeArguments()[1]; assertEquals( actualMapKeyType, expectedMapKey, errorString ); @@ -191,7 +191,6 @@ public class TestUtil { assertEquals( actualMapKeyValue, expectedMapValue, errorString ); } - public static void assertSuperClassRelationShipInMetamodel(Class entityClass, Class superEntityClass) { String entityModelClassName = entityClass.getName() + META_MODEL_CLASS_POSTFIX; String superEntityModelClassName = superEntityClass.getName() + META_MODEL_CLASS_POSTFIX; @@ -238,6 +237,25 @@ public class TestUtil { return getFieldFromMetamodelFor( clazz, fieldName ) != null; } + private static Type getComponentType(Type actualType) { + if ( actualType instanceof Class ) { + Class clazz = (Class) actualType; + if ( clazz.isArray() ) { + return clazz.getComponentType(); + } + else { + fail("Unexpected component type"); + } + } + + if ( actualType instanceof GenericArrayType ) { + return ( (GenericArrayType) actualType ).getGenericComponentType(); + } else { + fail("Unexpected component type"); + return null; // making the compiler happy + } + } + private static class MetaModelFilenameFilter implements FileFilter { @Override public boolean accept(File pathName) {