Lets you control the sorting settings.
Lets you control the sorting of the main declaration elements of Java compilation units: classes, interfaces, enums, annotations, fields, initializers, constructors and methods.
Enables or disables the sorting of declaration elements. When disabled, the elements appear in their original order. Otherwise they are sorted according to the specified order (see the section called "Sort Order" below).
You can specify the order in which static fields/initializers, instance fields, instance initializers, constructor, method, enum, annotation, class and interface declarations and enum constants should appear in source files by selecting an element type and moving it up or down the list.
By default, with sorting enabled, the different declaration elements are grouped together, but within one element type the contained declarations are still placed in their original order. For example all methods will be grouped together, but otherwise the methods appear in their original order. Enable any of the check boxes, if you want to have all members of one type sorted, too.
Use the button to define the order in which the individual members should appear. A dialog opens that lets you specify the sorting criteria, e.g. modifier or name. You can select what criteria should be used and in what order. Jalopy checks all significant sorting conditions in the specified order until the sorting position of a declaration member could be determined.
For example if you want your methods to be sorted according to their access modifier and names, enable both criteria and disable the others. For two methods Jalopy will first check whether the modifiers are equal. If they differ, the sorting order is already obvious and no further criteria applied. But if they are equal, it will check their names and sort the two methods lexicographically.
Please note that for modifiers you can further refine what modifiers should be significant for sorting and in what order they are tested. Though accessible from different dialogs, the settings for modifier sorting are global and used across all declaration types to achieve a consistent style.
For fields, you can specify to sort according to modifier, object type and/or name. Enable the check box for each criteria that should be significant and use the and buttons to specify the order in which the criteria should be applied.
In the above example, the access modifier would be "public", the object type "String" and the name "aName".
Lets you sort fields according to their names.
Example 2.688. Sort fields by name
protected Vector aAliases = null; private String aName = "John Doo"; public List aValues = new ArrayList();
Please note that in the above example only the name is significant for determining the order to demonstrate the purpose.
Lets you sort fields according to their object type.
Example 2.689. Sort fields by object type
public List aValues = new ArrayList(); private String aName = "John Doo"; protected Vector aAliases = null;
Please note that in the above example only the object type is significant for determining the order to demonstrate the purpose.
Lets you sort fields according to their modifiers.
Example 2.690. Sort fields by modifiers
public List aValues = new ArrayList(); protected Vector aAliases = null; private String aName = "John Doo";
Please note that in the above example only the modifiers are significant for determining the order to demonstrate the purpose.
To further refine the way sorting is applied for modifiers, select the "Modifiers" entry, press the button to define what modifiers should be significant and adjust the order in which testing should be applied.
Configuration for modifiers is explained in detail in the section called "Modifiers".
Constructors can be sorted by modifier, default constructor, copy constructor and parameter count.
Enable the check box for each criteria that should be significant and use the and buttons to define the order in which the criteria should be applied.
In the above example, the modifier would be "private", and the parameter count "1".
Default constructor means the single parameter-less constructor every class may have. If you want to ensure a specific location for default constructors, check this entry and move it to the desired position.
Copy constructors are those constructors that take a single parameter of the same type as the class itself. If you want to ensure a specific location for copy constructors, check this entry and move it to the desired position.
Lets you sort constructors according to the number of parameters. Those whose number is smaller will be placed above the others.
Example 2.694. Constructors sorted by parameter count
public class Foo { protected Foo() { ... } private Foo(Foo rFoo) { ... } public Foo(int param1, String param2) { ... } }
Please note that in the above example only the parameter count is significant for determining the order to demonstrate the purpose.
To further refine the way sorting is applied for modifiers, select the "Modifiers" entry, press the button to define what modifiers should be significant and adjust the order in which testing should be applied.
Example 2.695. Constructors sorted by modifiers
public class Foo { public Foo(int param1, String param2) { ... } protected Foo() { ... } private Foo(Foo rFoo) { ... } }
Please note that in the above example only the modifiers are significant for determining the order to demonstrate the purpose.
Configuration for modifiers is explained in detail in the section called "Modifiers".
For methods, you can specify sorting by modifiers, name, parameter count, Java Bean pattern, regular expression pattern or custom ordering. Enable the check box for each criteria that should be significant and use the and buttons to specify the order in which the criteria should be applied.
In the above example, the access modifier would be "public final", the name "setName" and parameter count "2".
To further refine the way sorting is applied for modifiers, select the "Modifiers" entry and press the button to define what modifiers should be significant and adjust their order.
Bean pattern refers to the Java Bean specification naming convention that requires accessor and mutator methods to begin with either the set, get or is prefixes.
You can control the order in which Java Bean methods and ordinary methods appear by selecting the entry and press the button. Adjust the order of the different elements in the list component of the new dialog and press . The "Ordinary method" entry refers to all non-Bean methods.
Normally bean pattern sorting means that all methods of one type (getters, boolean getters, setters, ordinary methods) are grouped together according to the specified order. Enabling this option causes all methods with similar names to be grouped together, i.e. bean methods and ordinary methods may be mixed, but all bean methods for one property stay together.
Similar methods are determined by stripping the bean prefix and comparing the resulting method names. Similar methods are grouped together according to the specified order (getters, boolean getters, setters, ordinary methods).
Since 1.5
Example 2.697. Bean pattern sorting
public void aaaaaa() {} public void bbbbbb() {} public void cccccc() {} public Object getAaaaaa() {} public Object getBbbbbb() {} public Object getCccccc() {} public boolean isAaaaaa() {} public boolean isBbbbbb() {} public boolean isCccccc() {} public void setAaaaaa() {} public void setBbbbbb() {} public void setCccccc() {}
Example 2.698. Bean pattern sorting, similar methods grouped
public void aaaaaa() {} public Object getAaaaaa() {} public boolean isAaaaaa() {} public void setAaaaaa() {} public void bbbbbb() {} public Object getBbbbbb() {} public boolean isBbbbbb() {} public void setBbbbbb() {} public void cccccc() {} public Object getCccccc() {} public boolean isCccccc() {} public void setCccccc() {}
Grouping similar methods will let you group all bean methods for one property together, but the bean methods are otherwise still mixed with ordinary methods. If you instead prefer to have all> bean methods grouped together, you can enable this option to build one large block with all bean methods.
Since 1.8
Example 2.699. Bean pattern sorting, similar methods grouped
public void aaaaaa() {} public Object getAaaaaa() {} public boolean isAaaaaa() {} public void setAaaaaa() {} public void bbbbbb() {} public Object getBbbbbb() {} public boolean isBbbbbb() {} public void setBbbbbb() {} public void cccccc() {} public Object getCccccc() {} public boolean isCccccc() {} public void setCccccc() {}
Example 2.700. Bean pattern sorting, similar methods grouped, bean methods kept together
public Object getAaaaaa() {} public boolean isAaaaaa() {} public void setAaaaaa() {} public Object getBbbbbb() {} public boolean isBbbbbb() {} public void setBbbbbb() {} public Object getCccccc() {} public boolean isCccccc() {} public void setCccccc() {} public void aaaaaa() {} public void bbbbbb() {} public void cccccc() {}
Lets you define arbitrary regular expressions to match method signatures to specify absolute positions for specific methods.
Matching is performed against a simplified signature: only the modifiers, return type and method name are used.
The above method declaration would yield the following signature: public boolean equals
To add a new regular expression, press the button.
Enter the regular expression into the Regex textfield and press the button to apply the addition.
If you want to test the regular expression before you submit it, enter a test string in the String field and press the button to perform pattern matching.
To remove an existing regular expression, select the expression you want to remove and press the button.
To change an existing regular expression, select the expression you want to change and press the button.
Adjust the regular expression in the Regex textfield and press the button to apply the change.
If you want to test the regular expression before you submit it, enter a test string in the String field and press the button to perform pattern matching.
As it might not always be sufficient to rely on method signature information alone, developers can take total control over method ordering using special Javadoc tags.
Please note that Javadoc formatting must be enabled for this feature to work!
In order to have methods grouped by purpose, check the Custom entry in the upper list of the dialog, move it to the top and utilize two custom Javadoc tags in your method commentary.
In your method declaration comments, you need to add the Javadoc standalone tag @jalopy.group followed by a logical group name. This name can be freely chosen and defines the group a method belongs to.
Example 2.702. Sorting method declarations with @jalopy.group
/** * Returns the value of the Foo property. * * @jalopy.group Accessors */ public int getFoo () { ... }
Then you specify the order of methods with the @jalopy.group-order (you can use @jalopy.group_order to circumvent a bug in the Sun 1.4.2 Javadoc implementation) in the class or interface Javadoc comment. Simply place all group names defined with @jalopy.group tags in the desired order here and all methods will be sorted accordingly.
There is no special requirement on how the logical group names should be written, but it is good practice to separate them by commas.
Example 2.703. Class declaration with @jalopy.group-order
/** * I want methods ordered by value provided in the @jalopy.group tag of * each method in this order. If the method doesn't have a @jalopy.group tag, * fall back on project defaults. * * @jalopy.group-order Constructors,Queries,Accessors */ class Foo { ... }
This works recursively for all methods of a compilation unit, i.e. for inner classes, Jalopy first checks the inner class declaration comment and if no @jalopy.group-order tag can be found, it recursively searches all parent class/interface declarations of the unit.
Please note that all methods that have no custom group information associated are placed below the ones with grouping tags. Within each group the methods are sorted according to the normal criteria (access modifier, name, parameter count).
A group name not only defines the sorting order, but is used for separator comments also (Refer to the section called "Comments" for more information on this feature).
Since 1.1
Example 2.704. Custom separator comments
//~ Queries ------------------------------------------------------------ /** * This method gets object by primary key * * @param inConn db conn * @param inPK the primary key * * @jalopy.group Queries */ public static MyClass getByPK (Connection inConn, Long inPK) { ... } ... //~ Accessors ------------------------------------------------------------ /** * This method returns the Name property. * * @jalopy.group Accessors */ public String getName (Connection inConn, String inLoginName) { ... }
To sort all class, interfac or enum declarations, you can specify access modifier and name.
In the above example, the modifiers would be "protected abstract" and the name "AbstractPage".
To further refine the way sorting is applied for access modifiers, select the "Access Modifier" entry, press the button and define what modifiers should be significant and adjust the order in which testing should be applied.
Lets you define what modifiers should be significant when sorting by modifier and in which order the declarations should be sorted.
Please note that the position of the "Modifiers" entry in the parent dialog, defines whether and when the modifiers are actually used to determine the order of two declarations. E.g. if you want to sort by modifier first, "Modifiers" must be the topmost entry in the parent dialog.
Select the check box of each access modifier that should be used to determine the order of declarations and use the and buttons to define the order in which the declarations should be sorted.
For example, if you want to place all static methods together above the other ones, you would check the "static" modifier and move it to the top of the list.
Example 2.706. Sort by static modifier first, then access modifier
class Foo { public static void x() {} static void y() {} public void c() {} public void d() {} protected void b() {} private void a() {} }
But if you only want to have the methods sorted by access modifier, just check the four access modifiers and specify the order in which the declarations are to be sorted, e.g. private, package protected, protected and public.
Lets you define the regular expression that is used to determine what method declarations should be recognized as Boolean Getters.
According to the JavaBeans naming conventions, only method declarations starting with the is prefix are Boolean Getters, but it might make sense to lift these restriction. In certain cases it is more reasonable to name methods in a way that better describes its purpose but still treat them as Boolean Getters, like e.g. canDelete() or shouldDelete().
Important note: The prefix must be enclosed with matching parentheses! For example, always use something like "^(is|should|can)[A-Z]\w+" rather than "^is|should|can[A-Z]\w+".
Since 1.1