View | Details | Raw Unified | Return to bug 286601 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+25 lines)
Lines 10849-10852 Link Here
10849
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10849
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10850
	runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10850
	runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10851
}
10851
}
10852
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=286601
10853
public void testBug286601() throws JavaModelException {
10854
	this.formatterPrefs.join_wrapped_lines = false;
10855
	String source = 
10856
		"public class Test\n" + 
10857
		"{\n" + 
10858
		"    public void aMethod()\n" + 
10859
		"    {\n" + 
10860
		"        Object anObject = new Object()\n" + 
10861
		"        {\n" + 
10862
		"            boolean aVariable;\n" + 
10863
		"        };\n" + 
10864
		"    }\n" + 
10865
		"}\n";
10866
	formatSource(source,
10867
		"public class Test {\n" + 
10868
		"	public void aMethod() {\n" + 
10869
		"		Object anObject = new Object()\n" + 
10870
		"		{\n" + 
10871
		"			boolean aVariable;\n" + 
10872
		"		};\n" + 
10873
		"	}\n" + 
10874
		"}\n"
10875
	);
10876
}
10852
}
10877
}
(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (+1 lines)
Lines 45-50 Link Here
45
	public int shiftBreakIndentationLevel;
45
	public int shiftBreakIndentationLevel;
46
	public int[] fragmentBreaks;
46
	public int[] fragmentBreaks;
47
	public boolean wasSplit;
47
	public boolean wasSplit;
48
	public boolean useBreakIndentionWhilePreservingLineBreaks = false;
48
49
49
	public Scribe scribe;
50
	public Scribe scribe;
50
51
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-4 / +8 lines)
Lines 948-957 Link Here
948
				// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476
948
				// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476
949
				if (this.lastNumberOfNewLines == 0) {
949
				if (this.lastNumberOfNewLines == 0) {
950
					StringBuffer buffer = new StringBuffer(getNewLine());
950
					StringBuffer buffer = new StringBuffer(getNewLine());
951
					int savedIndentation = this.indentationLevel;
951
					if (this.currentAlignment.useBreakIndentionWhilePreservingLineBreaks) {
952
					this.indentationLevel = this.currentAlignment.breakIndentationLevel;
952
						int savedIndentation = this.indentationLevel;
953
					printIndentationIfNecessary(buffer);
953
						this.indentationLevel = this.currentAlignment.breakIndentationLevel;
954
					this.indentationLevel = savedIndentation;
954
						printIndentationIfNecessary(buffer);
955
						this.indentationLevel = savedIndentation;
956
					} else {
957
						printIndentationIfNecessary(buffer);
958
					}
955
					return buffer.toString();
959
					return buffer.toString();
956
				}
960
				}
957
			}
961
			}
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-1 / +3 lines)
Lines 431-436 Link Here
431
			this.scribe.printComment();
431
			this.scribe.printComment();
432
			Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
432
			Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
433
			this.scribe.enterAlignment(binaryExpressionAlignment);
433
			this.scribe.enterAlignment(binaryExpressionAlignment);
434
			binaryExpressionAlignment.useBreakIndentionWhilePreservingLineBreaks = true;
434
			boolean ok = false;
435
			boolean ok = false;
435
			ASTNode[] fragments = builder.fragments();
436
			ASTNode[] fragments = builder.fragments();
436
			int[] operators = builder.operators();
437
			int[] operators = builder.operators();
Lines 4861-4871 Link Here
4861
			manageOpeningParenthesizedExpression(stringLiteral, numberOfParens);
4862
			manageOpeningParenthesizedExpression(stringLiteral, numberOfParens);
4862
		}
4863
		}
4863
4864
4864
		this.scribe.printComment();
4865
		ASTNode[] fragments = stringLiteral.literals;
4865
		ASTNode[] fragments = stringLiteral.literals;
4866
		int fragmentsSize = stringLiteral.counter;
4866
		int fragmentsSize = stringLiteral.counter;
4867
		Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
4867
		Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
4868
		this.scribe.enterAlignment(binaryExpressionAlignment);
4868
		this.scribe.enterAlignment(binaryExpressionAlignment);
4869
		binaryExpressionAlignment.useBreakIndentionWhilePreservingLineBreaks = true;
4870
		this.scribe.printComment();
4869
		boolean ok = false;
4871
		boolean ok = false;
4870
		do {
4872
		do {
4871
			try {
4873
			try {

Return to bug 286601