Author: alexsmirnov
Date: 2010-07-12 14:52:04 -0400 (Mon, 12 Jul 2010)
New Revision: 17983
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
Log:
cleanup NPE fix
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-12
18:50:30 UTC (rev 17982)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-12
18:52:04 UTC (rev 17983)
@@ -90,7 +90,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @author asmirnov(a)exadel.com
*/
public class RendererClassVisitor implements TemplateVisitor {
@@ -177,25 +177,23 @@
List<ResourceDependency> resourceDependencies =
compositeInterface.getResourceDependencies();
ELType dependencyType =
typesFactory.getType(javax.faces.application.ResourceDependency.class);
- if (resourceDependencies != null) {
- if (1 == resourceDependencies.size()) {
- ResourceDependency resource = resourceDependencies.get(0);
-
this.generatedClass.addAnnotation(createResourceAnnotation(dependencyType, resource));
- } else if (resourceDependencies.size() > 1) {
- StringBuilder resources = new StringBuilder("{");
- for (ResourceDependency resource : resourceDependencies) {
- if (resources.length() > 1) {
- resources.append(',');
- }
- resources.append("@ResourceDependency(");
-
resources.append("name=\"").append(resource.getName()).append("\",library=\"").append(
-
resource.getLibrary()).append("\",target=\"").append(resource.getTarget()).append("\"").append(")");
+ if (1 == resourceDependencies.size()) {
+ ResourceDependency resource = resourceDependencies.get(0);
+ this.generatedClass.addAnnotation(createResourceAnnotation(dependencyType,
resource));
+ } else if (resourceDependencies.size() > 1) {
+ StringBuilder resources = new StringBuilder("{");
+ for (ResourceDependency resource : resourceDependencies) {
+ if (resources.length() > 1) {
+ resources.append(',');
}
- resources.append("}");
- this.generatedClass.addAnnotation(new
JavaAnnotation(typesFactory.getType(ResourceDependencies.class),
- resources.toString()));
-
this.generatedClass.addImport(javax.faces.application.ResourceDependency.class);
+ resources.append("@ResourceDependency(");
+
resources.append("name=\"").append(resource.getName()).append("\",library=\"").append(
+
resource.getLibrary()).append("\",target=\"").append(resource.getTarget()).append("\"").append(")");
}
+ resources.append("}");
+ this.generatedClass.addAnnotation(new
JavaAnnotation(typesFactory.getType(ResourceDependencies.class),
+ resources.toString()));
+
this.generatedClass.addImport(javax.faces.application.ResourceDependency.class);
}
this.createMethodContext();
}
@@ -315,7 +313,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the rendererClass
*/
public JavaClass getGeneratedClass() {
@@ -324,7 +322,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkBodyElement)
*/
@@ -336,7 +334,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkBodyElement)
*/
@@ -348,7 +346,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.AnyElement)
*/
@@ -368,7 +366,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.AnyElement)
*/
@@ -382,7 +380,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
org.richfaces.cdk.templatecompiler.model.TemplateVisitor#visitElement(java.lang.String)
*/
@@ -399,7 +397,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #visitElement(org.richfaces.cdk.templatecompiler.model.CdkCallElement)
*/
@@ -415,7 +413,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkIfElement)
*/
@@ -429,7 +427,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkIfElement)
*/
@@ -442,7 +440,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkChooseElement)
*/
@@ -454,7 +452,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkChooseElement)
*/
@@ -466,7 +464,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkWhenElement)
*/
@@ -479,7 +477,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkWhenElement)
*/
@@ -491,7 +489,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement)
*/
@@ -503,7 +501,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement)
*/
@@ -515,7 +513,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #visitElement(org.richfaces.cdk.templatecompiler.model.CdkObjectElement)
*/
@@ -534,7 +532,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #startElement(org.richfaces.cdk.templatecompiler.model.CdkForEachElement)
*/
@@ -556,7 +554,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor
* #endElement(org.richfaces.cdk.templatecompiler.model.CdkForEachElement)
*/
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-07-12
18:50:30 UTC (rev 17982)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-07-12
18:52:04 UTC (rev 17983)
@@ -22,7 +22,6 @@
package org.richfaces.cdk.templatecompiler.builder.model;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
@@ -81,15 +80,10 @@
public Iterable<JavaImport> getRequiredImports() {
Iterable<JavaImport> exceptionsImports =
Iterables.concat(Iterables.transform(getExceptions(), RequireImports.IMPORTS_TRANSFORM));
Iterable<JavaImport> argumentsImports =
Iterables.concat(Iterables.transform(getArguments(), RequireImports.IMPORTS_TRANSFORM));
-
- Iterable<JavaImport> methodBodyImports = Collections.emptySet();
-
- JavaStatement methodBody = getMethodBody();
- if (methodBody != null) {
- methodBodyImports = methodBody.getRequiredImports();
+ Iterable<JavaImport> imports =
Iterables.concat(getReturnType().getRequiredImports(),exceptionsImports,argumentsImports);
+ if(null != getMethodBody()){
+ imports = Iterables.concat(imports,getMethodBody().getRequiredImports());
}
-
- Iterable<JavaImport> imports =
Iterables.concat(getReturnType().getRequiredImports(),methodBodyImports,exceptionsImports,argumentsImports);
return imports;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java 2010-07-12
18:50:30 UTC (rev 17982)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java 2010-07-12
18:52:04 UTC (rev 17983)
@@ -33,6 +33,8 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.xmlconfig.model.ClassAdapter;
+import com.google.common.collect.Lists;
+
/**
* <p class="changed_added_4_0"></p>
*
@@ -77,7 +79,7 @@
private ClassName type = new ClassName(Object.class);
@XmlElement(name = "clientBehavior", namespace =
Template.COMPOSITE_NAMESPACE)
- private List<ClientBehavior> clientBehaviors;
+ private List<ClientBehavior> clientBehaviors=Lists.newArrayList();
/**
* <p class="changed_added_4_0"></p>
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-07-12
18:50:30 UTC (rev 17982)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-07-12
18:52:04 UTC (rev 17983)
@@ -36,7 +36,9 @@
import org.richfaces.cdk.xmlconfig.model.ClassAdapter;
import org.richfaces.cdk.xmlconfig.model.FacesIdAdapter;
+import com.google.common.collect.Lists;
+
/**
* <p class="changed_added_4_0"></p>
*
@@ -49,11 +51,11 @@
private FacesId componentFamily;
- private List<Attribute> attributes;
+ private List<Attribute> attributes=Lists.newArrayList();
- private List<ResourceDependency> resourceDependencies;
+ private List<ResourceDependency> resourceDependencies=Lists.newArrayList();
- private List<ImportAttributes> attributesImports;
+ private List<ImportAttributes> attributesImports=Lists.newArrayList();
private String renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-12
18:50:30 UTC (rev 17982)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-12
18:52:04 UTC (rev 17983)
@@ -8,30 +8,22 @@
import org.richfaces.cdk.CdkException;
+import com.google.common.collect.Lists;
+
/**
- * <p class="changed_added_4_0">All classes that are used in template
bodey should be presented
- * in the {@link XmlSeeAlso} annotation </p>
- *
+ * <p class="changed_added_4_0">
+ * All classes that are used in template bodey should be presented in the {@link
XmlSeeAlso} annotation
+ * </p>
+ *
* @author asmirnov(a)exadel.com
*/
-@XmlSeeAlso({
- CdkCallElement.class,
- CdkBodyElement.class,
- CdkIfElement.class,
- CdkObjectElement.class,
- CdkChooseElement.class,
- CdkWhenElement.class,
- CdkOtherwiseElement.class,
- CdkForEachElement.class,
- CdkSwitchElement.class,
- CdkCaseElement.class,
- CdkDefaultElement.class
-})
+@XmlSeeAlso( { CdkCallElement.class, CdkBodyElement.class, CdkIfElement.class,
CdkObjectElement.class,
+ CdkChooseElement.class, CdkWhenElement.class, CdkOtherwiseElement.class,
CdkForEachElement.class,
+ CdkSwitchElement.class, CdkCaseElement.class, CdkDefaultElement.class })
public class ModelFragment implements LeafModelElement {
- private List<Object> children;
+ private List<Object> children = Lists.newArrayList();
- //TODO filter unhandled elements from known namespaces
@XmlAnyElement(lax = true, value = ElementsHandler.class)
@XmlMixed
public List<Object> getChildren() {
@@ -39,9 +31,11 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
- * @param body the body to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param body
+ * the body to set
*/
public void setChildren(List<Object> body) {
this.children = body;
@@ -51,15 +45,13 @@
public void visit(TemplateVisitor visitor) throws CdkException {
beforeVisit(visitor);
List<Object> childrenList = getChildren();
- if (childrenList != null) {
- for (Object child : childrenList) {
- if (child instanceof String) {
- visitor.visitElement((String) child);
- } else if (child instanceof ModelElement) {
- ((ModelElement) child).visit(visitor);
- } else {
- throw new CdkException("Unknown type of element in renderer
template " + child.getClass());
- }
+ for (Object child : childrenList) {
+ if (child instanceof String) {
+ visitor.visitElement((String) child);
+ } else if (child instanceof ModelElement) {
+ ((ModelElement) child).visit(visitor);
+ } else {
+ throw new CdkException("Unknown type of element in renderer template
" + child.getClass());
}
}
afterVisit(visitor);