[forge-dev] [JBoss JIRA] Issue Comment Edited: (SEAMFORGE-79) When using the new-field command, the getters and setters should be separated from the field to make it more readable.

Pablo Martinez (JIRA) jira-events at lists.jboss.org
Mon Mar 21 21:34:45 EDT 2011


    [ https://issues.jboss.org/browse/SEAMFORGE-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12589505#comment-12589505 ] 

Pablo Martinez edited comment on SEAMFORGE-79 at 3/21/11 9:33 PM:
------------------------------------------------------------------

what about this logic:

when adding a new-field, search for the last field location, and add the field after that one (private String field), then , search for constructors, if there's any, put the getter/setter for the recent added field after all constructors, if no constructor found, put the getter/setter after last field location (in this case the recently added field)

when adding a new-method, just put it at the bottom.

on pseudo pseudo pseudo code:

{code}
if (command.equals("new-field") {
  int fieldLine = searchLastFieldLocation();
  addField(fieldLine + 1);
  constructorLine = searchLastConstructorLocation();
  if (constructorLine != -1 ) //when -1 it indicates no constructor found
    addGetterSetter(constructorLine + 1);
  else{
    addGetterSetter(fieldLine + 2); //+2 instead of +1 to indicate AFTER the recently added field
  }
} else if (command.equals("new-method")) {
  int methodLine = searchLastMethodLocation();
  addMethod(methodLine + 1);
}
{code}

This way, we can be sure that fields go top, constructors after fields, getters/setters after constructors (if any), and other methods always at the bottom.

Of course, if the user mess with the code creating a field at the bottom, or a constructor at top or something like that, it wouldn't work as one would expect, BUT at least it won't break the code, and if the user follows this *CONVENTION* (at least I follow this methodology always), this would help a lot on understanding the code afterwards.

Any idea about this?

      was (Author: pablomartinez):
    what about this logic:

when adding a new-field, search for the last field location, and add the field after that one (private String field), then , search for constructors, if there's any, put the getter/setter for the recent added field after all constructors, if no constructor found, put the getter/setter after last field location (in this case the recently added field)

when adding a new-method, just put it at the bottom.

on pseudo pseudo pseudo code:

{code}
if (method == new-field) {
  int fieldLine = searchLastFieldLocation();
  addField(fieldLine + 1);
  constructorLine = searchLastConstructorLocation();
  if (constructorLine != -1 ) //when -1 it indicates no constructor found
    addGetterSetter(constructorLine + 1);
  else{
    addGetterSetter(fieldLine + 2); //+2 instead of +1 to indicate AFTER the recently added field
  }
} else if (method == new-method) {
  int methodLine = searchLastMethodLocation();
  addMethod(methodLine + 1);
}
{code}

This way, we can be sure that fields go top, constructors after fields, getters/setters after constructors (if any), and other methods always at the bottom.

Of course, if the user mess with the code creating a field at the bottom, or a constructor at top or something like that, it wouldn't work as one would expect, BUT at least it won't break the code, and if the user follows this *CONVENTION* (at least I follow this methodology always), this would help a lot on understanding the code afterwards.

Any idea about this?
  
> When using the new-field command, the getters and setters should be separated from the field to make it more readable.
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: SEAMFORGE-79
>                 URL: https://issues.jboss.org/browse/SEAMFORGE-79
>             Project: Seam Forge
>          Issue Type: Feature Request
>          Components: Brainstorming
>    Affects Versions: 1.0.0.Alpha1, 1.0.0.Alpha2, 1.0.0.Alpha3
>            Reporter: Pablo Martinez
>            Priority: Optional
>
> When using the new-field command, the getters and setters should be separated from the fields, to make the java class more readable after using seamforge.
> An idea is to separate every java class in 4 parts: Field block, Constructor block, Getter/Setter block and Method block, using some arbitrary sintax (for easy parsing maybe?), for example something like:
> {code}
> @Entity
> public class User {
>   /* [FIELDS] */
>   private int id;
>   private String username;
>   private String password;
>   /* [CONSTRUCTORS] */
>   public User() {
>   }
>   public User(String username, String password) {
>   }
>   /* [GETTERS/SETTERS] */
>   public String getUsername() {
>     return this.username;
>   }
>   public void setUsername(final String username) {
>     this.username = username;
>   }
>   //etc...
>   /* [METHODS] */
>   public void doSomething() { }
>   public boolean equals(User other) { return false; }
>   //etc...  
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the forge-dev mailing list