### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.213 diff -u -r1.213 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 7 Mar 2009 00:59:01 -0000 1.213 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 2 Apr 2009 15:57:17 -0000 @@ -1110,9 +1110,9 @@ if (kind == TypeDeclaration.ENUM_DECL) { FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; boolean hasConstants = false; + int length = fieldDeclarations != null ? fieldDeclarations.length : 0; + int enumConstantsLength = 0; 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) { @@ -1155,7 +1155,8 @@ } } while (!ok); this.scribe.exitAlignment(enumConstantsAlignment, true); - } else { + } else if (hasConstants) { + // only one enum constant FieldDeclaration fieldDeclaration = fieldDeclarations[0]; fieldDeclaration.traverse(this, typeDeclaration.initializerScope); if (isNextToken(TerminalTokens.TokenNameCOMMA)) { @@ -1173,8 +1174,15 @@ if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) { this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printTrailingComment(); - } - if (hasConstants) { + if (hasConstants + || ((enumConstantsLength - length) != 0) + || typeDeclaration.methods != null + || typeDeclaration.memberTypes != null) { + // make sure that empty enums don't get a new line + this.scribe.printNewLine(); + } + } else if (hasConstants) { + // only had a new line if there is at least one enum constant this.scribe.printNewLine(); } } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v retrieving revision 1.241 diff -u -r1.241 FormatterRegressionTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 30 Jan 2009 15:42:32 -0000 1.241 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 2 Apr 2009 15:57:18 -0000 @@ -57,7 +57,7 @@ DefaultCodeFormatterOptions formatterPrefs; static { -// TESTS_NUMBERS = new int[] { 719 }; +// TESTS_NUMBERS = new int[] { 721 }; // TESTS_RANGE = new int[] { 715, -1 }; } public static Test suite() { @@ -10763,4 +10763,26 @@ "}\n" ); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983 +public void test720() { + final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); + DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); + Map compilerOptions = new HashMap(); + compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions); + runTest(codeFormatter, "test720", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983 +public void test721() { + final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); + DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); + Map compilerOptions = new HashMap(); + compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions); + runTest(codeFormatter, "test721", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ +} } Index: workspace/Formatter/test720/A_in.java =================================================================== RCS file: workspace/Formatter/test720/A_in.java diff -N workspace/Formatter/test720/A_in.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test720/A_in.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +public enum MyEnum {;private int foo;} Index: workspace/Formatter/test721/A_in.java =================================================================== RCS file: workspace/Formatter/test721/A_in.java diff -N workspace/Formatter/test721/A_in.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test721/A_in.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +public enum MyEnum {;} Index: workspace/Formatter/test721/A_out.java =================================================================== RCS file: workspace/Formatter/test721/A_out.java diff -N workspace/Formatter/test721/A_out.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test721/A_out.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,3 @@ +public enum MyEnum { + ; +} Index: workspace/Formatter/test720/A_out.java =================================================================== RCS file: workspace/Formatter/test720/A_out.java diff -N workspace/Formatter/test720/A_out.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test720/A_out.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,4 @@ +public enum MyEnum { + ; + private int foo; +}