METAGEN-29 adding handling of type variables in AnnotationMetaEntity
This commit is contained in:
parent
521b477e8e
commit
402d21cd44
|
@ -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>
|
||||
|
||||
|
@ -89,6 +91,27 @@
|
|||
</resources>
|
||||
|
||||
<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>
|
||||
<groupId>org.jboss.maven.plugins</groupId>
|
||||
<artifactId>maven-injection-plugin</artifactId>
|
||||
|
@ -243,7 +266,9 @@
|
|||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
|
||||
<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>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -35,6 +35,7 @@ import javax.lang.model.type.ExecutableType;
|
|||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVariable;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
import javax.persistence.AccessType;
|
||||
|
@ -215,6 +216,15 @@ public class AnnotationMetaEntity implements MetaEntity {
|
|||
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
|
||||
public AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
|
||||
TypeElement returnedElement = ( TypeElement ) context.getTypeUtils().asElement( declaredType );
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
|
@ -21,6 +21,8 @@ import org.testng.annotations.Test;
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -29,14 +31,22 @@ import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClassRelat
|
|||
*/
|
||||
public class InheritanceTest extends CompilationTest {
|
||||
@Test
|
||||
public void testSuperEntity() throws Exception {
|
||||
assertSuperClassRelationShipInMetamodel( Customer.class, User.class );
|
||||
}
|
||||
public void testInheritance() throws Exception {
|
||||
|
||||
@Test
|
||||
public void testMappedSuperclass() throws Exception {
|
||||
// entity inheritance
|
||||
assertSuperClassRelationShipInMetamodel( Customer.class, User.class );
|
||||
|
||||
|
||||
// mapped super class
|
||||
assertSuperClassRelationShipInMetamodel( House.class, Building.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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue