METAGEN-52 Removing remaining compile time dependency for javax.persistence classes

This commit is contained in:
Hardy Ferentschik 2012-01-17 14:42:12 +01:00 committed by Strong Liu
parent 214e357d13
commit bd37d376aa
10 changed files with 91 additions and 84 deletions

View File

@ -25,11 +25,11 @@
</issueManagement>
<scm>
<connection>scm:git:git://github.com/hibernate/hibernate-metamodelgen.git</connection>
<developerConnection>scm:git:git@github.com:hibernate/hibernate-metamodelgen.git</developerConnection>
<connection>scm:git:git://github.com/hibernate/hibernate-metamodelgen.git</connection>
<developerConnection>scm:git:git@github.com:hibernate/hibernate-metamodelgen.git</developerConnection>
<url>http://github.com/hibernate/hibernate-metamodelgen</url>
</scm>
<distributionManagement>
<repository>
<id>jboss-releases-repository</id>
@ -64,15 +64,8 @@
<url>http://in.relation.to/Bloggers/Max</url>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!-- test dependencies -->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
@ -80,6 +73,12 @@
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -98,7 +97,7 @@
<version>3.6.0.Beta1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>

View File

@ -26,10 +26,11 @@ import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.persistence.AccessType;
import javax.tools.Diagnostic;
import org.hibernate.jpamodelgen.model.MetaEntity;
import org.hibernate.jpamodelgen.util.AccessType;
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
import org.hibernate.jpamodelgen.util.Constants;
/**

View File

@ -27,14 +27,14 @@ import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.persistence.AccessType;
import org.hibernate.jpamodelgen.AccessTypeInformation;
import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.ImportContextImpl;
import org.hibernate.jpamodelgen.model.ImportContext;
import org.hibernate.jpamodelgen.model.MetaAttribute;
import org.hibernate.jpamodelgen.model.MetaEntity;
import org.hibernate.jpamodelgen.util.AccessType;
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
import org.hibernate.jpamodelgen.util.Constants;
import org.hibernate.jpamodelgen.util.TypeUtils;
@ -104,6 +104,26 @@ public class AnnotationMetaEntity implements MetaEntity {
}
}
public final String generateImports() {
return importContext.generateImports();
}
public final String importType(String fqcn) {
return importContext.importType( fqcn );
}
public final String staticImport(String fqcn, String member) {
return importContext.staticImport( fqcn, member );
}
public final String importType(Name qualifiedName) {
return importType( qualifiedName.toString() );
}
public final TypeElement getTypeElement() {
return element;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
@ -118,6 +138,17 @@ public class AnnotationMetaEntity implements MetaEntity {
return element;
}
protected final void init() {
TypeUtils.determineAccessTypeForHierarchy( element, context );
entityAccessTypeInfo = context.getAccessTypeInfo( getQualifiedName() );
List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
addPersistentMembers( fieldsOfClass, AccessType.FIELD );
List<? extends Element> methodsOfClass = ElementFilter.methodsIn( element.getEnclosedElements() );
addPersistentMembers( methodsOfClass, AccessType.PROPERTY );
}
private void addPersistentMembers(List<? extends Element> membersOfClass, AccessType membersKind) {
for ( Element memberOfClass : membersOfClass ) {
AccessType forcedAccessType = TypeUtils.determineAnnotationSpecifiedAccessType( memberOfClass );
@ -138,35 +169,4 @@ public class AnnotationMetaEntity implements MetaEntity {
}
}
}
protected final void init() {
TypeUtils.determineAccessTypeForHierarchy( element, context );
entityAccessTypeInfo = context.getAccessTypeInfo( getQualifiedName() );
List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
addPersistentMembers( fieldsOfClass, AccessType.FIELD );
List<? extends Element> methodsOfClass = ElementFilter.methodsIn( element.getEnclosedElements() );
addPersistentMembers( methodsOfClass, AccessType.PROPERTY );
}
public final String generateImports() {
return importContext.generateImports();
}
public final String importType(String fqcn) {
return importContext.importType( fqcn );
}
public final String staticImport(String fqcn, String member) {
return importContext.staticImport( fqcn, member );
}
public final String importType(Name qualifiedName) {
return importType( qualifiedName.toString() );
}
public final TypeElement getTypeElement() {
return element;
}
}

View File

@ -29,17 +29,11 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.SimpleTypeVisitor6;
import javax.persistence.AccessType;
import javax.persistence.ElementCollection;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyClass;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.tools.Diagnostic;
import org.hibernate.jpamodelgen.AccessTypeInformation;
import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.util.AccessType;
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
import org.hibernate.jpamodelgen.util.Constants;
import org.hibernate.jpamodelgen.util.StringUtil;
import org.hibernate.jpamodelgen.util.TypeUtils;
@ -200,7 +194,7 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6<Annotatio
if ( TypeUtils.containsAnnotation( element, Constants.MAP_KEY_CLASS ) ) {
TypeMirror typeMirror = (TypeMirror) TypeUtils.getAnnotationValue(
TypeUtils.getAnnotationMirror(
element, MapKeyClass.class
element, Constants.MAP_KEY_CLASS
), TypeUtils.DEFAULT_ANNOTATION_PARAMETER_NAME
);
keyType = typeMirror.toString();
@ -249,13 +243,13 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6<Annotatio
private String getTargetEntity(List<? extends AnnotationMirror> annotations) {
String fullyQualifiedTargetEntityName = null;
for ( AnnotationMirror mirror : annotations ) {
if ( TypeUtils.isAnnotationMirrorOfType( mirror, ElementCollection.class ) ) {
if ( TypeUtils.isAnnotationMirrorOfType( mirror, Constants.ELEMENT_COLLECTION ) ) {
fullyQualifiedTargetEntityName = getFullyQualifiedClassNameOfTargetEntity( mirror, "targetClass" );
}
else if ( TypeUtils.isAnnotationMirrorOfType( mirror, OneToMany.class )
|| TypeUtils.isAnnotationMirrorOfType( mirror, ManyToMany.class )
|| TypeUtils.isAnnotationMirrorOfType( mirror, ManyToOne.class )
|| TypeUtils.isAnnotationMirrorOfType( mirror, OneToOne.class ) ) {
else if ( TypeUtils.isAnnotationMirrorOfType( mirror, Constants.ONE_TO_MANY )
|| TypeUtils.isAnnotationMirrorOfType( mirror, Constants.MANY_TO_MANY )
|| TypeUtils.isAnnotationMirrorOfType( mirror, Constants.MANY_TO_ONE )
|| TypeUtils.isAnnotationMirrorOfType( mirror, Constants.ONE_TO_ONE ) ) {
fullyQualifiedTargetEntityName = getFullyQualifiedClassNameOfTargetEntity( mirror, "targetEntity" );
}
else if ( TypeUtils.isAnnotationMirrorOfType( mirror, ORG_HIBERNATE_ANNOTATIONS_TARGET ) ) {

View File

@ -0,0 +1,25 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, 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.util;
/**
* @author Hardy Ferentschik
*/
public enum AccessType {
PROPERTY,
FIELD
}

