Modello
  1. Modello
  2. MODELLO-97

Add constants for tags and attributes in xpp3

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major 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 :
      1

      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

        Activity

        Hide
        Herve Boutemy added a comment -

        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?

        Show
        Herve Boutemy added a comment - 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?
        Hide
        Vincent Siveton added a comment -

        We could add these constants in the reader and the writer (similar to WriterFactory.UTF_8 ReaderFactory.UTF_8 from p-u)
        The interface idea could be also a good idea.

        Show
        Vincent Siveton added a comment - We could add these constants in the reader and the writer (similar to WriterFactory.UTF_8 ReaderFactory.UTF_8 from p-u) The interface idea could be also a good idea.

          People

          • Assignee:
            Unassigned
            Reporter:
            Vincent Siveton
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: