[webbeans-commits] Webbeans SVN: r2051 - in extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd: helpers and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Mar 16 17:35:01 EDT 2009
Author: nickarls
Date: 2009-03-16 17:35:01 -0400 (Mon, 16 Mar 2009)
New Revision: 2051
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Bar.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
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/helpers/XSDHelper.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
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
Log:
return types, change in hierarchy etc.
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-16 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -1,20 +1,42 @@
package org.jboss.webbeans.xsd;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.dom4j.Document;
+import org.jboss.webbeans.xsd.model.TypedModel;
public class PackageInfo
{
private List<String> namespaces;
private Document schema;
private String packageName;
+ private Map<String, Set<String>> typeReferences;
public PackageInfo(String packageName)
{
this.packageName = packageName;
+ typeReferences = new HashMap<String, Set<String>>();
}
+ public void addTypeReferences(Set<TypedModel> references)
+ {
+ for (TypedModel reference : references)
+ {
+ String key = reference.isPrimitive() ? "" : reference.getTypePackage();
+ Set<String> typeNames = typeReferences.get(key);
+ if (typeNames == null)
+ {
+ typeNames = new HashSet<String>();
+ typeReferences.put(reference.getTypePackage(), typeNames);
+ }
+ typeNames.add(reference.getType());
+ }
+ }
+
public List<String> getNamespaces()
{
return namespaces;
@@ -44,5 +66,9 @@
{
this.packageName = packageName;
}
-
+
+ public Map<String, Set<String>> getTypeReferences()
+ {
+ return typeReferences;
+ }
}
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -64,6 +64,7 @@
List<ClassModel> workingSet = new ArrayList<ClassModel>();
// Iterates over the classes compiled, creates a model of the classes and
// add them to a working set
+
for (Element element : roundEnv.getRootElements())
{
workingSet.add(inspectClass(element));
@@ -87,8 +88,9 @@
private ClassModel inspectClass(Element element)
{
TypeElement typeElement = (TypeElement) element;
+
ClassModel classModel = new ClassModel();
-
+
// If the class has superclass's, scan them recursively
if (typeElement.getSuperclass().getKind() != TypeKind.NONE)
{
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -28,11 +28,13 @@
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.FieldModel;
import org.jboss.webbeans.xsd.model.MethodModel;
import org.jboss.webbeans.xsd.model.ParameterModel;
+import org.jboss.webbeans.xsd.model.TypedModel;
/**
* Helper for examining classes and members and populating the model
@@ -84,8 +86,14 @@
}
String name = element.getSimpleName().toString();
String type = element.asType().toString();
+ boolean primitive = element.asType().getKind().isPrimitive();
Map<String, Set<String>> annotations = getAnnotations(element);
- classModel.addField(new FieldModel(name, type, annotations));
+ FieldModel field = new FieldModel();
+ field.setName(name);
+ field.setType(type);
+ field.setPrimitive(primitive);
+ field.setAnnotations(annotations);
+ classModel.addField(field);
}
/**
@@ -103,16 +111,27 @@
ExecutableElement executableElement = (ExecutableElement) element;
String name = element.getSimpleName().toString();
- String returnType = executableElement.getReturnType().toString();
- Map<String, Set<String>> annotations = getAnnotations(element);
- MethodModel method = new MethodModel(name, returnType, annotations);
+
+ TypedModel returnType = new TypedModel();
+ returnType.setType(executableElement.getReturnType().toString());
+ returnType.setPrimitive(executableElement.getReturnType().getKind().isPrimitive() || executableElement.getReturnType().getKind() == TypeKind.VOID);
+
+ MethodModel method = new MethodModel();
+ method.setName(name);
+ method.setAnnotations(getAnnotations(executableElement));
+ method.setReturnType(returnType);
for (VariableElement parameterElement : executableElement.getParameters())
{
String paramName = parameterElement.getSimpleName().toString();
String paramType = parameterElement.asType().toString();
- Map<String, Set<String>> paramAnnotations = getAnnotations(element);
- ParameterModel parameter = new ParameterModel(paramName, paramType, paramAnnotations);
+ boolean paramPrimitive = parameterElement.asType().getKind().isPrimitive();
+ Map<String, Set<String>> paramAnnotations = getAnnotations(parameterElement);
+ ParameterModel parameter = new ParameterModel();
+ parameter.setName(paramName);
+ parameter.setType(paramType);
+ parameter.setPrimitive(paramPrimitive);
+ parameter.setAnnotations(paramAnnotations);
method.addParameter(parameter);
}
// OK, cheating a little with a common model for methods and constructors
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-16 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.annotation.processing.Filer;
import javax.tools.StandardLocation;
@@ -222,7 +223,11 @@
}
packageInfoMap.put(packageName, packageInfo);
}
- updateClassInSchema(classModel, packageInfo.getSchema());
+ updateClassInSchema(classModel, packageInfo);
+ System.out.println("-------------");
+ for (Entry<String, Set<String>> e : packageInfo.getTypeReferences().entrySet()) {
+ System.out.println(e.getKey() + "=>" + e.getValue());
+ }
}
}
@@ -239,11 +244,12 @@
/**
* Updates a schema with XSD from a file model
*
- * @param schema The schema
+ * @param packageInfo The schema
* @param classModel The class model
*/
- private void updateClassInSchema(ClassModel classModel, Document schema)
+ private void updateClassInSchema(ClassModel classModel, PackageInfo packageInfo)
{
+ Document schema = packageInfo.getSchema();
Node oldClassModel = schema.selectSingleNode("//" + classModel.getSimpleName());
if (oldClassModel != null)
{
@@ -252,6 +258,7 @@
}
// Create a new one
schema.getRootElement().addElement(classModel.getSimpleName());
+ packageInfo.addTypeReferences(classModel.getTypeReferences());
}
/**
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -41,13 +41,6 @@
private List<MethodModel> constructors = new ArrayList<MethodModel>();
/**
- * Creates a new class model
- */
- public ClassModel()
- {
- }
-
- /**
* Adds a field to the class model
*
* @param fieldModel The field to add
@@ -110,28 +103,6 @@
}
/**
- * Gets the package of the file
- *
- * @return The package
- */
- public String getPackage()
- {
- int lastDot = name.lastIndexOf(".");
- return lastDot < 0 ? name : name.substring(0, lastDot);
- }
-
- /**
- * Gets the simple name of the class
- *
- * @return The simple name
- */
- public String getSimpleName()
- {
- int lastDot = name.lastIndexOf(".");
- return lastDot < 0 ? name : name.substring(lastDot + 1);
- }
-
- /**
* Gets the merged hierarchy of available constructors. Returns the
* constructors of this class since constructors aren't inherited
*
@@ -196,29 +167,41 @@
return mergedMethods;
}
- public Set<String> getReferencedTypes()
+ public Set<TypedModel> getTypeReferences()
{
- Set<String> types = new HashSet<String>();
+ Set<TypedModel> typeReferences = new HashSet<TypedModel>();
for (FieldModel field : getMergedFields())
{
- types.add(field.getType());
+ typeReferences.add(field);
}
for (MethodModel method : getMergedMethods())
{
- types.add(method.getReturnType());
+ typeReferences.add(method.getReturnType());
for (ParameterModel parameter : method.getParameters())
{
- types.add(parameter.getType());
+ typeReferences.add(parameter);
}
}
for (MethodModel constructor : getMergedConstructors())
{
for (ParameterModel parameter : constructor.getParameters())
{
- types.add(parameter.getType());
+ typeReferences.add(parameter);
}
}
- return types;
+ return typeReferences;
}
+ public String getPackage()
+ {
+ int lastDot = name.lastIndexOf(".");
+ return lastDot < 0 ? "nopak" : name.substring(0, lastDot);
+ }
+
+ public String getSimpleName()
+ {
+ int lastDot = name.lastIndexOf(".");
+ return lastDot < 0 ? name : name.substring(lastDot + 1);
+ }
+
}
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -17,9 +17,6 @@
package org.jboss.webbeans.xsd.model;
-import java.util.Map;
-import java.util.Set;
-
/**
* A model of a field
*
@@ -28,19 +25,7 @@
*/
public class FieldModel extends NamedModel
{
- protected String type;
- public FieldModel(String name, String type, Map<String, Set<String>> annotations)
- {
- super(name, annotations);
- this.type = type;
- }
-
- public String getType()
- {
- return type;
- }
-
@Override
public boolean equals(Object other)
{
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -19,8 +19,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* The model of a method
@@ -30,18 +28,17 @@
*/
public class MethodModel extends NamedModel
{
- private String returnType;
+ private TypedModel returnType;
private List<ParameterModel> parameters = new ArrayList<ParameterModel>();
- public MethodModel(String name, String returnType, Map<String, Set<String>> annotations)
+ public TypedModel getReturnType()
{
- super(name, annotations);
- this.returnType = returnType;
+ return returnType;
}
- public void addParameter(ParameterModel parameter)
+ public void setReturnType(TypedModel returnType)
{
- parameters.add(parameter);
+ this.returnType = returnType;
}
public List<ParameterModel> getParameters()
@@ -49,10 +46,15 @@
return parameters;
}
- public String getReturnType()
+ public void setParameters(List<ParameterModel> parameters)
{
- return returnType;
+ this.parameters = parameters;
}
+
+ public void addParameter(ParameterModel parameter)
+ {
+ parameters.add(parameter);
+ }
@Override
public boolean equals(Object other)
@@ -71,7 +73,7 @@
public String toString()
{
String annotationString = (annotations.isEmpty()) ? "" : "@" + annotations + ": ";
- return "\n " + annotationString + returnType + " " + name + "(" + (parameters.isEmpty() ? "" : parameters) + ")";
+ return "\n " + annotationString + returnType.getType() + " " + 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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -27,21 +27,11 @@
* @author Nicklas Karlsson
*
*/
-public class NamedModel
+public class NamedModel extends TypedModel
{
protected String name;
protected Map<String, Set<String>> annotations = new HashMap<String, Set<String>>();
- public NamedModel()
- {
- }
-
- public NamedModel(String name, Map<String, Set<String>> annotations)
- {
- this.name = name;
- this.annotations.putAll(annotations);
- }
-
public String getName()
{
return name;
@@ -61,4 +51,17 @@
{
this.annotations = annotations;
}
+
+ @Override
+ public boolean equals(Object other)
+ {
+ return name.equals(other);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
}
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 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -17,8 +17,6 @@
package org.jboss.webbeans.xsd.model;
-import java.util.Map;
-import java.util.Set;
/**
* The model of a method or constrcutor parameter
@@ -28,16 +26,11 @@
*/
public class ParameterModel extends FieldModel
{
-
- public ParameterModel(String name, String type, Map<String, Set<String>> annotations)
- {
- super(name, type, annotations);
- }
@Override
public boolean equals(Object other)
{
- ParameterModel otherModel = (ParameterModel) other;
+ TypedModel otherModel = (TypedModel) other;
return type.equals(otherModel.getType());
}
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java (rev 0)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -0,0 +1,56 @@
+package org.jboss.webbeans.xsd.model;
+
+public class TypedModel
+{
+ protected String type;
+ protected boolean primitive;
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ public boolean isPrimitive()
+ {
+ return primitive;
+ }
+
+ public void setPrimitive(boolean primitive)
+ {
+ this.primitive = primitive;
+ }
+
+ public String getTypePackage()
+ {
+ if (primitive)
+ {
+ return "";
+ }
+ int lastDot = type.lastIndexOf(".");
+ return lastDot < 0 ? "nopak" : type.substring(0, lastDot);
+ }
+
+ public String getTypeSimpleName()
+ {
+ int lastDot = type.lastIndexOf(".");
+ return lastDot < 0 ? type : type.substring(lastDot + 1);
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ return type.equals(other);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return type.hashCode();
+ }
+
+}
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Bar.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Bar.java (rev 0)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Bar.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.xsd.test;
+
+public class Bar
+{
+
+}
Modified: 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 2009-03-16 21:17:53 UTC (rev 2050)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java 2009-03-16 21:35:01 UTC (rev 2051)
@@ -8,6 +8,8 @@
{
@Current
public String foo;
+ public int poo;
+ public Bar bar;
@Initializer
public Foo(String foo)
More information about the weld-commits
mailing list