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

Collapse All | Expand All

(-)buildnotes_jdt-core.html (+1 lines)
Lines 48-53 Link Here
48
<br>Project org.eclipse.jdt.core v_A22
48
<br>Project org.eclipse.jdt.core v_A22
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A22">cvs</a>).
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A22">cvs</a>).
50
<h2>What's new in this drop</h2>
50
<h2>What's new in this drop</h2>
51
Patch v01 for bug 295238
51
52
52
<h3>Problem Reports Fixed</h3>
53
<h3>Problem Reports Fixed</h3>
53
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=295175">295175</a>
54
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=295175">295175</a>
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-1 / +7 lines)
Lines 1561-1566 Link Here
1561
		boolean hasMultiLines = false;
1561
		boolean hasMultiLines = false;
1562
		boolean hasTokens = false;
1562
		boolean hasTokens = false;
1563
		boolean bufferHasTokens = false;
1563
		boolean bufferHasTokens = false;
1564
		boolean bufferHasNewLine = false;
1564
		boolean lineHasTokens = false;
1565
		boolean lineHasTokens = false;
1565
		int hasTextOnFirstLine = 0;
1566
		int hasTextOnFirstLine = 0;
1566
		boolean firstWord = true;
1567
		boolean firstWord = true;
Lines 1595-1600 Link Here
1595
						this.column += tokensBuffer.length();
1596
						this.column += tokensBuffer.length();
1596
						tokensBuffer.setLength(0);
1597
						tokensBuffer.setLength(0);
1597
						bufferHasTokens = true;
1598
						bufferHasTokens = true;
1599
						bufferHasNewLine = false;
1598
					}
1600
					}
1599
					if (previousToken == -1) {
1601
					if (previousToken == -1) {
1600
						// do not remember the first whitespace
1602
						// do not remember the first whitespace
Lines 1710-1715 Link Here
1710
		    		this.column += BLOCK_LINE_PREFIX_LENGTH;
1712
		    		this.column += BLOCK_LINE_PREFIX_LENGTH;
1711
		    		firstWord = true;
1713
		    		firstWord = true;
1712
					multiLines = true;
1714
					multiLines = true;
1715
					bufferHasNewLine = true;
1713
				}
1716
				}
1714
				insertSpace = insertSpace && linesGap == 0;
1717
				insertSpace = insertSpace && linesGap == 0;
1715
			}
1718
			}
Lines 1744-1751 Link Here
1744
					buffer.append(tokensString);
1747
					buffer.append(tokensString);
1745
					this.column += tokensString.length();
1748
					this.column += tokensString.length();
1746
					tokensBuffer.setLength(0);
1749
					tokensBuffer.setLength(0);
1750
					bufferHasNewLine = false;
1751
					bufferHasTokens = true;
1747
				}
1752
				}
1748
				if (bufferHasTokens) {
1753
				if (bufferHasTokens && !bufferHasNewLine) {
1749
			    	buffer.append(this.lineSeparator);
1754
			    	buffer.append(this.lineSeparator);
1750
			    	this.column = 1;
1755
			    	this.column = 1;
1751
			    	printIndentationIfNecessary(buffer);
1756
			    	printIndentationIfNecessary(buffer);
Lines 1759-1764 Link Here
1759
		    	}
1764
		    	}
1760
				buffer.append(this.scanner.source, tokenStart, tokenLength);
1765
				buffer.append(this.scanner.source, tokenStart, tokenLength);
1761
				bufferHasTokens = true;
1766
				bufferHasTokens = true;
1767
				bufferHasNewLine = false;
1762
				this.column += tokenLength;
1768
				this.column += tokenLength;
1763
				multiLines = true;
1769
				multiLines = true;
1764
				hasTextOnFirstLine = -1;
1770
				hasTextOnFirstLine = -1;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+136 lines)
Lines 1976-1979 Link Here
1976
		"}\n"
1976
		"}\n"
1977
	);
1977
	);
1978
}
1978
}
1979
1980
/**
1981
 * @bug 295238: [formatter] The comment formatter add an unexpected new line in block comment
1982
 * @test Verify that formatting a block comment with a tag does not add an unexpected new line
1983
 * 		when the 'Never join lines' option is set
1984
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295238"
1985
 */
