METAGEN-29 adding handling of type variables in AnnotationMetaEntity

This commit is contained in:
Hardy Ferentschik 2010-05-12 17:17:45 +00:00 committed by Strong Liu
parent 521b477e8e
commit 402d21cd44
6 changed files with 129 additions and 9 deletions

View File

@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -89,6 +91,27 @@
</resources> </resources>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireJavaVersion>
<!-- require JDK 1.6 to run the build -->
<version>[1.6,)</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.jboss.maven.plugins</groupId> <groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId> <artifactId>maven-injection-plugin</artifactId>
@ -243,7 +266,9 @@
<autoVersionSubmodules>true</autoVersionSubmodules> <autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots> <allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<remoteTagging>true</remoteTagging> <remoteTagging>true</remoteTagging>
<goals>package deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:resources org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:generate assembly:assembly</goals> <goals>package deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:resources
org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:generate assembly:assembly
</goals>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -35,6 +35,7 @@ import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
import javax.persistence.AccessType; import javax.persistence.AccessType;
@ -215,6 +216,15 @@ public class AnnotationMetaEntity implements MetaEntity {
return new AnnotationMetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) ); return new AnnotationMetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) );
} }
public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) {
// METAGEN-29 - for a type variable we use the upper bound
TypeMirror mirror = t.getUpperBound();
TypeMirror erasedType = context.getTypeUtils().erasure( mirror );
return new AnnotationMetaSingleAttribute(
parent, element, erasedType.toString()
);
}
@Override @Override
public AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) { public AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
TypeElement returnedElement = ( TypeElement ) context.getTypeUtils().asElement( declaredType ); TypeElement returnedElement = ( TypeElement ) context.getTypeUtils().asElement( declaredType );

View File

@ -206,7 +206,7 @@ public class TypeUtils {
if ( accessTypeInfo != null && accessTypeInfo.isAccessTypeResolved() ) { if ( accessTypeInfo != null && accessTypeInfo.isAccessTypeResolved() ) {
context.logMessage( context.logMessage(
Diagnostic.Kind.OTHER, Diagnostic.Kind.OTHER,
"AccessType for " + searchedElement.toString() + "found in cache: " + accessTypeInfo "AccessType for " + searchedElement.toString() + " found in cache: " + accessTypeInfo
); );
return; return;
} }

View File

@ -0,0 +1,35 @@
// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.jpamodelgen.test.inheritance;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class AbstractEntity<T> {
@Id
@GeneratedValue
private Long id;
private T foo;
public AbstractEntity() {
}
}

View File

@ -21,6 +21,8 @@ import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest; import org.hibernate.jpamodelgen.test.util.CompilationTest;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClassRelationShipInMetamodel; import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClassRelationShipInMetamodel;
/** /**
@ -29,14 +31,22 @@ import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClassRelat
*/ */
public class InheritanceTest extends CompilationTest { public class InheritanceTest extends CompilationTest {
@Test @Test
public void testSuperEntity() throws Exception { public void testInheritance() throws Exception {
assertSuperClassRelationShipInMetamodel( Customer.class, User.class );
}
@Test // entity inheritance
public void testMappedSuperclass() throws Exception { assertSuperClassRelationShipInMetamodel( Customer.class, User.class );
// mapped super class
assertSuperClassRelationShipInMetamodel( House.class, Building.class ); assertSuperClassRelationShipInMetamodel( House.class, Building.class );
assertSuperClassRelationShipInMetamodel( Building.class, Area.class ); assertSuperClassRelationShipInMetamodel( Building.class, Area.class );
// METAGEN-29
assertSuperClassRelationShipInMetamodel( Person.class, AbstractEntity.class );
assertPresenceOfFieldInMetamodelFor( AbstractEntity.class, "foo", "Property should exist - METAGEN-29" );
assertAttributeTypeInMetaModelFor(
AbstractEntity.class, "foo", Object.class, "Object is the upper bound of foo "
);
} }
@Override @Override

View File

@ -0,0 +1,40 @@
// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.jpamodelgen.test.inheritance;
import javax.persistence.Entity;
/**
* @author Hardy Ferentschik
*/
@Entity
public class Person extends AbstractEntity<String> {
private String name;
protected Person() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}