Skip to content
This repository
Browse code

[Issue 1] Evolution

  • Loading branch information...
commit 22bd1a28093e4533c8dbb8d53afdd69b1dfd1f54 1 parent b873f2a
attonnnn authored
13 src/main/java/fr/exanpe/tapestry/tldgen/taglib/builder/StructureBuilder.java
@@ -40,6 +40,7 @@
40 40 import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
41 41 import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
42 42 import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
  43 +import fr.exanpe.tapestry.tldgen.utils.TapestryTldGenConstants;
43 44
44 45 /**
45 46 * This class builds the final structure of the taglib to generate
@@ -182,7 +183,17 @@ private Attribute buildAttributeFromField(Field field)
182 183
183 184 attribute.setDeferredValue(field.getType().getName());
184 185 attribute.setRequired(field.getAnnotation(Parameter.class).required());
185   -
  186 + attribute.setParameterDescription(buildParameterDescription(field.getAnnotation(Parameter.class)));
  187 +
186 188 return attribute;
187 189 }
  190 +
  191 + private String buildParameterDescription(Parameter p){
  192 + StringBuilder builder = new StringBuilder();
  193 +
  194 + builder.append(TapestryTldGenConstants.ALLOW_NULL_TXT).append(p.allowNull()).append("\n");
  195 + builder.append(TapestryTldGenConstants.DEFAULT_PREFIX_TXT).append(p.defaultPrefix()).append("\n");
  196 +
  197 + return builder.toString();
  198 + }
188 199 }
17 src/main/java/fr/exanpe/tapestry/tldgen/taglib/mapping/Attribute.java
@@ -34,6 +34,7 @@
34 34 {
35 35 /**
36 36 * Name of the field. Can be different of the name of the paramter.
  37 + * Used to bind with Javadoc information
37 38 * @see Parameter#name()
38 39 */
39 40 @XStreamOmitField
@@ -46,6 +47,12 @@
46 47 private String name;
47 48
48 49 private String description;
  50 +
  51 + /**
  52 + * A annotation specific description used to gather information from @Parameter annotation.
  53 + */
  54 + @XStreamOmitField
  55 + private String parameterDescription;
49 56
50 57 private boolean required;
51 58
@@ -98,6 +105,16 @@ public void setDescription(String description)
98 105 {
99 106 this.description = description;
100 107 }
  108 +
  109 + public String getParameterDescription()
  110 + {
  111 + return parameterDescription;
  112 + }
  113 +
  114 + public void setParameterDescription(String parameterDescription)
  115 + {
  116 + this.parameterDescription = parameterDescription;
  117 + }
101 118
102 119 public boolean isRequired()
103 120 {
2  src/main/java/fr/exanpe/tapestry/tldgen/taglib/writer/TaglibWriterProcessor.java
@@ -68,7 +68,7 @@ private FieldKeySorter getMappingSorter()
68 68 { "description", "name", "tagClass", "bodyContent", "attributes" });
69 69
70 70 sorter.registerFieldOrder(Attribute.class, new String[]
71   - { "description", "name", "required", "deferredValue" });
  71 + { "description", "name", "required", "deferredValue", "parameterDescription", "fieldName"});
72 72
73 73 return sorter;
74 74 }
10 src/main/java/fr/exanpe/tapestry/tldgen/utils/JavadocBeanMerger.java
@@ -53,14 +53,18 @@ public static void mergeToTaglib(Taglib taglib, ComponentsInfoBean infos)
53 53
54 54 ParameterBean param = comp.getParameterByName(a.getFieldName());
55 55
  56 + String description = null;
  57 +
56 58 if (param != null)
57 59 {
58   - a.setDescription(param.getDescription());
  60 + description = param.getDescription();
59 61 }
60 62 else
61 63 {
62   - a.setDescription(getParentAttributeDescription(comp, a, infos));
  64 + description = getParentAttributeDescription(comp, a, infos);
63 65 }
  66 +
  67 + a.setDescription(description+"\n"+a.getParameterDescription());
64 68 }
65 69 }
66 70 }
@@ -80,7 +84,7 @@ private static String getParentAttributeDescription(ComponentBean comp, Attribut
80 84 {
81 85 try
82 86 {
83   - Class c = Class.forName(comp.getClassName());
  87 + Class<?> c = Class.forName(comp.getClassName());
84 88
85 89 if (c.getSuperclass() == null) { return null; }
86 90
10 src/main/java/fr/exanpe/tapestry/tldgen/utils/TapestryTldGenConstants.java
@@ -63,4 +63,14 @@
63 63 */
64 64 public final static String[] TAPESTRY_SUPPORTED_SUBPACKAGES = new String[]
65 65 { "base", "components" };
  66 +
  67 + /**
  68 + * Allow null String in generation
  69 + */
  70 + public static final String ALLOW_NULL_TXT = "Allow null : ";
  71 +
  72 + /**
  73 + * Allow null String in generation
  74 + */
  75 + public static final String DEFAULT_PREFIX_TXT = "Default prefix : ";
66 76 }
23 src/test/java/fr/exanpe/tapestry/tldgen/taglib/builder/StructureBuilderTest.java
@@ -29,6 +29,7 @@
29 29 import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
30 30 import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
31 31 import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
  32 +import fr.exanpe.tapestry.tldgen.utils.TapestryTldGenConstants;
32 33 import fr.exanpe.test.heritage.components.SubSubComponent;
33 34
34 35 public class StructureBuilderTest extends TestCase
@@ -86,6 +87,26 @@ public void testParameterName() throws MalformedURLException, MojoExecutionExcep
86 87 found |= (a.getName().equals("subnewname") && a.getFieldName().equals("subsubParam"));
87 88 }
88 89
89   - assertEquals(true, found);
  90 + assertTrue(found);
  91 + }
  92 +
  93 + /**
  94 + * Issue 1 Junit
  95 + * @throws MalformedURLException
  96 + * @throws MojoExecutionException
  97 + */
  98 + public void testParameterInfos() throws MalformedURLException, MojoExecutionException
  99 + {
  100 + StructureBuilder builder = new StructureBuilder(new SystemStreamLog());
  101 +
  102 + Taglib t = builder.build("fr.exanpe.test.heritage", new String[]
  103 + { "base", "components" }, new URL[]
  104 + { new File("target/test-classes/").toURI().toURL() });
  105 +
  106 + Attribute a = t.getTags().get(0).getAttributes().get(0);
  107 +
  108 + //just all to default
  109 + assertTrue(a.getParameterDescription().contains(TapestryTldGenConstants.ALLOW_NULL_TXT+"true"));
  110 + assertTrue(a.getParameterDescription().contains(TapestryTldGenConstants.DEFAULT_PREFIX_TXT+"prop"));
90 111 }
91 112 }
44 src/test/java/fr/exanpe/tapestry/tldgen/taglib/writer/TaglibWriterProcessorTest.java
@@ -21,6 +21,7 @@
21 21 import java.io.Writer;
22 22
23 23 import junit.framework.TestCase;
  24 +import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
24 25 import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
25 26 import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
26 27
@@ -83,4 +84,47 @@ public void testWriteTag() throws IOException
83 84 assertTrue(xmlRes.contains("</tag>"));
84 85 }
85 86
  87 + public void testWriteAttribute() throws IOException
  88 + {
  89 + Writer writer = new StringWriter();
  90 + TaglibWriterProcessor processor = new TaglibWriterProcessor(writer);
  91 +
  92 + Taglib taglib = new Taglib();
  93 + taglib.setShortName("ShortName");
  94 + taglib.setTaglibVersion("2.12");
  95 + taglib.setUri("test.com");
  96 +
  97 +
  98 + Tag tag = new Tag();
  99 + tag.setName("monTagName");
  100 + tag.setTagClass("fr.MaClasse");
  101 + tag.setDescription("Ma description");
  102 +
  103 +
  104 +
  105 +
  106 + Attribute att = new Attribute();
  107 + att.setDeferredValue("java.lang.String");
  108 + att.setDescription("My Attribute");
  109 + att.setFieldName("fieldName");
  110 + att.setName("attName");
  111 + att.setRequired(true);
  112 + att.setParameterDescription("parameter description");
  113 +
  114 + tag.getAttributes().add(att);
  115 + taglib.getTags().add(tag);
  116 +
  117 + processor.write(taglib);
  118 +
  119 + String xmlRes = writer.toString();
  120 +
  121 + assertNotNull(xmlRes);
  122 + assertNotSame("", xmlRes);
  123 +
  124 + assertTrue(xmlRes.contains("<attribute>"));
  125 + assertTrue(xmlRes.contains("<name>attName</name>"));
  126 + assertTrue(xmlRes.contains("<description>My Attribute</description>"));
  127 + assertTrue(xmlRes.contains("<required>true</required>"));
  128 + assertTrue(xmlRes.contains("</attribute>"));
  129 + }
86 130 }

0 comments on commit 22bd1a2

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