1986
public void testBug295238() {
1987
	this.formatterPrefs.join_lines_in_comments = false;
1988
	String source = 
1989
		"package wksp1;\n" + 
1990
		"\n" + 
1991
		"public interface X03 {\n" + 
1992
		"	\n" + 
1993
		"	class Inner {\n" + 
1994
		"		\n" + 
1995
		"		/* (non-Javadoc)\n" + 
1996
		"		 * @see org.eclipse.jface.text.TextViewer#customizeDocumentCommand(org.eclipse.jface.text.DocumentCommand)\n" + 
1997
		"		 */\n" + 
1998
		"		protected void foo() {\n" + 
1999
		"		}\n" + 
2000
		"	}\n" + 
2001
		"}\n";
2002
	formatSource(source,
2003
		"package wksp1;\n" + 
2004
		"\n" + 
2005
		"public interface X03 {\n" + 
2006
		"\n" + 
2007
		"	class Inner {\n" + 
2008
		"\n" + 
2009
		"		/*\n" + 
2010
		"		 * (non-Javadoc)\n" + 
2011
		"		 * \n" + 
2012
		"		 * @see\n" + 
2013
		"		 * org.eclipse.jface.text.TextViewer#customizeDocumentCommand(org.eclipse\n" + 
2014
		"		 * .jface.text.DocumentCommand)\n" + 
2015
		"		 */\n" + 
2016
		"		protected void foo() {\n" + 
2017
		"		}\n" + 
2018
		"	}\n" + 
2019
		"}\n"
2020
	);
2021
}
2022
// the following test already passed with v_A21, but failed with first version of the patch
2023
public void testBug295238b1() {
2024
	this.formatterPrefs.join_lines_in_comments = false;
2025
	String source = 
2026
		"package wksp1;\n" + 
2027
		"\n" + 
2028
		"public class X02 {\n" + 
2029
		"\n" + 
2030
		"	void foo() {\n" + 
2031
		"/*		if ((operatorSignature & CompareMASK) == (alternateOperatorSignature & CompareMASK)) { // same promotions and result\n" + 
2032
		"			scope.problemReporter().unnecessaryCastForArgument((CastExpression)expression,  TypeBinding.wellKnownType(scope, expression.implicitConversion >> 4)); \n" + 
2033
		"		}\n" + 
2034
		"*/		\n" + 
2035
		"	}\n" + 
2036
		"}\n";
2037
	formatSource(source,
2038
		"package wksp1;\n" + 
2039
		"\n" + 
2040
		"public class X02 {\n" + 
2041
		"\n" + 
2042
		"	void foo() {\n" + 
2043
		"		/*\n" + 
2044
		"		 * if ((operatorSignature & CompareMASK) == (alternateOperatorSignature\n" + 
2045
		"		 * & CompareMASK)) { // same promotions and result\n" + 
2046
		"		 * scope.problemReporter().unnecessaryCastForArgument((CastExpression)\n" + 
2047
		"		 * expression, TypeBinding.wellKnownType(scope,\n" + 
2048
		"		 * expression.implicitConversion >> 4));\n" + 
2049
		"		 * }\n" + 
2050
		"		 */\n" + 
2051
		"	}\n" + 
2052
		"}\n"
2053
	);
2054
}
2055
// the following test failed with v_A21 and with the version v00 of the patch
2056
public void testBug295238b2() {
2057
	this.formatterPrefs.join_lines_in_comments = false;
2058
	String source = 
2059
		"package wksp1;\n" + 
2060
		"\n" + 
2061
		"public class X02 {\n" + 
2062
		"\n" + 
2063
		"	void foo() {\n" + 
2064
		"/*			scope.problemReporter().unnecessaryCastForArgument((CastExpression)expression,  TypeBinding.wellKnownType(scope, expression.implicitConversion >> 4)); \n" + 
2065
		"*/		\n" + 
2066
		"	}\n" + 
2067
		"}\n";
2068
	formatSource(source,
2069
		"package wksp1;\n" + 
2070
		"\n" + 
2071
		"public class X02 {\n" + 
2072
		"\n" + 
2073
		"	void foo() {\n" + 
2074
		"		/*\n" + 
2075
		"		 * scope.problemReporter().unnecessaryCastForArgument((CastExpression)\n" + 
2076
		"		 * expression, TypeBinding.wellKnownType(scope,\n" + 
2077
		"		 * expression.implicitConversion >> 4));\n" + 
2078
		"		 * }\n" + 
2079
		"		 */\n" + 
2080
		"	}\n" + 
2081
		"}\n"
2082
	);
2083
}
2084
// the following test failed with v_A21 and with the version v00 of the patch
2085
public void testBug295238b3() {
2086
	this.formatterPrefs.join_lines_in_comments = false;
2087
	String source = 
2088
		"package wksp1;\n" + 
2089
		"\n" + 
2090
		"public class X02 {\n" + 
2091
		"\n" + 
2092
		"	void foo() {\n" + 
2093
		"/*\n" + 
2094
		"			scope.problemReporter().unnecessaryCastForArgument((CastExpression)expression,  TypeBinding.wellKnownType(scope, expression.implicitConversion >> 4)); \n" + 
2095
		"		}\n" + 
2096
		"*/		\n" + 
2097
		"	}\n" + 
2098
		"}\n";
2099
	formatSource(source,
2100
		"package wksp1;\n" + 
2101
		"\n" + 
2102
		"public class X02 {\n" + 
2103
		"\n" + 
2104
		"	void foo() {\n" + 
2105
		"		/*\n" + 
2106
		"		 * scope.problemReporter().unnecessaryCastForArgument((CastExpression)\n" + 
2107
		"		 * expression, TypeBinding.wellKnownType(scope,\n" + 
2108
		"		 * expression.implicitConversion >> 4));\n" + 
2109
		"		 * }\n" + 
2110
		"		 */\n" + 
2111
		"	}\n" + 
2112
		"}\n"
2113
	);
2114
}
1979
}
2115
}

Return to bug 295238