Menu

setter getter template not working

Help
2011-12-21
2013-04-17
  • Pevdeveloper

    Pevdeveloper - 2011-12-21

    I can't seem to get the templates for getters and setters to work. It it always using something else, but I can't determine what exactly it is using. My template looks like this:

    Name: Setter
    Pattern: void set(\S+)\(+ (+)\)
    Example: void setNumberOfQuestions(int number)

    Template:
    /**
    * Sets the ${e.g(1).rsfl()}.
    *
    * @param ${e.g(2)} the helloworld ${e.g(1).rsfl()}
    */

    My code:
    public void setMyId(String myIdParam) {
    this.myId = myId;
    }

    After running template:
    /**
    * Sets the my id.
    *
    * @param myIdParam the new my id
    */
    public void setMyId(String myIdParam) {
    this.myId = myId;
    }

    There seems to be a similar problem with getters. FWIW I have the same problem with Eclipse (3.7) templates. Getters and setters seem to be ignored.

    Please let me know if I'm doing something wrong.
    Thanks.

     
  • Martin Kesting

    Martin Kesting - 2011-12-27

    Hi,
    Your template seems to be ok. There is an option "etter from field comment". If this option is selected, the related template is ignored. Could this be your problem?

     
  • Pevdeveloper

    Pevdeveloper - 2011-12-28

    Thank-you. That was the problem. Could you provide an explanation of what that parameter is supposed to do?

    Also, on my getter template I had Target - Element Name checked which also caused problems. Perhaps some additional explanation of when to use Element Name and when to use Signature would also be helpful.

    Thanks!

    BTW - I do like this tool! Thanks for creating it! I think it provides value in that it gets a base comment started and you can carefully add more to that base later if necessary.

     
  • Martin Kesting

    Martin Kesting - 2012-01-03

    If the option "etter from field comment" is checked, the setter comment will be created like this:

    /**
    * Sets the <field comment>.
    *
    * @param myIdParam the new <field comment>
    */
    public void setMyId(String myIdParam) {
        this.myId = myId;
    }

    Everything but <field comment> is hard coded and cannot be changed by templates. <field comment> is taken from the Javadoc of the related field.

    "Target" defines what the given Pattern should match:

    Element name: "setMyId"
    Signature: "void setMyId(String myIdParam)"

    With "Signature" checked you can write templates for methods with a specific return type and number of parameters.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.