View File

@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.jpamodelgen;
import javax.persistence.AccessType;
package org.hibernate.jpamodelgen.util;
/**
* Encapsulates the access type information for a single class.

View File

@ -34,7 +34,9 @@ public final class Constants {
public static final String TRANSIENT = "javax.persistence.Transient";
public static final String BASIC = "javax.persistence.Basic";
public static final String ONE_TO_ONE = "javax.persistence.OneToOne";
public static final String ONE_TO_MANY = "javax.persistence.OneToMany";
public static final String MANY_TO_ONE = "javax.persistence.ManyToOne";
public static final String MANY_TO_MANY = "javax.persistence.ManyToMany";
public static final String MAP_KEY_CLASS = "javax.persistence.MapKeyClass";
public static final String ELEMENT_COLLECTION = "javax.persistence.ElementCollection";
public static final String ACCESS = "javax.persistence.Access";
@ -42,22 +44,14 @@ public final class Constants {
public static Map<String, String> COLLECTIONS = new HashMap<String, String>();
static {
COLLECTIONS.put(
java.util.Collection.class.getName(), javax.persistence.metamodel.CollectionAttribute.class.getName()
);
COLLECTIONS.put( java.util.Set.class.getName(), javax.persistence.metamodel.SetAttribute.class.getName() );
COLLECTIONS.put( java.util.List.class.getName(), javax.persistence.metamodel.ListAttribute.class.getName() );
COLLECTIONS.put( java.util.Map.class.getName(), javax.persistence.metamodel.MapAttribute.class.getName() );
COLLECTIONS.put( java.util.Collection.class.getName(), "javax.persistence.metamodel.CollectionAttribute" );
COLLECTIONS.put( java.util.Set.class.getName(), "javax.persistence.metamodel.SetAttribute" );
COLLECTIONS.put( java.util.List.class.getName(), "javax.persistence.metamodel.ListAttribute" );
COLLECTIONS.put( java.util.Map.class.getName(), "javax.persistence.metamodel.MapAttribute" );
// Hibernate also supports the SortedSet and SortedMap interfaces
COLLECTIONS.put(
java.util.SortedSet.class.getName(),
javax.persistence.metamodel.SetAttribute.class.getName()
);
COLLECTIONS.put(
java.util.SortedMap.class.getName(),
javax.persistence.metamodel.MapAttribute.class.getName()
);
COLLECTIONS.put( java.util.SortedSet.class.getName(), "javax.persistence.metamodel.SetAttribute" );
COLLECTIONS.put( java.util.SortedMap.class.getName(), "javax.persistence.metamodel.MapAttribute" );
}
public static List<String> BASIC_TYPES = new ArrayList<String>();

View File

@ -36,15 +36,11 @@ import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import javax.lang.model.util.SimpleTypeVisitor6;
import javax.persistence.AccessType;
import javax.tools.Diagnostic;
import org.hibernate.jpamodelgen.AccessTypeInformation;
import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.MetaModelGenerationException;
//import javax.persistence.EmbeddedId;
/**
* Utility class.
*

View File

@ -30,7 +30,7 @@ import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.hibernate.jpamodelgen.AccessTypeInformation;
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.ImportContextImpl;
import org.hibernate.jpamodelgen.MetaModelGenerationException;

View File

@ -31,7 +31,6 @@ import java.util.Collection;
import java.util.List;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.persistence.AccessType;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
@ -43,7 +42,8 @@ import javax.xml.validation.SchemaFactory;
import org.xml.sax.SAXException;
import org.hibernate.jpamodelgen.AccessTypeInformation;
import org.hibernate.jpamodelgen.util.AccessType;
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.util.Constants;
import org.hibernate.jpamodelgen.util.FileTimeStampChecker;