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

(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (+10 lines)
Lines 222-227 Link Here
222
		}
222
		}
223
	}
223
	}
224
224
225
	public int depth() {
226
		int depth = 0;
227
		Alignment current = this.enclosing;
228
		while (current != null) {
229
			depth++;
230
			current = current.enclosing;
231
		}
232
		return depth;
233
	}
234
225
	public boolean couldBreak(){
235
	public boolean couldBreak(){
226
		int i;
236
		int i;
227
		switch(this.mode & SPLIT_MASK){
237
		switch(this.mode & SPLIT_MASK){
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-7 / +9 lines)
Lines 936-948 Link Here
936
		if (count == 0) {
936
		if (count == 0) {
937
			// preserve line breaks in wrapping if specified
937
			// preserve line breaks in wrapping if specified
938
			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
938
			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
939
			if (this.currentAlignment != null && !this.formatter.preferences.join_wrapped_lines) {
939
			if (this.currentAlignment != null && this.memberAlignment != null && !this.formatter.preferences.join_wrapped_lines) {
940
				int savedIndentation = this.indentationLevel;
940
				if (this.memberAlignment.depth() <= this.currentAlignment.depth()) {
941
				StringBuffer buffer = new StringBuffer(getNewLine());
941
					int savedIndentation = this.indentationLevel;
942
				this.indentationLevel = this.currentAlignment.breakIndentationLevel;
942
					StringBuffer buffer = new StringBuffer(getNewLine());
943
				printIndentationIfNecessary(buffer);
943
					this.indentationLevel = this.currentAlignment.breakIndentationLevel;
944
				this.indentationLevel = savedIndentation;
944
					printIndentationIfNecessary(buffer);
945
				return buffer.toString();
945
					this.indentationLevel = savedIndentation;
946
					return buffer.toString();
947
				}
946
			}
948
			}
947
			return Util.EMPTY_STRING;
949
			return Util.EMPTY_STRING;
948
		}
950
		}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (+106 lines)
Lines 3428-3431 Link Here
3428
		"}\n"
3428
		"}\n"
3429
	);
3429
	);
3430
}
3430
}
3431
3432
/**
3433
 * @bug 260798: [formatter] Strange behavior of never join lines
3434
 * @test Ensure that the formatter indents lines correctly when never join lines pref is activated
3435
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=260798"
3436
 */
3437
public void testBug260798() throws JavaModelException {
3438
	this.formatterPrefs.join_wrapped_lines = false;
3439
	String source = 
3440
		"class X {\n" + 
3441
		"    @Override\n" + 
3442
		"    public void addSelectionListener(SelectionListener listener) {\n" + 
3443
		"        super.addSelectionListener(new SelectionListener() {\n" + 
3444
		"            @Override\n" + 
3445
		"            public void widgetSelected(SelectionEvent e) {\n" + 
3446
		"            }\n" + 
3447
		"\n" + 
3448
		"            @Override\n" + 
3449
		"            public void widgetDefaultSelected(SelectionEvent e) {\n" + 
3450
		"            };\n" + 
3451
		"        });\n" + 
3452
		"    }\n" + 
3453
		"}\n";
3454
	formatSource(source,
3455
		"class X {\n" + 
3456
		"	@Override\n" + 
3457
		"	public void addSelectionListener(SelectionListener listener) {\n" + 
3458
		"		super.addSelectionListener(new SelectionListener() {\n" + 
3459
		"			@Override\n" + 
3460
		"			public void widgetSelected(SelectionEvent e) {\n" + 
3461
		"			}\n" + 
3462
		"\n" + 
3463
		"			@Override\n" + 
3464
		"			public void widgetDefaultSelected(SelectionEvent e) {\n" + 
3465
		"			};\n" + 
3466
		"		});\n" + 
3467
		"	}\n" + 
3468
		"}\n"
3469
	);
3470
}
3471
public void testBug260798b() throws JavaModelException {
3472
	this.formatterPrefs.join_wrapped_lines = false;
3473
	String source = 
3474
		"class X {\n" + 
3475
		"\n" + 
3476
		"    void foo() {\n" + 
3477
		"        this.bar(new Object() {\n" + 
3478
		"            @Override\n" + 
3479
		"            public String toString() {\n" + 
3480
		"                return \"\";\n" + 
3481
		"            }\n" + 
3482
		"        });\n" + 
3483
		"    }\n" + 
3484
		"}\n";
3485
	formatSource(source,
3486
		"class X {\n" + 
3487
		"\n" + 
3488
		"	void foo() {\n" + 
3489
		"		this.bar(new Object() {\n" + 
3490
		"			@Override\n" + 
3491
		"			public String toString() {\n" + 
3492
		"				return \"\";\n" + 
3493
		"			}\n" + 
3494
		"		});\n" + 
3495
		"	}\n" + 
3496
		"}\n"
3497
	);
3498
}
3499
public void testBug260798c() throws JavaModelException {
3500
	this.formatterPrefs.join_wrapped_lines = false;
3501
	String source = 
3502
		"class X {\n" + 
3503
		"\n" + 
3504
		"{\n" + 
3505
		"    this.bar(new Object() {\n" + 
3506
		"        @Override\n" + 
3507
		"        public String toString() {\n" + 
3508
		"            return \"\";\n" + 
3509
		"        }\n" + 
3510
		"    });\n" + 
3511
		"}\n" + 
3512
		"    void bar(Object object) {\n" + 
3513
		"        \n" + 
3514
		"    }\n" + 
3515
		"\n" + 
3516
		"}\n";
3517
	formatSource(source,
3518
		"class X {\n" + 
3519
		"\n" + 
3520
		"	{\n" + 
3521
		"		this.bar(new Object() {\n" + 
3522
		"			@Override\n" + 
3523
		"			public String toString() {\n" + 
3524
		"				return \"\";\n" + 
3525
		"			}\n" + 
3526
		"		});\n" + 
3527
		"	}\n" + 
3528
		"\n" + 
3529
		"	void bar(Object object) {\n" + 
3530
		"\n" + 
3531
		"	}\n" + 
3532
		"\n" + 
3533
		"}\n"
3534
	);
3535
}
3536
3431
}
3537
}

Return to bug 260798