Author: nickarls
Date: 2009-03-18 18:25:23 -0400 (Wed, 18 Mar 2009)
New Revision: 2103
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.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/TypedModel.java
Log:
minor refactorings
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-18
22:14:29 UTC (rev 2102)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-18
22:25:23 UTC (rev 2103)
@@ -17,18 +17,13 @@
package org.jboss.webbeans.xsd.helpers;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
-import javax.lang.model.element.VariableElement;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.MethodModel;
import org.jboss.webbeans.xsd.model.NamedModel;
-import org.jboss.webbeans.xsd.model.TypedModel;
/**
* Helper for examining classes and members and populating the model
@@ -38,13 +33,7 @@
*/
public class DataSetter
{
- private static Map<TypedModel, TypedModel> typeSubstitutions = new
HashMap<TypedModel, TypedModel>()
- {
- private static final long serialVersionUID = 8092480390430415094L;
- {
- put(TypedModel.of("java.lang.String", false),
TypedModel.of("string", true));
- }};
-
+
/**
* Checks if an element is public
*
@@ -68,7 +57,7 @@
{
return;
}
- NamedModel field = new NamedModel(element.getSimpleName().toString());
+ NamedModel field = NamedModel.of(element.getSimpleName().toString());
classModel.addField(field);
}
@@ -84,17 +73,8 @@
{
return;
}
- ExecutableElement executableElement = (ExecutableElement) element;
+ MethodModel method = MethodModel.of((ExecutableElement) element);
- MethodModel method = new MethodModel(element.getSimpleName().toString());
-
- for (VariableElement parameterElement : executableElement.getParameters())
- {
- boolean primitive = parameterElement.asType().getKind().isPrimitive();
- TypedModel parameter = new TypedModel(parameterElement.asType().toString(),
primitive);
- parameter = typeSubstitutions.containsKey(parameter) ?
typeSubstitutions.get(parameter) : parameter;
- method.addParameter(parameter);
- }
// OK, cheating a little with a common model for methods and constructors
if ("<init>".equals(method.getName()))
{
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-18
22:14:29 UTC (rev 2102)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-18
22:25:23 UTC (rev 2103)
@@ -18,8 +18,13 @@
package org.jboss.webbeans.xsd.model;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.VariableElement;
+
import org.dom4j.Element;
import org.jboss.webbeans.xsd.NamespaceHandler;
@@ -31,13 +36,33 @@
*/
public class MethodModel extends NamedModel
{
+ private static Map<TypedModel, TypedModel> typeSubstitutions = new
HashMap<TypedModel, TypedModel>()
+ {
+ private static final long serialVersionUID = 8092480390430415094L;
+ {
+ put(TypedModel.of("java.lang.String", false),
TypedModel.of("string", true));
+ }
+ };
+
private List<TypedModel> parameters = new ArrayList<TypedModel>();
- public MethodModel(String name)
+ protected MethodModel(ExecutableElement executableElement)
{
- super(name);
+ super(executableElement.getSimpleName().toString());
+ for (VariableElement parameterElement : executableElement.getParameters())
+ {
+ boolean primitive = parameterElement.asType().getKind().isPrimitive();
+ TypedModel parameter = TypedModel.of(parameterElement.asType().toString(),
primitive);
+ parameter = typeSubstitutions.containsKey(parameter) ?
typeSubstitutions.get(parameter) : parameter;
+ addParameter(parameter);
+ }
}
+ public static MethodModel of(ExecutableElement executableElement)
+ {
+ return new MethodModel(executableElement);
+ }
+
public List<TypedModel> getParameters()
{
return 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-18
22:14:29 UTC (rev 2102)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-18
22:25:23 UTC (rev 2103)
@@ -31,11 +31,16 @@
{
protected String name;
- public NamedModel(String name)
+ protected NamedModel(String name)
{
this.name = name;
}
+ public static NamedModel of(String name)
+ {
+ return new NamedModel(name);
+ }
+
public String getName()
{
return name;
@@ -45,7 +50,7 @@
{
this.name = name;
}
-
+
@Override
public String toString()
{
Modified: 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 2009-03-18
22:14:29 UTC (rev 2102)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-18
22:25:23 UTC (rev 2103)
@@ -32,7 +32,7 @@
protected String type;
protected boolean primitive;
- public TypedModel(String type, boolean primitive)
+ protected TypedModel(String type, boolean primitive)
{
this.type = type;
this.primitive = primitive;
Show replies by date