View | Details | Raw Unified | Return to bug 270983
Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-5 / +13 lines)
Lines 1110-1118 Link Here
1110
		if (kind == TypeDeclaration.ENUM_DECL) {
1110
		if (kind == TypeDeclaration.ENUM_DECL) {
1111
			FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
1111
			FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
1112
			boolean hasConstants = false;
1112
			boolean hasConstants = false;
1113
			int length = fieldDeclarations != null ? fieldDeclarations.length : 0;
1114
			int enumConstantsLength = 0;
1113
			if (fieldDeclarations != null) {
1115
			if (fieldDeclarations != null) {
1114
				int length = fieldDeclarations.length;
1115
				int enumConstantsLength = 0;
1116
				for (int i = 0; i < length; i++) {
1116
				for (int i = 0; i < length; i++) {
1117
					FieldDeclaration fieldDeclaration = fieldDeclarations[i];
1117
					FieldDeclaration fieldDeclaration = fieldDeclarations[i];
1118
					if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
1118
					if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
Lines 1155-1161 Link Here
1155
						}
1155
						}
1156
					} while (!ok);
1156
					} while (!ok);
1157
					this.scribe.exitAlignment(enumConstantsAlignment, true);
1157
					this.scribe.exitAlignment(enumConstantsAlignment, true);
1158
				} else {
1158
				} else if (hasConstants) {
1159
					// only one enum constant
1159
					FieldDeclaration fieldDeclaration = fieldDeclarations[0];
1160
					FieldDeclaration fieldDeclaration = fieldDeclarations[0];
1160
					fieldDeclaration.traverse(this, typeDeclaration.initializerScope);
1161
					fieldDeclaration.traverse(this, typeDeclaration.initializerScope);
1161
					if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
1162
					if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
Lines 1173-1180 Link Here
1173
			if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
1174
			if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
1174
				this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
1175
				this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
1175
				this.scribe.printTrailingComment();
1176
				this.scribe.printTrailingComment();
1176
			}
1177
				if (hasConstants
1177
			if (hasConstants) {
1178
						|| ((enumConstantsLength - length) != 0)
1179
						|| typeDeclaration.methods != null
1180
						|| typeDeclaration.memberTypes != null) {
1181
					// make sure that empty enums don't get a new line
1182
					this.scribe.printNewLine();
1183
				}
1184
			} else if (hasConstants) {
1185
				// only had a new line if there is at least one enum constant
1178
				this.scribe.printNewLine();
1186
				this.scribe.printNewLine();
1179
			}
1187
			}
1180
		}
1188
		}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-1 / +23 lines)
Lines 57-63 Link Here
57
	DefaultCodeFormatterOptions formatterPrefs;
57
	DefaultCodeFormatterOptions formatterPrefs;
58
58
59
	static {
59
	static {
60
//		TESTS_NUMBERS = new int[] { 719 };
60
//		TESTS_NUMBERS = new int[] { 721 };
61
//		TESTS_RANGE = new int[] { 715, -1 };
61
//		TESTS_RANGE = new int[] { 715, -1 };
62
	}
62
	}
63
	public static Test suite() {
63
	public static Test suite() {
Lines 10763-10766 Link Here
10763
		"}\n"
10763
		"}\n"
10764
	);
10764
	);
10765
}
10765
}
10766
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
10767
public void test720() {
10768
	final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10769
	DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10770
	Map compilerOptions = new HashMap();
10771
	compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
10772
	compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
10773
	compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
10774
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10775
	runTest(codeFormatter, "test720", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10776
}
10777
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
10778
public void test721() {
10779
	final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10780
	DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10781
	Map compilerOptions = new HashMap();
10782
	compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
10783
	compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
10784
	compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
10785
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10786
	runTest(codeFormatter, "test721", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10787
}
10766
}
10788
}
(-)workspace/Formatter/test720/A_in.java (+1 lines)
Added Link Here
1
public enum MyEnum {;private int foo;}
(-)workspace/Formatter/test721/A_in.java (+1 lines)
Added Link Here
1
public enum MyEnum {;}
(-)workspace/Formatter/test721/A_out.java (+3 lines)
Added Link Here
1
public enum MyEnum {
2
	;
3
}
(-)workspace/Formatter/test720/A_out.java (+4 lines)
Added Link Here
1
public enum MyEnum {
2
	;
3
	private int foo;
4
}

Return to bug 270983