Rearranger has stopped sorting methods and declarations.
I wrote a primitive Rearranger.
It parses declarations or method headers, and passes the fields to a
comparator.
It then can decide what order it wants the declarations methods
based on the
private/public static/non-static
type(int/void/String/Double/SomeClass) name
While it is at it, it complains about caps violations.
It would be nice if the new arranger let you write a custom
comparator on some objects with the information about a given block
encoded as strings or enums, then it would be trivial for a Java
programmer to knock off his own comparator, one each for
classes/interfaces, methods/constructors, declarations/static blocks.
You would not need to invent some elaborate specification language
that would never cover everything. Doing it that way would save you a
lot of work, and would give complete flexibility to programmers.
The program is mostly a mess of switch statement assigning keywords
and primitives to sorting priorities.
e.g.
private static char calcTypeOrder( final String typeName )
{
if ( ST.isEmpty( typeName ) )
{
return 'z';
}
switch ( typeName )
{
case "":
return 'z';
case "boolean":
return '0';
case "byte":
return '1';
case "char":
return '2';
case "short":
return '3';
case "int":
return '4';
case "long":
return '5';
case "float":
return '6';
case "double":
return '7';
case "Boolean":
return '8';
case "Byte":
return '9';
case "Character":
return 'A';
case "Short":
return 'B';
case "Integer":
return 'C';
case "Long":
return 'D';
case "Float":
return 'E';
case "Double":
return 'F';
case "String":
return 'G';
default:
// we should have a class name of some sort e.g.
HashMap
if ( Character.isUpperCase( typeName.charAt( 0 ) ) )
{
return 'H';
}
else
{
err.println( "Class name should start with a
capital letter: " + typeName );
return 'I';
}
} // end switch
You might do your own variant where byte, char, int, long all sort
mixed together by assigning them the same ordering letter.
--
Roedy Green Canadian Mind Products http://mindprod.com
Computers are like Old Testament gods; lots of rules and no mercy.
~ Joseph Campbell (born: 1904-03-26 died: 1987-10-31 at age: 83)