Author: awiner
Date: Mon Aug 7 17:43:54 2006
New Revision: 429529
URL: http://svn.apache.org/viewvc?rev=429529&view=rev
Log:
Commit improvents that reduce Java 5 warnings from Simon Lessard's patch
Modified:
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/AttributeBean.java
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
Modified:
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java?rev=429529&r1=429528&r2=429529&view=diff
==============================================================================
---
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
(original)
+++
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
Mon Aug 7 17:43:54 2006
@@ -19,7 +19,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
-
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,7 +30,11 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
import org.apache.myfaces.trinidadbuild.plugin.faces.parse.EventBean;
@@ -45,9 +48,6 @@
import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate;
import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-
/**
* @version $Id$
* @requiresDependencyResolution compile
@@ -126,7 +126,7 @@
ComponentBean component)
{
String fullClassName = component.getComponentClass();
-
+
try
{
getLog().debug("Generating " + fullClassName);
@@ -429,7 +429,18 @@
PropertyBean property = (PropertyBean)properties.next();
String propertyClass = property.getPropertyClass();
if (propertyClass != null)
+ {
imports.add(propertyClass);
+ // Check for generics
+ String[] types = property.getAttributeClassParameters();
+ if(types != null)
+ {
+ for(int i = types.length - 1; i >= 0; i--)
+ {
+ _addGenericImports(imports, types[i]);
+ }
+ }
+ }
// ComponentUtils only needed for resolvable properties
if (resolvable.accept(property))
@@ -483,6 +494,26 @@
writeImports(out, packageName, imports);
}
+
+ private void _addGenericImports(Set imports, String type)
+ {
+ Matcher matcher = _GENERIC_TYPE.matcher(type);
+ if(matcher.matches())
+ {
+ // Generic type
+ imports.add(matcher.group(1));
+ String[] types = matcher.group(2).split(",");
+ for(int i = types.length - 1; i >= 0; i--)
+ {
+ _addGenericImports(imports, types[i]);
+ }
+ }
+ else
+ {
+ // Non-generic type
+ imports.add(type);
+ }
+ }
private void _writeGenericConstants(
PrettyWriter out,
@@ -715,6 +746,7 @@
PrettyWriter out) throws IOException
{
out.println();
+ out.println("@Override");
out.println("public String getFamily()");
out.println("{");
out.indent();
@@ -727,6 +759,7 @@
PrettyWriter out) throws IOException
{
out.println();
+ out.println("@Override");
out.println("protected FacesBean.Type getBeanType()");
out.println("{");
out.indent();
@@ -847,21 +880,23 @@
PrettyWriter out,
PropertyBean property) throws IOException
{
- _writePropertySet(out, property, property.getPropertyClass());
+ String propertyClass = Util.getPropertyClass(property);
+ _writePropertySet(out, property, propertyClass);
- String alternateClass = property.getAlternateClass();
- if (alternateClass != null)
+ if (property.getAlternateClass() != null)
+ {
+ String alternateClass = Util.getAlternatePropertyClass(property);
_writePropertySet(out, property, alternateClass);
+ }
}
private void _writePropertySet(
PrettyWriter out,
PropertyBean property,
- String propertyFullClass) throws IOException
+ String propertyClass) throws IOException
{
String propName = property.getPropertyName();
String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propertyClass = Util.getClassFromFullClass(propertyFullClass);
String propVar = Util.getVariableFromName(propName);
String description = property.getDescription();
String setMethod = Util.getPrefixedPropertyName("set", propName);
@@ -918,10 +953,18 @@
String propertyClass = Util.getClassFromFullClass(propertyFullClass);
String description = property.getDescription();
String getMethod = Util.getMethodReaderFromProperty(propName,
propertyClass);
-
+
+ boolean isUnchecked = false;
+ String[] genericTypes = property.getPropertyClassParameters();
+ if(genericTypes != null && genericTypes.length > 0)
+ {
+ isUnchecked = true;
+ propertyClass = Util.getPropertyClass(property);
+ }
+
out.println();
out.println("/**");
- if (description != null)
+ if (description != null)
{
out.println(" * Gets " + convertMultilineComment(description));
}
@@ -929,12 +972,18 @@
{
out.println(" * <p>");
out.println(" * This is a required property on the component.");
+ out.println(" * </p>");
}
// TODO: put this back in
//out.println(" *");
//out.println(" * @return the new " + propName + " value");
out.println(" */");
+ if(isUnchecked)
+ {
+ out.println("@SuppressWarnings(\"unchecked\")");
+ }
+
out.println("final public " + propertyClass + " " + getMethod + "()");
out.println("{");
out.indent();
@@ -964,13 +1013,21 @@
}
else
{
- out.println("return (" + propertyClass + ")" +
- "(getProperty(" + propKey + "));");
+ if(propertyClass.equals("Object"))
+ {
+ // Cast is not necessary if the property class is Object
+ out.println("return getProperty(" + propKey + ");");
+ }
+ else
+ {
+ out.println("return (" + propertyClass + ")" +
+ "getProperty(" + propKey + ");");
+ }
}
out.unindent();
out.println("}");
}
-
+
private void _writeFacetMethods(
PrettyWriter out,
ComponentBean component) throws IOException
@@ -1011,6 +1068,11 @@
//out.println(" * @param " + facetVar + " the new " + facetName + "
facet");
out.println(" */");
+ // Remove type safety warning since getFacets is not generics enabled
+ // under JSF 1.1 spec
+ // TODO: Remove this line when Trinidad switch to JSF 1.2
+ out.println("@SuppressWarnings(\"unchecked\")");
+
out.println("final public void " + setMethod + "(UIComponent " + facetVar
+ ")");
out.println("{");
out.indent();
@@ -1323,5 +1385,6 @@
*/
private boolean suppressListenerMethods;
+ static private final Pattern _GENERIC_TYPE =
Pattern.compile("([^<]+)<(.+)>");
static final private Map _RESOLVABLE_TYPES = _createResolvableTypes();
}
Modified:
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/AttributeBean.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/AttributeBean.java?rev=429529&r1=429528&r2=429529&view=diff
==============================================================================
---
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/AttributeBean.java
(original)
+++
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/AttributeBean.java
Mon Aug 7 17:43:54 2006
@@ -212,6 +212,7 @@
private String[] _attributeClassParameters;
private String _description;
private String _defaultValue;
+ // FIXME: Alternate type does not seem to support generic types
private String _alternateClass;
private boolean _virtual;
private MethodSignatureBean _signature;
Modified:
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java?rev=429529&r1=429528&r2=429529&view=diff
==============================================================================
---
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
(original)
+++
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
Mon Aug 7 17:43:54 2006
@@ -19,6 +19,10 @@
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
public class Util
{
@@ -100,6 +104,33 @@
return prefix + Character.toUpperCase(propertyName.charAt(0)) +
propertyName.substring(1);
}
+
+ static public String getPropertyClass(PropertyBean property)
+ {
+ String propertyFullClass = property.getPropertyClass();
+ String propertyClass = Util.getClassFromFullClass(propertyFullClass);
+ String[] genericTypes = property.getPropertyClassParameters();
+ if(genericTypes != null && genericTypes.length > 0)
+ {
+ StringBuffer buffer = new StringBuffer(60);
+ buffer.append(propertyClass);
+ buffer.append('<');
+ int max = genericTypes.length - 1;
+ for(int i = 0; i <= max; i++)
+ {
+ _buildPropertyClass(buffer, genericTypes[i]);
+ if(i < max)
+ {
+ buffer.append(", ");
+ }
+ }
+ buffer.append('>');
+
+ propertyClass = buffer.toString();
+ }
+
+ return propertyClass;
+ }
static public String getMethodNameFromEvent(
String methodPrefix,
@@ -140,6 +171,14 @@
"long".equals(className) ||
"short".equals(className);
}
+
+ static public String getAlternatePropertyClass(PropertyBean property)
+ {
+ StringBuffer buffer = new StringBuffer(60);
+ _buildPropertyClass(buffer, property.getAlternateClass());
+
+ return buffer.toString();
+ }
static public String getBoxedClass(
String className)
@@ -215,6 +254,33 @@
return name;
}
+ static private void _buildPropertyClass(StringBuffer buffer, String type)
+ {
+ Matcher matcher = _GENERIC_TYPE.matcher(type);
+ if(matcher.matches())
+ {
+ // Generic type
+ buffer.append(Util.getClassFromFullClass(matcher.group(1)));
+ buffer.append('<');
+ String[] types = matcher.group(2).split(",");
+ int max = types.length - 1;
+ for(int i = 0; i <= max; i++)
+ {
+ _buildPropertyClass(buffer, types[i]);
+ if(i < max)
+ {
+ buffer.append(", ");
+ }
+ }
+ buffer.append('>');
+ }
+ else
+ {
+ // Non-generic type
+ buffer.append(Util.getClassFromFullClass(type));
+ }
+ }
+
static private Set _createPrimitiveTypesSet()
{
Set primitives = new TreeSet();
@@ -239,7 +305,7 @@
}
static private final String[] _PRIMITIVE_TYPES = new String[]
- {
+ {// TODO: Shouldn't java.lang.* be specified in that list as well?
"boolean",
"byte",
"char",
@@ -304,6 +370,8 @@
static public final Set RESERVED_WORDS = _createReservedWordsSet();
static public final Set PRIMITIVE_TYPES = _createPrimitiveTypesSet();
+
+ static private final Pattern _GENERIC_TYPE =
Pattern.compile("([^<]+)<(.+)>");
// no instances
private Util()