|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
| ConflictResolutionPolicy | Interface that defines a policy for dealing with conflicts (i.e., the user is
trying to generate a Object.toString() method but one already exists in
this class. |
| Class Summary | |
| CancelPolicy | |
| Config | Configuration. |
| ConfigUI | Configuration User Interface. |
| DuplicatePolicy | |
| FieldElement | This is a field element containing information about the field. |
| FieldElementFactory | Factory for creating FieldElement objects. |
| GenerateToStringAction | The IDEA action for this plugin. |
| GenerateToStringPlugin | The IDEA component for this plugin. |
| MethodExistsDialog | This is a dialog when the toString() method already exists. |
| PsiUtil | Utility methods accessing the IDEA PSI API (Program Structure Information). |
| ReplacePolicy | |
| Exception Summary | |
| GenerateCodeException | Error generating the javacode for the toString method. |
toString() method.
The reason is valuebeans usually needs to dump their fieldvalues for debug purpose, and it's tedious to write
the dump code for this. So this action plugin generates the code to dump all the fields in a simple manner.
In the code below we need to override the public toString method so the fields can be dumped:
public class MyServerConfigBean {
private String name;
private String url;
private int port;
private String[] validIPs;
...
}
After invoking the GenerateToString action the bean is now added with the following method
public String toString() {
return "MyServerConfigBean{" +
"name='" + name + "'" +
", url='" + url + "'" +
", port=" + port +
", validIPs=" + (validIPs == null ? null : "length:" + validIPs.length + Arrays.asList(validIPs)) +
"}";
}
And if you change the fields you can run the action again and have it update the toString() method.
In this situation where the toString() method already exists a dialog is displayed with options to:
toString() method, so you'll have duplicate methods
Cancel
| field | description | |
| $classname | the name of the class | |
| $fields | list of | |
| $field | the | |
| $field.name | the name of the field | |
| $field.array | is the field an array type? | |
| $field.primitiveArray | is the field a primitve array type? (int[], short[], float[] etc.) | |
| $field.objectArray | is the field an Object array type? (Object[], String[] etc.) | |
| $field.collection | is the field a Collection type? (is assignable from java.util.Map) | |
| $field.map | is the field a Map type? (is assignable from java.util.Map) | |
| $field.primitive | is the field a primitive type? (int, byte, long, etc.) | |
| $field.constant | is the field a constant type? (it's static and it's name is in UPPERCASE.) | |
| $field.transient | does the field have a transient modifier? | |
| $field.string | is the field a java.lang.String type? | |
| $FQClassname | the fully qualified name of the class |
#if ( $fields.size() > 0 )
#set ( $i = 0 )
return "$classname{" +
#foreach( $field in $fields )
#if ( $i == 0 )
"##
#else
", ##
#end
#if ( $field.primitiveArray )
$field.name=" + ($field.name == null ? null : "(length:" + $field.name .length + ")") +
#elseif ( $field.objectArray )
$field.name=" + ($field.name == null ? null : "(length:" + $field.name .length + ")" + Arrays.asList($field.name)) +
#elseif ( $field.collection || $field.map )
$field.name=" + ($field.name == null ? null : "(size:" + $field.name .size() + ")" + $field.name) +
#elseif ( $field.string )
$field.name='" + $field.name + "'" +
#else
$field.name=" + $field.name +
#end
#set ( $i = $i + 1 )
#end
"}";
#else
return "$classname{}";
#end
isAssignableFrom method calls so all kind of objects are regonized as a Collection/Map properly. New dialog to select fields, enable/disable it in the settings. Thanks to Martin Schmid (author of the greate SimpleUML plugin) for the dialog code.
v0.6 - All code is now generated using a velocity template. See the template in Options -> IDE Settings. Now handles arrays and collections to dump their contents.
v0.5 - Fixed problem using same Velocity engine as IDEA. Cosmetic fix for body code when no fields and for first field. Updated javadoc.
v0.4 - Added Velocity template for method body code generation. Added build.xml in source distribution.
v0.3 - Can generate methods for inner classes. Added UML diagram to javadoc. Doesn't generate field dump for constant fields.
v0.2 - Removed super call option.
v0.1 - Initial version.
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||