Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Eclipse - New Class Boiler Plate

  1. #1
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Eclipse - New Class Boiler Plate

    I am looking at using Eclipse for a project and there are several copy paste requirements for each class, to fit the project requirements.

    I have looked in Window > Preferences > Java > Editor > Templates, and a few other seemingly related areas of the preferences with no luck so far.

    When I create a new class, say A for example, Eclipse creates the following code:
    /**
     * 
     */
    package packagename;
     
     
    /**
     * @author jps
     *
     */
    public class A {
     
    }

    What I would like to have is the following code:
    /** nameThisFileIsSavedAs.Extension */
    package packagename;
     
    /**
     * @author jps
     *
     */
    public class A {
    /* Comment 1 */
    /* Comment 2 */
    /* Comment 3 */
    /* Comment 4 */
    }
    Question #1: How do I get the saved file name and the Comments 1-4 to be generated by eclipse? -or is it not possible?
    Question #2: Is there a way to make the first comment, where the file name goes, appear all on one line (as shown in my desired code sample)?


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Eclipse - New Class Boiler Plate

    Have you tried playing around in Window > Preferences > Java > Code Style, and either Code Template or Formatter?

    In Code Template, you could probably make some changes to Code > Class body for the 4 comments, and Comments > Files for the file name at the top. I have no idea what tags to use to make those things show up, but you can probably figure it out with a bit of tinkering.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    jps (August 14th, 2012)

  4. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Eclipse - New Class Boiler Plate

    For the comments in the body:
    Window > Preferences > Java > Code Style > Code Templates > Code > Class Body > Edit
    /* Comment */


    For the file name:
    Window > Preferences > Java > Code Style > Code Templates > Comments > File > Edit
    /** ${file_name} */

    ${file_name} is the variable, but one does not need to know what to type, you can select what you want from a list.

    Everything turned out as expected, thanks aussiemcgr

Similar Threads

  1. Eclipse not recognizing my method for class.
    By jerryg in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 9th, 2012, 06:52 PM
  2. Beginners Eclipse Tutorial. How to run first java application on Eclipse?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 13
    Last Post: June 24th, 2011, 12:26 AM
  3. How to edit .class files in Eclipse
    By xbill in forum Java IDEs
    Replies: 2
    Last Post: April 22nd, 2011, 02:31 PM
  4. Replies: 5
    Last Post: November 13th, 2010, 01:53 PM