Please find attached is an enhanced(?) version of Javier's
"jde-wiz-get-set-methods"
prototype. Give it a try....(at your own risk).

Enhancements -

        1. Do not ignore "non-public final" variables.
           Generate "accessors" for final variables if not already defined.

        2. Print a report of accessors and mutators

E.g.

Given a source file -

public class GetSetMethodGeneratorTest {

        private int intVar;
        protected static int staticIntVar;
        static final int staticFinalIntVar;
        
        boolean booleanVar;
        private static boolean staticBooleanVar;
        protected static final boolean staticFinalBooleanVar;
        
}// GetSetMethodGeneratorTest

Running 'jde-wiz-get-set-methods' once gives this report in
buffer named *jde-wiz-get-set-methods report for GetSetMethodGeneratorTest*
-

Variable : (private) int intVar
        Accessor: [Added ]
        Mutator: [Added ]
Variable : (protected static) int staticIntVar
        Accessor: [Added ]
        Mutator: [Added ]
Variable : (static final) int staticFinalIntVar
        Accessor: [Added ]
        Mutator: [N/A   ] variable is final
Variable : nil boolean booleanVar
        Accessor: [Added ]
        Mutator: [Added ]
Variable : (private static) boolean staticBooleanVar
        Accessor: [Added ]
        Mutator: [Added ]
Variable : (protected static final) boolean staticFinalBooleanVar
        Accessor: [Added ]
        Mutator: [N/A   ] variable is final

The new source buffer looks like -

public class GetSetMethodGeneratorTest {

        private int intVar;
        protected static int staticIntVar;
        static final int staticFinalIntVar;
        
        boolean booleanVar;
        private static boolean staticBooleanVar;
        protected static final boolean staticFinalBooleanVar;
        

        /**
         * Gets the value of intVar
         *
         * @return the value of intVar
         */
        public int getIntVar() {
                return this.intVar;
        }

        /**
         * Sets the value of intVar
         *
         * @param intVar Value to assign to this.intVar
         */
        public void setIntVar(int intVar) {
                this.intVar = intVar;
        }

        /**
         * Gets the value of staticIntVar
         *
         * @return the value of staticIntVar
         */
        public static int getStaticIntVar() {
                return GetSetMethodGeneratorTest.staticIntVar;
        }

        /**
         * Sets the value of staticIntVar
         *
         * @param staticIntVar Value to assign to this.staticIntVar
         */
        public static void setStaticIntVar(int staticIntVar) {
                GetSetMethodGeneratorTest.staticIntVar = staticIntVar;
        }

        /**
         * Gets the value of staticFinalIntVar
         *
         * @return the value of staticFinalIntVar
         */
        public static int getStaticFinalIntVar() {
                return GetSetMethodGeneratorTest.staticFinalIntVar;
        }

        /**
         * Gets the value of booleanVar
         *
         * @return the value of booleanVar
         */
        public boolean isBooleanVar() {
                return this.booleanVar;
        }

        /**
         * Sets the value of booleanVar
         *
         * @param booleanVar Value to assign to this.booleanVar
         */
        public void setBooleanVar(boolean booleanVar) {
                this.booleanVar = booleanVar;
        }

        /**
         * Gets the value of staticBooleanVar
         *
         * @return the value of staticBooleanVar
         */
        public static boolean isStaticBooleanVar() {
                return GetSetMethodGeneratorTest.staticBooleanVar;
        }

        /**
         * Sets the value of staticBooleanVar
         *
         * @param staticBooleanVar Value to assign to this.staticBooleanVar
         */
        public static void setStaticBooleanVar(boolean staticBooleanVar) {
                GetSetMethodGeneratorTest.staticBooleanVar =
staticBooleanVar;
        }

        /**
         * Gets the value of staticFinalBooleanVar
         *
         * @return the value of staticFinalBooleanVar
         */
        public static boolean isStaticFinalBooleanVar() {
                return GetSetMethodGeneratorTest.staticFinalBooleanVar;
        }
}// GetSetMethodGeneratorTest

Running 'jde-wiz-get-set-methods' it again gives this report in
buffer named *jde-wiz-get-set-methods report for GetSetMethodGeneratorTest*
-

Variable : (private) int intVar
        Accessor: [Exists]
        Mutator: [Exists]
Variable : (protected static) int staticIntVar
        Accessor: [Exists]
        Mutator: [Exists]
Variable : (static final) int staticFinalIntVar
        Accessor: [Exists]
        Mutator: [N/A   ] variable is final
Variable : nil boolean booleanVar
        Accessor: [Exists]
        Mutator: [Exists]
Variable : (private static) boolean staticBooleanVar
        Accessor: [Exists]
        Mutator: [Exists]
Variable : (protected static final) boolean staticFinalBooleanVar
        Accessor: [Exists]
        Mutator: [N/A   ] variable is final

I hope people enjoy this...

regards,
-sandip

> -----Original Message-----
> From: Javier Lopez [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 25, 2001 10:59 PM
> To: [EMAIL PROTECTED]
> Subject: RE: auto-gen get/set pairs for existing class variables
> 
> 
> Here is the prototype I promised.
> The method jde-wiz-get-set-methods
> will generate get/set method for all variables that
> are non public and non final declared in the current buffer.
> If the method is already defined in the buffer it won't be generated.
> The methods generated look like this
> 
>   /**
>    * Gets the value of name
>    *
>    * @return the value of name
>    */
>   public String getName() {
>     return this.name;
>   }
> 
>   /**
>    * Sets the value of name
>    *
>    * @param name Value to assign to this.name
>    */
>   public void setName(String name) {
>     this.name = name;
>   }
> 
> Javier

-sandip

Sandip V. Chitale                               150, Almaden Blvd
Software Architect                      San Jose, CA, USA
work:  (408) 535 1791 ext: 791
email: [EMAIL PROTECTED]        web:   http://www.brokat.com

jde-wiz.el

Reply via email to