/*
* Superclass
*/
final TypeReference superclass = typeDeclaration.superclass;
if (superclass != null) {
Alignment superclassAlignment =this.scribe.createAlignment(
"superclass", //$NON-NLS-1$
this.preferences.alignment_for_superclass_in_type_declaration,
2,
this.scribe.scanner.currentPosition);
this.scribe.enterAlignment(superclassAlignment);
boolean ok = false;
do {
try {
this.scribe.alignFragment(superclassAlignment, 0);
this.scribe.printNextToken(TerminalTokens.TokenNameextends, true);
this.scribe.alignFragment(superclassAlignment, 1);
this.scribe.space();
superclass.traverse(this, typeDeclaration.scope);
ok = true;
} catch (AlignmentException e) {
this.scribe.redoAlignment(e);
}
} while (!ok);
this.scribe.exitAlignment(superclassAlignment, true);
}
/*
* Super Interfaces
*/
final TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
if (superInterfaces != null) {
int alignment_for_superinterfaces;
int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
switch(kind) {
case TypeDeclaration.ENUM_DECL :
alignment_for_superinterfaces = this.preferences.alignment_for_superinterfaces_in_enum_declaration;
break;
default:
alignment_for_superinterfaces = this.preferences.alignment_for_superinterfaces_in_type_declaration;
break;
}
int superInterfaceLength = superInterfaces.length;
Alignment interfaceAlignment =this.scribe.createAlignment(
"superInterfaces",//$NON-NLS-1$
alignment_for_superinterfaces,
superInterfaceLength+1, // implements token is first fragment
this.scribe.scanner.currentPosition);
this.scribe.enterAlignment(interfaceAlignment);
boolean ok = false;
do {
try {
this.scribe.alignFragment(interfaceAlignment, 0);
if (kind == TypeDeclaration.INTERFACE_DECL) {
this.scribe.printNextToken(TerminalTokens.TokenNameextends, true);
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameimplements, true);
}
for (int i = 0; i < superInterfaceLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_superinterfaces);
this.scribe.printTrailingComment();
this.scribe.alignFragment(interfaceAlignment, i+1);
if (this.preferences.insert_space_after_comma_in_superinterfaces) {
this.scribe.space();
}
superInterfaces[i].traverse(this, typeDeclaration.scope);
} else {
this.scribe.alignFragment(interfaceAlignment, i+1);
this.scribe.space();
superInterfaces[i].traverse(this, typeDeclaration.scope);
}
}
ok = true;
} catch (AlignmentException e) {
this.scribe.redoAlignment(e);
}
} while (!ok);
this.scribe.exitAlignment(interfaceAlignment, true);
}
/*
* Type body
*/
String class_declaration_brace;
boolean space_before_opening_brace;
int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
switch(kind) {
case TypeDeclaration.ENUM_DECL :
class_declaration_brace = this.preferences.brace_position_for_enum_declaration;
space_before_opening_brace = this.preferences.insert_space_before_opening_brace_in_enum_declaration;
break;
case TypeDeclaration.ANNOTATION_TYPE_DECL :
class_declaration_brace = this.preferences.brace_position_for_annotation_type_declaration;
space_before_opening_brace = this.preferences.insert_space_before_opening_brace_in_annotation_type_declaration;
break;
default:
class_declaration_brace = this.preferences.brace_position_for_type_declaration;
space_before_opening_brace = this.preferences.insert_space_before_opening_brace_in_type_declaration;
break;
}
formatLeftCurlyBrace(line, class_declaration_brace);
formatTypeOpeningBrace(class_declaration_brace, space_before_opening_brace, typeDeclaration);
boolean indent_body_declarations_compare_to_header;
switch(kind) {
case TypeDeclaration.ENUM_DECL :
indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_enum_declaration_header;
break;
case TypeDeclaration.ANNOTATION_TYPE_DECL :
indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_annotation_declaration_header;
break;
default:
indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_type_header;
break;
}
if (indent_body_declarations_compare_to_header) {
this.scribe.indent();
}
if (kind == TypeDeclaration.ENUM_DECL) {
FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
boolean hasConstants = false;
if (fieldDeclarations != null) {
int length = fieldDeclarations.length;
int enumConstantsLength = 0;
for (int i = 0; i < length; i++) {
FieldDeclaration fieldDeclaration = fieldDeclarations[i];
if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
enumConstantsLength++;
} else {
break;
}
}
hasConstants = enumConstantsLength != 0;
if (enumConstantsLength > 1) {
Alignment enumConstantsAlignment = this.scribe.createAlignment(
"enumConstants",//$NON-NLS-1$
this.preferences.alignment_for_enum_constants,
enumConstantsLength,
this.scribe.scanner.currentPosition,
0, // we don't want to indent enum constants when splitting to a new line