Eclipse JUtils toString() Logo

JUtils ToString Generator Plugin for Eclipse
 


7th July 2007: Version 3.1 of JUtils ToString Generator for Eclipse rolls out into production! This is yet another refinement to the world's favourite toString() generator plugin for Eclipse.

This version fixes a critical bug that used to occur when the plugin was used on Eclipse Europa (Eclipse 3.3). Also fixed is another minor bug which was showing up under special circumstances.

Please see the Change History page for a more detailed discussion.

The plugin has been rigorously tested on Eclipse versions 3.0, 3.1, 3.2 and 3.3 and it works simply robustly! Go ahead, download a copy right now and start toStringing.

If you think visually, Screenshots is the right place for you to start exploring the features of the plugin.

TOP You can generate code as shown below in an instant for hundreds of Java classes, all at once! Generating toString() implementation or Copy Constructor had never been simpler.

Depending on your needs, toString() or Copy Constructor can be generated in one of the following ways for your Java Classes:

  • Single Public Class: Open Package Explorer in Java Perspective, right click on the Java File which contains this class and select either JUtils >> Generate toString() or JUtils >> Generate Copy Constructor from the context menu, depending on what you need.


  • Single Public/Non-Public/Nested/Inner Class: Open the Java File containing the Class in the Java Editor and right click after placing the caret (keyboard cursor or 'I' cursor) within the Class. You should be seeing an entry by name JUtils at the end of the context. Click JUtils >> Generate toString() or JUtils >> Generate Copy Constructor from this context menu, depending on your need.


  • Multiple Public Classes Under A Single Package: Open Package Explorer in Java Perspective. Select all the Classes (under any one package at a time) for which toString() or Copy Constructor is desired. Right click, select either JUtils >> Generate toString() or JUtils >> Generate Copy Constructor from the context menu to do a batch code generation.

- hide

    /**
     * Constructs a <code>String</code>with all attributes
     * in name = value format.
     * 
     * @return a <code>String</code> representation
     * of this object.
     */
    public String toString()
    {
        final String TAB = "    ";
        
        String retValue = "";
        
        retValue = "Person ( "
            + super.toString() + TAB
            + "name = " + this.name + TAB
            + "age = " + this.age + TAB
            + "height = " + this.height + TAB
            + "weight = " + this.weight + TAB
            + "salary = " + this.salary + TAB
            + "address = " + this.address + TAB
            + " )";
        
        return retValue;
    }

Alternately, if you don't want so much of string concatenation happening in your code, you can always switch to either StringBuffer or StringBuilder mode.

This can be configured using the plugin's preference page.

The same code generated using StringBuffer would look like this.

- hide

    /**
     * Constructs a <code>String</code> with all attributes
     * in name = value format.
     * 
     * @return a <code>String</code> representation
     * of this object.
     */
    public String toString()
    {
        final String TAB = "    ";
        
        StringBuffer retValue = new StringBuffer();
        
        retValue.append("Person ( ")
            .append(super.toString()).append(TAB)
            .append("name = ").append(this.name).append(TAB)
            .append("age = ").append(this.age).append(TAB)
            .append("height = ").append(this.height).append(TAB)
            .append("weight = ").append(this.weight).append(TAB)
            .append("salary = ").append(this.salary).append(TAB)
            .append("address = ").append(this.address).append(TAB)
            .append(" )");
        
        return retValue.toString();
    }
TOP The instructions for generating Copy Constructor remain same as those for toString(). However, in this case, there is only one mode. Following is a sample of the code generated.

- hide

    /**
     * Copy Constructor.
     * 
     * @param person a <code>Person</code> object.
     */
    public Person(Person person)
    {
        this.name = person.name;
        this.age = person.age;
        this.height = person.height;
        this.weight = person.weight;
        this.salary = person.salary;
        this.address = person.address;
    }
TOP Eclipse - 3.0, 3.1, 3.2 and 3.3
Operating System - Windows, UNIX (whichever can run Eclipse)
Java Version - 1.4.2 and above.