Author: max.andersen(a)jboss.com
Date: 2009-01-16 12:17:08 -0500 (Fri, 16 Jan 2009)
New Revision: 13092
Added:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity$TypeVisitor.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.class
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.class
Removed:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.java
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.java
Log:
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContext.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,23 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-public interface ImportContext {
-
- /**
- * Add fqcn to the import list. Returns fqcn as needed in source code.
- * Attempts to handle fqcn with array and generics references.
- *
- * e.g.
- * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns
Collection
- * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
- *
- *
- * @param fqcn
- * @return import string
- */
- public abstract String importType(String fqcn);
-
- public abstract String staticImport(String fqcn, String member);
-
- public abstract String generateImports();
-
-}
\ No newline at end of file
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.java
===================================================================
---
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.java 2009-01-16
17:15:21 UTC (rev 13091)
+++
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/ImportContextImpl.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,160 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-
-
-public class ImportContextImpl implements ImportContext {
-
- Set<String> imports = new TreeSet<String>();
- Set<String> staticImports = new TreeSet<String>();
- Map<String, String> simpleNames = new HashMap<String, String>();
-
- String basePackage = "";
-
- private static final Map<String, String> PRIMITIVES = new HashMap<String,
String>();
- static {
- PRIMITIVES.put( "char", "Character" );
-
- PRIMITIVES.put( "byte", "Byte" );
- PRIMITIVES.put( "short", "Short" );
- PRIMITIVES.put( "int", "Integer" );
- PRIMITIVES.put( "long", "Long" );
-
- PRIMITIVES.put( "boolean", "Boolean" );
-
- PRIMITIVES.put( "float", "Float" );
- PRIMITIVES.put( "double", "Double" );
-
- }
-
- public ImportContextImpl(String basePackage) {
- this.basePackage = basePackage;
- }
-
- /**
- * Add fqcn to the import list. Returns fqcn as needed in source code.
- * Attempts to handle fqcn with array and generics references.
- *
- * e.g.
- * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns
Collection
- * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
- *
- *
- * @param fqcn
- * @return import string
- */
- public String importType(String fqcn) {
- String result = fqcn;
-
- String additionalTypePart = null;
- if(fqcn.indexOf('<')>=0) {
- additionalTypePart = result.substring(fqcn.indexOf('<'));
- result = result.substring(0,fqcn.indexOf('<'));
- fqcn = result;
- } else if(fqcn.indexOf('[')>=0) {
- additionalTypePart = result.substring(fqcn.indexOf('['));
- result = result.substring(0,fqcn.indexOf('['));
- fqcn = result;
- }
-
- String pureFqcn = fqcn.replace( '$', '.' );
-
- boolean canBeSimple = true;
-
-
- String simpleName = unqualify(fqcn);
- if(simpleNames.containsKey(simpleName)) {
- String existingFqcn = simpleNames.get(simpleName);
- if(existingFqcn.equals(pureFqcn)) {
- canBeSimple = true;
- } else {
- canBeSimple = false;
- }
- } else {
- canBeSimple = true;
- simpleNames.put(simpleName, pureFqcn);
- imports.add( pureFqcn );
- }
-
-
- if ( inSamePackage(fqcn) || (imports.contains( pureFqcn ) && canBeSimple) ) {
- result = unqualify( result ); // dequalify
- } else if ( inJavaLang( fqcn ) ) {
- result = result.substring( "java.lang.".length() );
- }
-
- if(additionalTypePart!=null) {
- result = result + additionalTypePart;
- }
-
- result = result.replace( '$', '.' );
- return result;
- }
-
- public String staticImport(String fqcn, String member) {
- String local = fqcn + "." + member;
- imports.add(local);
- staticImports.add(local);
-
- if(member.equals("*")) {
- return "";
- } else {
- return member;
- }
- }
-
- private boolean inDefaultPackage(String className) {
- return className.indexOf( "." ) < 0;
- }
-
- private boolean isPrimitive(String className) {
- return PRIMITIVES.containsKey( className );
- }
-
- private boolean inSamePackage(String className) {
- String other = qualifier( className );
- return other == basePackage
- || (other != null && other.equals( basePackage ) );
- }
-
- private boolean inJavaLang(String className) {
- return "java.lang".equals( qualifier( className ) );
- }
-
- public String generateImports() {
- StringBuffer buf = new StringBuffer();
-
- for ( Iterator<String> imps = imports.iterator(); imps.hasNext(); ) {
- String next = imps.next();
- if(isPrimitive(next) || inDefaultPackage(next) || inJavaLang(next) ||
inSamePackage(next)) {
- // dont add automatically "imported" stuff
- } else {
- if(staticImports.contains(next)) {
- buf.append("import static " + next + ";\r\n");
- } else {
- buf.append("import " + next + ";\r\n");
- }
- }
- }
-
- if(buf.indexOf( "$" )>=0) {
- return buf.toString();
- }
- return buf.toString();
- }
-
- public static String unqualify(String qualifiedName) {
- int loc = qualifiedName.lastIndexOf(".");
- return ( loc < 0 ) ? qualifiedName : qualifiedName.substring(
qualifiedName.lastIndexOf(".") + 1 );
- }
-
- public static String qualifier(String qualifiedName) {
- int loc = qualifiedName.lastIndexOf(".");
- return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc );
- }
-}
Added:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
---
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-01-16
17:15:21 UTC (rev 13091)
+++
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,152 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import static javax.lang.model.SourceVersion.RELEASE_6;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Set;
-
-import javax.annotation.Generated;
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.FilerException;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
-import javax.tools.Diagnostic;
-import javax.tools.FileObject;
-
-(a)SupportedAnnotationTypes("javax.persistence.Entity")
-@SupportedSourceVersion(RELEASE_6)
-public class JPAMetaModelEntityProcessor extends AbstractProcessor {
-
- public JPAMetaModelEntityProcessor() {
-
- }
-
- /**
- * Process JPA-specific annotations in Java entity classes.
- *
- * @param aAnnotations
- * Matching annotations to be processed.
- * @param aRoundEnvironment
- * Annotation processing round environment.
- * @return
- */
- @Override
- public boolean process(final Set<? extends TypeElement> aAnnotations,
- final RoundEnvironment aRoundEnvironment) {
-
-
- if(aRoundEnvironment.processingOver()) { // No need to run since all our output needs
to be considered
- return false;
- }
-
- Set<? extends Element> elements = aRoundEnvironment.getRootElements();
-
- for (Element element : elements) {
- handleRootElementAnnotationMirrors(element);
- }
-
- return true;
- }
-
- private void handleRootElementAnnotationMirrors(final Element element) {
-
- List<? extends AnnotationMirror> annotationMirrors = element
- .getAnnotationMirrors();
-
- for (AnnotationMirror mirror : annotationMirrors) {
- final String annotationType = mirror.getAnnotationType().toString();
-
- if (element.getKind()==ElementKind.CLASS &&
- annotationType.equals(javax.persistence.Entity.class.getName())) {
-
- MetaEntity metaEntity = new MetaEntity(processingEnv,(TypeElement) element);
-
- writeFile(metaEntity);
-
- }
- }
- }
-
- private void writeFile(MetaEntity entity) {
-
- try {
- Name metaModelPackage = entity.getPackageName();
-
-
- StringBuffer body = generateBody(entity);
-
- FileObject fo = processingEnv.getFiler().createSourceFile(
- metaModelPackage + "." + entity.getSimpleName() + "_",
- entity.getOriginalElement());
- OutputStream os = fo.openOutputStream();
- PrintWriter pw = new PrintWriter(os);
-
- pw.println("package " + metaModelPackage + ";");
-
- pw.println();
-
- pw.println(entity.generateImports());
-
- pw.println(body);
-
- pw.flush();
- pw.close();
-
- } catch (FilerException filerEx) {
- processingEnv.getMessager().printMessage(
- Diagnostic.Kind.ERROR,
- "Problem with Processing Environment Filer: "
- + filerEx.getMessage());
- } catch (IOException ioEx) {
- processingEnv.getMessager().printMessage(
- Diagnostic.Kind.ERROR,
- "Problem opening file to write MetaModel for " + entity.getSimpleName()
- + ioEx.getMessage());
- }
- }
-
- /** Generate everything after import statements
- * @return body content
- **/
- private StringBuffer generateBody(MetaEntity entity) {
-
- StringWriter sw = new StringWriter();
- PrintWriter pw = null;
- try {
-
- pw = new PrintWriter(sw);
-
- pw.println("@" + entity.importType(Generated.class.getName()) +
"(\"JPA MetaModel for " + entity.getQualifiedName() +
"\")");
-
- pw.println("@" +
entity.importType("javax.jpa.metamodel.TypesafeMetamodel"));
-
- pw.println("public abstract class " + entity.getSimpleName() + "_"
+ " {");
-
- pw.println();
-
- List<MetaMember> members = entity.getMembers();
-
- for (MetaMember metaMember : members) {
- pw.println( " " + metaMember.getDeclarationString() );
- }
- pw.println();
- pw.println("}");
- return sw.getBuffer();
- } finally {
- if (pw!=null) pw.close();
- }
-
-
- }
-
-}
Added:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.java
===================================================================
---
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.java 2009-01-16
17:15:21 UTC (rev 13091)
+++
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/JpaAnnotationsConstants.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,33 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-public class JpaAnnotationsConstants
-{
- public static final String ANNOTATION_KEY_ALLOCATION_SIZE =
"allocationSize()";
- public static final String ANNOTATION_KEY_COLUMN_DEFINITION =
"columnDefinition()";
- public static final String ANNOTATION_KEY_DISCRIMINATOR_TYPE =
- "discriminatorType()";
- public static final String ANNOTATION_KEY_INITIAL_VALUE = "initialValue()";
- public static final String ANNOTATION_KEY_GENERATOR = "generator()";
- public static final String ANNOTATION_KEY_INSERTABLE = "insertable()";
- public static final String ANNOTATION_KEY_INVERSE_JOIN_COLUMNS =
- "inverseJoinColumns()";
- public static final String ANNOTATION_KEY_JOIN_COLUMNS = "joinColumns()";
- public static final String ANNOTATION_KEY_LENGTH = "length()";
- public static final String ANNOTATION_KEY_MAPPED_BY = "mappedBy()";
- public static final String ANNOTATION_KEY_NAME = "name()";
- public static final String ANNOTATION_KEY_NULLABLE = "nullable()";
- public static final String ANNOTATION_KEY_QUERY = "query()";
- public static final String ANNOTATION_KEY_REFERENCED_COLUMN_NAME =
- "referencedColumnName()";
- public static final String ANNOTATION_KEY_SEQUENCE_NAME = "sequenceName()";
- public static final String ANNOTATION_KEY_STRATEGY = "strategy()";
- public static final String ANNOTATION_TARGET_ENTITY = "targetEntity()";
- public static final String ANNOTATION_KEY_VALUE = "value()";
-
- public static final String JPA_VERSION = "1.0";
-
- public static final String PROCESSOR_USER_OPTION_XML_OVERRIDE =
- "xmlOverrideAnnotations";
- public static final String PROCESSOR_USER_OPTION_UPPER_COLUMN_NAMES =
- "useUpperCaseColumnNames";
-}
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaAttribute.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,16 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import javax.lang.model.element.Element;
-
-public class MetaAttribute extends MetaMember {
-
- public MetaAttribute(MetaEntity parent, Element element, String type) {
- super(parent, element, type);
- }
-
- @Override
- protected String getMetaType() {
- return "javax.jpa.metamodel.Attribute";
- }
-
-}
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.java
===================================================================
---
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.java 2009-01-16
17:15:21 UTC (rev 13091)
+++
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaCollection.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,22 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import javax.lang.model.element.Element;
-
-
-public class MetaCollection extends MetaMember {
-
- private String collectionType;
-
-
- public MetaCollection(MetaEntity parent, Element element, String collectionType, String
elementType) {
- super(parent, element, elementType);
- this.collectionType = collectionType;
- }
-
- @Override
- protected String getMetaType() {
- return collectionType;
- }
-
-
-}
Added:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity$TypeVisitor.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity$TypeVisitor.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaEntity.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,224 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.type.ExecutableType;
-import javax.lang.model.type.PrimitiveType;
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.util.ElementFilter;
-import javax.lang.model.util.SimpleTypeVisitor6;
-import javax.tools.Diagnostic.Kind;
-
-public class MetaEntity implements ImportContext {
-
- final TypeElement element;
- final protected ProcessingEnvironment pe;
-
- final ImportContext importContext;
-
- public MetaEntity(ProcessingEnvironment pe, TypeElement element) {
- this.element = element;
- this.pe = pe;
- importContext = new ImportContextImpl(getPackageName().toString());
- }
-
- public Name getSimpleName() {
- return element.getSimpleName();
- }
-
- public Element getOriginalElement() {
- return element;
- }
-
- public Name getQualifiedName() {
- return element.getQualifiedName();
- }
-
- public Name getPackageName() {
- PackageElement packageOf = pe.getElementUtils().getPackageOf(element);
- return pe.getElementUtils().getName(packageOf.getQualifiedName() +
".metamodel");
- }
-
- public List<MetaMember> getMembers() {
-
- List<MetaMember> members = new ArrayList<MetaMember>();
-
- if(useFields()) {
-
- List<? extends Element> myMembers =
ElementFilter.fieldsIn(element.getEnclosedElements());
-
- System.out.println("Scanning " + myMembers.size() + " field s for
" + element.toString());
-
- for (Element mymember : myMembers) {
-
- MetaMember result = mymember.asType().accept(new TypeVisitor(this), mymember);
- if(result!=null) {
- members.add(result);
- } else {
- pe.getMessager().printMessage(Kind.WARNING, "Could not find valid info for JPA
property", mymember);
- }
- }
-
- } else {
-
-
- List<? extends Element> myMembers =
ElementFilter.methodsIn(element.getEnclosedElements());
-
- System.out.println("Scanning " + myMembers.size() + " methods for
" + element.toString());
- for (Element mymember : myMembers) {
-
- MetaMember result = mymember.asType().accept(new TypeVisitor(this), mymember);
- if(result!=null) {
- members.add(result);
- } else {
- //pe.getMessager().printMessage(Kind.WARNING, "Not a valid JPA property",
mymember);
- }
- }
-
- }
-
- if(members.size()==0) {
- pe.getMessager().printMessage(Kind.WARNING, "No properties found on " +
element, element);
- }
- return members;
- }
-
-
- //TODO: Find more efficient way to identify wether we should use fields or properties
- private boolean useFields() {
- List<? extends Element> myMembers = element.getEnclosedElements();
- for (Element element : myMembers) {
- List<? extends AnnotationMirror> entityAnnotations =
- pe.getElementUtils().getAllAnnotationMirrors(element);
-
- for (Iterator<?> iterator = entityAnnotations.iterator(); iterator
- .hasNext();) {
- AnnotationMirror annotationMirror = (AnnotationMirror) iterator
- .next();
-
- final String annotationType = annotationMirror.getAnnotationType().toString();
-
- if ( annotationType.equals(javax.persistence.Id.class.getName()) ||
- annotationType.equals(javax.persistence.EmbeddedId.class.getName()))
- {
- if(element.getKind()==ElementKind.FIELD) {
- return true;
- }
- }
- }
- }
-
- return false;
- }
-
-
-
- static Map<String, String> COLLECTIONS = new HashMap<String, String>();
- static {
- COLLECTIONS.put("java.util.Collection",
"javax.jpa.metamodel.Collection");
- COLLECTIONS.put("java.util.Set", "javax.jpa.metamodel.Set");
- COLLECTIONS.put("java.util.List", "javax.jpa.metamodel.List");
- COLLECTIONS.put("java.util.Map", "javax.jpa.metamodel.Map");
- }
-
- class TypeVisitor extends SimpleTypeVisitor6<MetaMember, Element> {
-
- MetaEntity parent;
-
- TypeVisitor(MetaEntity parent) {
- this.parent = parent;
- }
-
- @Override
- protected MetaMember defaultAction(TypeMirror e, Element p) {
- //System.out.println("Default action for: " + e + " on " + p);
- //new Exception().printStackTrace();
- return super.defaultAction(e, p);
- }
- @Override
- public MetaMember visitPrimitive(PrimitiveType t, Element p) {
- return new MetaAttribute(parent, p, TypeUtils.toTypeString(t));
- }
-
-
-
- @Override
- public MetaMember visitDeclared(DeclaredType t, Element p) {
- TypeElement e = (TypeElement) pe.getTypeUtils().asElement(t);
-
- String collection = COLLECTIONS.get(e.getQualifiedName().toString()); // WARNING:
.toString() is necessary here since Name equals does not compare to String
- if(collection!=null) {
- if(collection.equals("javax.jpa.metamodel.Map")) {
- return new MetaMap(parent, p, collection, getKeyType(t), getElementType(t));
- } else {
- return new MetaCollection(parent, p, collection, getElementType(t));
- }
- } else {
- return new MetaAttribute(parent, p, e.getQualifiedName().toString());
- }
- }
-
-
-
- @Override
- public MetaMember visitExecutable(ExecutableType t, Element p) {
- String string = p.getSimpleName().toString();
-
- // TODO: implement proper property get/is/boolean detection
- if(string.startsWith("get") || string.startsWith("is")) {
- TypeMirror returnType = t.getReturnType();
-
- return returnType.accept(this, p);
- } else {
- return null;
- }
- }
- }
-
- @Override
- public String generateImports() {
- return importContext.generateImports();
- }
-
- @Override
- public String importType(String fqcn) {
- return importContext.importType(fqcn);
- }
-
- @Override
- public String staticImport(String fqcn, String member) {
- return importContext.staticImport(fqcn, member);
- }
-
- public String importType(Name qualifiedName) {
- return importType(qualifiedName.toString());
- }
-
- private String getKeyType(DeclaredType t) {
- System.out.println("key type" + t);
- return t.getTypeArguments().get(0).toString();
- }
-
-
- private String getElementType(DeclaredType declaredType) {
- if(declaredType.getTypeArguments().size()==1) {
- return declaredType.getTypeArguments().get(0).toString();
- } else {
- return declaredType.getTypeArguments().get(1).toString();
- }
- }
-
-
-}
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMap.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,19 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import javax.lang.model.element.Element;
-
-public class MetaMap extends MetaCollection {
-
- private final String keyType;
-
- public MetaMap(MetaEntity parent, Element element, String collectionType,
- String keyType, String elementType) {
- super(parent, element, collectionType, elementType);
- this.keyType = keyType;
- }
-
- public String getDeclarationString() {
- return "public static " + parent.importType(getMetaType()) + "<"
+ parent.importType(parent.getQualifiedName()) + ", " +
parent.importType(keyType) + ", " + parent.importType(getTypeDeclaration()) +
"> " + getPropertyName() + ";";
- }
-
-}
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/MetaMember.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,52 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import java.beans.Introspector;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.Name;
-
-public abstract class MetaMember {
-
- final protected Element element;
- final protected MetaEntity parent;
- final protected ProcessingEnvironment pe;
- private final String type;
-
- public MetaMember(MetaEntity parent, Element element, String type) {
- this.element = element;
- this.parent = parent;
- this.type = type;
- this.pe = parent.pe;
- }
-
- public String getDeclarationString() {
- return "public static " + parent.importType(getMetaType()) + "<"
+ parent.importType(parent.getQualifiedName()) + ", " +
parent.importType(getTypeDeclaration()) + "> " + getPropertyName() +
";";
- }
-
- protected Name getPropertyName() {
- if(element.getKind()==ElementKind.FIELD) {
- return element.getSimpleName();
- } else if (element.getKind()==ElementKind.METHOD) {
-
- String name = element.getSimpleName().toString();
- if(name.startsWith("get")) {
- return
pe.getElementUtils().getName(Introspector.decapitalize(name.substring("get".length())));
- } else if(name.startsWith("is")) {
- return
(pe.getElementUtils().getName(Introspector.decapitalize(name.substring("is".length()))));
- }
- return pe.getElementUtils().getName(Introspector.decapitalize(name));
- } else {
- return pe.getElementUtils().getName(element.getSimpleName() + "/* " +
element.getKind() + " */");
- }
- }
-
- abstract protected String getMetaType();
-
-
- protected String getTypeDeclaration() {
- return type;
- }
-
-}
Added: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.class
===================================================================
(Binary files differ)
Property changes on:
workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.java
===================================================================
--- workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.java 2009-01-16
17:15:21 UTC (rev 13091)
+++ workspace/max/jpaap/jpaap/src/org/jboss/jpa/metamodel/ap/TypeUtils.java 2009-01-16
17:17:08 UTC (rev 13092)
@@ -1,33 +0,0 @@
-package org.jboss.jpa.metamodel.ap;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.lang.model.type.TypeMirror;
-
-public class TypeUtils {
-
- private static final Map<String, String> PRIMITIVES = new HashMap<String,
String>();
- static {
- PRIMITIVES.put( "char", "Character" );
-
- PRIMITIVES.put( "byte", "Byte" );
- PRIMITIVES.put( "short", "Short" );
- PRIMITIVES.put( "int", "Integer" );
- PRIMITIVES.put( "long", "Long" );
-
- PRIMITIVES.put( "boolean", "Boolean" );
-
- PRIMITIVES.put( "float", "Float" );
- PRIMITIVES.put( "double", "Double" );
-
- }
-
- static public String toTypeString(TypeMirror type) {
- if(type.getKind().isPrimitive()) {
- return PRIMITIVES.get(type.toString());
- }
-
- return type.toString();
- }
-}