Author: nickarls
Date: 2009-03-16 03:16:55 -0400 (Mon, 16 Mar 2009)
New Revision: 2026
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Test.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java
Log:
annotation detection
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -118,6 +118,7 @@
}
// Place the new class model in the cache
helper.cacheClassModel(classModel);
+ System.out.println(classModel);
return classModel;
}
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -17,6 +17,10 @@
package org.jboss.webbeans.xsd.helpers;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
@@ -32,7 +36,7 @@
* Helper for examining classes and members and populating the model
*
* @author Nicklas Karlsson
- *
+ *
*/
public class DataSetter
{
@@ -50,16 +54,18 @@
/**
* Inspects a type element and populates a class model
- *
+ *
* @param classModel The class model to populate
* @param element The element to inspect
* @param parent The parent of the class
*/
public static void populateClassModel(ClassModel classModel, Element element,
ClassModel parent)
{
+ List<String> annotations = getAnnotations(element);
TypeElement typeElement = (TypeElement) element;
classModel.setName(typeElement.getQualifiedName().toString());
classModel.setParent(parent);
+ classModel.setAnnotations(annotations);
}
/**
@@ -76,7 +82,8 @@
}
String name = element.getSimpleName().toString();
String type = element.asType().toString();
- classModel.addField(new FieldModel(name, type));
+ List<String> annotations = getAnnotations(element);
+ classModel.addField(new FieldModel(name, type, annotations));
}
/**
@@ -95,16 +102,18 @@
String name = element.getSimpleName().toString();
String returnType = executableElement.getReturnType().toString();
- MethodModel method = new MethodModel(name, returnType);
+ List<String> annotations = getAnnotations(element);
+ MethodModel method = new MethodModel(name, returnType, annotations);
for (VariableElement parameterElement : executableElement.getParameters())
{
String paramName = parameterElement.getSimpleName().toString();
String paramType = parameterElement.asType().toString();
- ParameterModel parameter = new ParameterModel(paramName, paramType);
+ List<String> paramAnotations = getAnnotations(parameterElement);
+ ParameterModel parameter = new ParameterModel(paramName, paramType,
paramAnotations);
method.addParameter(parameter);
}
- // OK, checting a little with a common model for methods and constructors
+ // OK, cheating a little with a common model for methods and constructors
if ("<init>".equals(name))
{
classModel.addConstructor(method);
@@ -115,4 +124,14 @@
}
}
+ public static List<String> getAnnotations(Element element)
+ {
+ List<String> annotations = new ArrayList<String>();
+ for (AnnotationMirror annotation : element.getAnnotationMirrors())
+ {
+ annotations.add(annotation.getAnnotationType().toString());
+ }
+ return annotations;
+ }
+
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -81,10 +81,11 @@
public String toString()
{
StringBuilder buffer = new StringBuilder();
- buffer.append("Name: " + name + "\n");
- buffer.append("Constructors: " + getMergedConstructors() +
"\n");
- buffer.append("Methods: " + getMergedMethods() + "\n");
- buffer.append("Fields: " + getMergedFields() + "\n");
+ String annotationString = (annotations.isEmpty()) ? "" : "@" +
annotations + ": ";
+ buffer.append("----------------------------------\n" + annotationString +
name + "\n");
+ buffer.append("Constructors:\n " + getMergedConstructors() +
"\n");
+ buffer.append("Methods:\n" + getMergedMethods() + "\n");
+ buffer.append("Fields:\n" + getMergedFields() + "\n");
return buffer.toString();
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -17,6 +17,8 @@
package org.jboss.webbeans.xsd.model;
+import java.util.List;
+
/**
* A model of a field
*
@@ -27,9 +29,9 @@
{
protected String type;
- public FieldModel(String name, String type)
+ public FieldModel(String name, String type, List<String> annotations)
{
- super(name);
+ super(name, annotations);
this.type = type;
}
@@ -54,7 +56,8 @@
@Override
public String toString()
{
- return type + " " + name;
+ String annotationString = (annotations.isEmpty()) ? "" : "@" +
annotations + ": ";
+ return "\n " + annotationString + type + " " + name;
}
}
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -31,9 +31,9 @@
private String returnType;
private List<ParameterModel> parameters = new
ArrayList<ParameterModel>();
- public MethodModel(String name, String returnType)
+ public MethodModel(String name, String returnType, List<String> annotations)
{
- super(name);
+ super(name, annotations);
this.returnType = returnType;
}
@@ -68,7 +68,8 @@
@Override
public String toString()
{
- return returnType + " " + name + "(" + (parameters.isEmpty() ?
"" : parameters) + ")";
+ String annotationString = (annotations.isEmpty()) ? "" : "@" +
annotations + ": ";
+ return "\n " + annotationString + returnType + " " + name +
"(" + (parameters.isEmpty() ? "" : parameters) + ")";
}
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -17,25 +17,41 @@
package org.jboss.webbeans.xsd.model;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* A superclass for named models
*
* @author Nicklas Karlsson
- *
+ *
*/
public class NamedModel
{
protected String name;
+ protected Set<String> annotations = new HashSet<String>();
public NamedModel()
{
}
- public NamedModel(String name)
+ public NamedModel(String name, List<String> annotations)
{
this.name = name;
+ this.annotations.addAll(annotations);
}
+ public void setAnnotations(List<String> annotations)
+ {
+ this.annotations.addAll(annotations);
+ }
+
+ public Set<String> getAnnotations()
+ {
+ return annotations;
+ }
+
public String getName()
{
return name;
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java 2009-03-16
06:58:11 UTC (rev 2025)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -17,6 +17,8 @@
package org.jboss.webbeans.xsd.model;
+import java.util.List;
+
/**
* The model of a method or constrcutor parameter
*
@@ -26,9 +28,9 @@
public class ParameterModel extends FieldModel
{
- public ParameterModel(String name, String type)
+ public ParameterModel(String name, String type, List<String> annotations)
{
- super(name, type);
+ super(name, type, annotations);
}
@Override
@@ -43,5 +45,12 @@
{
return type.hashCode();
}
+
+ @Override
+ public String toString()
+ {
+ String annotationString = (annotations.isEmpty()) ? "" : "@" +
annotations + ": ";
+ return "\n " + annotationString + type + " " + name;
+ }
}
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
(rev 0)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -0,0 +1,23 @@
+package org.jboss.webbeans.xsd.test;
+
+import javax.inject.Current;
+import javax.inject.Initializer;
+
+@Current
+public class Foo
+{
+ @Current
+ public String foo;
+
+ @Initializer
+ public Foo(String foo)
+ {
+ }
+
+ @Current
+ public String foo(@Current String foo)
+ {
+ return foo;
+ }
+
+}
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Test.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Test.java
(rev 0)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Test.java 2009-03-16
07:16:55 UTC (rev 2026)
@@ -0,0 +1,30 @@
+package org.jboss.webbeans.xsd.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import javax.tools.JavaCompiler.CompilationTask;
+
+import org.jboss.webbeans.xsd.PackageSchemaGenerator;
+
+public class Test
+{
+
+ public static void main(String[] args)
+ {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null,
null);
+ Iterable<? extends JavaFileObject> compilationUnits =
fileManager.getJavaFileObjects(args);
+ CompilationTask task = compiler.getTask(null, fileManager, null, null, null,
compilationUnits);
+ List<AbstractProcessor> processors = new
ArrayList<AbstractProcessor>();
+ processors.add(new PackageSchemaGenerator());
+ task.setProcessors(processors);
+ task.call();
+ }
+
+}