Announcement Announcement Module
Collapse
No announcement yet.
How to add comments to my fields using roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add comments to my fields using roo

    I am using roo's 'field' command to create fields for my entities. I would like to comment my fields and it would appear that the --comment option would be the best way to do it. However, when I run a command such as the following:
    Code:
    field string --fieldName description --notNull --sizeMax 500 --class ~.domain.Implementation --comment "A useful description of the implementation for the feature"
    I don't see this comment located anywhere in my project; it's not above either of the getters or setters that are in the auto-generated *.aj files nor is it above private member variable in the Implementation class.

    I suppose I wouldn't mind creating the javadoc by hand, but the only logical place to put it would be in the *.aj files that contain the getter and setter definitions. However, I shouldn't be editing this file as it is managed by roo and it would seem silly just to push the method definitions into the .java file just so I can customize my javadoc commments.

    Here are my specific questions:
    1. Does the --comment option work?
    2. How can I continually tweak my javadoc comments in a way that won't get them overwritten the next time roo manages one of its auto-generated files?

    Thanks!

  • #2
    Hi,

    Let's see.
    First let's find comment option in sources
    Code:
    grep -lr "@CliOption(key = \"comment\"" .
    ./classpath/src/main/java/org/springframework/roo/classpath/operations/FieldCommands.java
    Take a look at this class you will see mentioned option, then what hapens with this field?
    Code:
    if (comment != null) {
      fieldDetails.setComment(comment);
    }
    ...
    insertField(fieldDetails, permitReservedWords, transientModifier);
    ...
    private void insertField(final FieldDetails fieldDetails,
                final boolean permitReservedWords, final boolean transientModifier) {  // line 588
    
    if (!permitReservedWords) {
                ReservedWords.verifyReservedWordsNotPresent(fieldDetails
                        .getFieldName());
                if (fieldDetails.getColumn() != null) {
                    ReservedWords.verifyReservedWordsNotPresent(fieldDetails
                            .getColumn());
                }
            }
    
            final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
            fieldDetails.decorateAnnotationsList(annotations);
            String initializer = null;
            if (fieldDetails instanceof CollectionField) {
                final CollectionField collectionField = (CollectionField) fieldDetails;
                initializer = "new " + collectionField.getInitializer() + "()";
            }
            else if (fieldDetails instanceof DateField
                    && fieldDetails.getFieldName().getSymbolName()
                            .equals("created")) {
                initializer = "new Date()";
            }
            int modifier = Modifier.PRIVATE;
            if (transientModifier) {
                modifier += Modifier.TRANSIENT;
            }
    
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
                    fieldDetails.getPhysicalTypeIdentifier(), modifier,
                    annotations, fieldDetails.getFieldName(),
                    fieldDetails.getFieldType());
            fieldBuilder.setFieldInitializer(initializer);
            typeManagementService.addField(fieldBuilder.build());
        }
    There is no fieldDetail - comment operations.
    So I guess that this command is not handled. But I can be wrong ...

    Your second question, if comment will be generated to *.aj files so update comment is easy.
    Delete field and create new one with new comment. Or push that method to *.java file and write your comment manualy.

    Valerian

    Comment


    • #3
      Hi,
      Found declaration in classpath/src/main/java/org/springframework/roo/classpath/operations/jsr303/FieldDetails.java

      Code:
      /** Any JavaDoc comments (reserved for future expansion) */
      protected String comment = "";
      So you can suggest some ideas to this expansion. Like where to place this comment and so on.

      Valerian

      Comment


      • #4
        /** Any JavaDoc comments (reserved for future expansion) */
        protected String comment = "";

        Comment


        • #5
          So the --comment options isn't supported? Why would the option be in the documented behavior of roo if it didn't actually do anything? Seems like a bug to me.

          Comment


          • #6
            Well I found some issue on this already ... see
            https://jira.springsource.org/browse/ROO-546
            https://jira.springsource.org/browse/ROO-635

            valerian

            Comment


            • #7
              This may have worked in the beginning, but have never ever got it to work since I took up Roo one and a half year ago or so. So I gave it up a long time ago and forgot about it.

              Comment


              • #8
                Hi,

                thanks for reply.
                Tried to solve that but unfortunately I am not strong enough to solve this yet.
                ( I have hard times to customize roo for my own purposes, with no documentation for core components and addons )

                Comment

                Working...
                X