Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.0-alpha-16
-
Fix Version/s: 1.x
-
Component/s: modello-plugin-xpp3
-
Labels:None
-
Complexity:Intermediate
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
I proposed to add constants for tags and attributes, i.e.:
MyGeneratedXpp3Reader.java
public class MavenXpp3Reader { ... /** * Tag name for <code>myTag</code>. */ public static final java.lang.String TAG_MYTAG = "myTag"; /** * Attribute name for <code>myAttribute</code>. */ public static final java.lang.String ATTRIBUTE_MYATTRIBUTE = "myAttribute"; ... }
The patch includes:
- added new methods in Xpp3ReaderGenerator class to handle that: addConstantField(...) and getConstantName(...)
- replaces all tagName/singularTagName by getConstantName(...)
- removed unused import
- updated Xpp3WriterGenerator to use the constants defined in the generated Xpp3Reader class
- added a test case
Note: in src/test/java, the package org.codehaus.modello.generator.xml.xpp3 was moved to org.codehaus.modello.plugin.xpp3 like defined in src/main/java
The idea is interesting: constants should improve generated code (yes, code is generated, there won't be any copy/paste error, but copying/pasting String values is not a good practice).
I have a few concerns about how to implement this idea: why constants in XPP3 only, and not other XML readers/writers? Why constants in reader instead of writer?
Idea: what if modello-plugin-xml generates constants in a separate MavenXmlTags class or interface in io package?
Another concern is about conflicting tag names between multiple classes of the model, or recognizing which tag is for which class.
Shouldn't the constants names contain the class name as a prefix?