Skip to content
Browse files

[Issue 1] Evolution

  • Loading branch information...
1 parent b873f2a commit 22bd1a28093e4533c8dbb8d53afdd69b1dfd1f54 attonnnn committed Sep 28, 2010
View
13 src/main/java/fr/exanpe/tapestry/tldgen/taglib/builder/StructureBuilder.java
@@ -40,6 +40,7 @@
import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
+import fr.exanpe.tapestry.tldgen.utils.TapestryTldGenConstants;
/**
* This class builds the final structure of the taglib to generate
@@ -182,7 +183,17 @@ private Attribute buildAttributeFromField(Field field)
attribute.setDeferredValue(field.getType().getName());
attribute.setRequired(field.getAnnotation(Parameter.class).required());
-
+ attribute.setParameterDescription(buildParameterDescription(field.getAnnotation(Parameter.class)));
+
return attribute;
}
+
+ private String buildParameterDescription(Parameter p){
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(TapestryTldGenConstants.ALLOW_NULL_TXT).append(p.allowNull()).append("\n");
+ builder.append(TapestryTldGenConstants.DEFAULT_PREFIX_TXT).append(p.defaultPrefix()).append("\n");
+
+ return builder.toString();
+ }
}
View
17 src/main/java/fr/exanpe/tapestry/tldgen/taglib/mapping/Attribute.java
@@ -34,6 +34,7 @@
{
/**
* Name of the field. Can be different of the name of the paramter.
+ * Used to bind with Javadoc information
* @see Parameter#name()
*/
@XStreamOmitField
@@ -46,6 +47,12 @@
private String name;
private String description;
+
+ /**
+ * A annotation specific description used to gather information from @Parameter annotation.
+ */
+ @XStreamOmitField
+ private String parameterDescription;
private boolean required;
@@ -98,6 +105,16 @@ public void setDescription(String description)
{
this.description = description;
}
+
+ public String getParameterDescription()
+ {
+ return parameterDescription;
+ }
+
+ public void setParameterDescription(String parameterDescription)
+ {
+ this.parameterDescription = parameterDescription;
+ }
public boolean isRequired()
{
View
2 src/main/java/fr/exanpe/tapestry/tldgen/taglib/writer/TaglibWriterProcessor.java
@@ -68,7 +68,7 @@ private FieldKeySorter getMappingSorter()
{ "description", "name", "tagClass", "bodyContent", "attributes" });
sorter.registerFieldOrder(Attribute.class, new String[]
- { "description", "name", "required", "deferredValue" });
+ { "description", "name", "required", "deferredValue", "parameterDescription", "fieldName"});
return sorter;
}
View
10 src/main/java/fr/exanpe/tapestry/tldgen/utils/JavadocBeanMerger.java
@@ -53,14 +53,18 @@ public static void mergeToTaglib(Taglib taglib, ComponentsInfoBean infos)
ParameterBean param = comp.getParameterByName(a.getFieldName());
+ String description = null;
+
if (param != null)
{
- a.setDescription(param.getDescription());
+ description = param.getDescription();
}
else
{
- a.setDescription(getParentAttributeDescription(comp, a, infos));
+ description = getParentAttributeDescription(comp, a, infos);
}
+
+ a.setDescription(description+"\n"+a.getParameterDescription());
}
}
}
@@ -80,7 +84,7 @@ private static String getParentAttributeDescription(ComponentBean comp, Attribut
{
try
{
- Class c = Class.forName(comp.getClassName());
+ Class<?> c = Class.forName(comp.getClassName());
if (c.getSuperclass() == null) { return null; }
View
10 src/main/java/fr/exanpe/tapestry/tldgen/utils/TapestryTldGenConstants.java
@@ -63,4 +63,14 @@
*/
public final static String[] TAPESTRY_SUPPORTED_SUBPACKAGES = new String[]
{ "base", "components" };
+
+ /**
+ * Allow null String in generation
+ */
+ public static final String ALLOW_NULL_TXT = "Allow null : ";
+
+ /**
+ * Allow null String in generation
+ */
+ public static final String DEFAULT_PREFIX_TXT = "Default prefix : ";
}
View
23 src/test/java/fr/exanpe/tapestry/tldgen/taglib/builder/StructureBuilderTest.java
@@ -29,6 +29,7 @@
import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
+import fr.exanpe.tapestry.tldgen.utils.TapestryTldGenConstants;
import fr.exanpe.test.heritage.components.SubSubComponent;
public class StructureBuilderTest extends TestCase
@@ -86,6 +87,26 @@ public void testParameterName() throws MalformedURLException, MojoExecutionExcep
found |= (a.getName().equals("subnewname") && a.getFieldName().equals("subsubParam"));
}
- assertEquals(true, found);
+ assertTrue(found);
+ }
+
+ /**
+ * Issue 1 Junit
+ * @throws MalformedURLException
+ * @throws MojoExecutionException
+ */
+ public void testParameterInfos() throws MalformedURLException, MojoExecutionException
+ {
+ StructureBuilder builder = new StructureBuilder(new SystemStreamLog());
+
+ Taglib t = builder.build("fr.exanpe.test.heritage", new String[]
+ { "base", "components" }, new URL[]
+ { new File("target/test-classes/").toURI().toURL() });
+
+ Attribute a = t.getTags().get(0).getAttributes().get(0);
+
+ //just all to default
+ assertTrue(a.getParameterDescription().contains(TapestryTldGenConstants.ALLOW_NULL_TXT+"true"));
+ assertTrue(a.getParameterDescription().contains(TapestryTldGenConstants.DEFAULT_PREFIX_TXT+"prop"));
}
}
View
44 src/test/java/fr/exanpe/tapestry/tldgen/taglib/writer/TaglibWriterProcessorTest.java
@@ -21,6 +21,7 @@
import java.io.Writer;
import junit.framework.TestCase;
+import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
@@ -83,4 +84,47 @@ public void testWriteTag() throws IOException
assertTrue(xmlRes.contains("</tag>"));
}
+ public void testWriteAttribute() throws IOException
+ {
+ Writer writer = new StringWriter();
+ TaglibWriterProcessor processor = new TaglibWriterProcessor(writer);
+
+ Taglib taglib = new Taglib();
+ taglib.setShortName("ShortName");
+ taglib.setTaglibVersion("2.12");
+ taglib.setUri("test.com");
+
+
+ Tag tag = new Tag();
+ tag.setName("monTagName");
+ tag.setTagClass("fr.MaClasse");
+ tag.setDescription("Ma description");
+
+
+
+
+ Attribute att = new Attribute();
+ att.setDeferredValue("java.lang.String");
+ att.setDescription("My Attribute");
+ att.setFieldName("fieldName");
+ att.setName("attName");
+ att.setRequired(true);
+ att.setParameterDescription("parameter description");
+
+ tag.getAttributes().add(att);
+ taglib.getTags().add(tag);
+
+ processor.write(taglib);
+
+ String xmlRes = writer.toString();
+
+ assertNotNull(xmlRes);
+ assertNotSame("", xmlRes);
+
+ assertTrue(xmlRes.contains("<attribute>"));
+ assertTrue(xmlRes.contains("<name>attName</name>"));
+ assertTrue(xmlRes.contains("<description>My Attribute</description>"));
+ assertTrue(xmlRes.contains("<required>true</required>"));
+ assertTrue(xmlRes.contains("</attribute>"));
+ }
}

0 comments on commit 22bd1a2

Please sign in to comment.
Something went wrong with that request. Please try again.