Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 239719 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (+87 lines)
Lines 1722-1725 Link Here
1722
		"}\n"
1722
		"}\n"
1723
	);
1723
	);
1724
}
1724
}
1725
1726
/**
1727
 * @bug 239719: [formatter] Code formatter destroys pre formatted javadoc comments
1728
 * @test Ensure that annotations inside <pre>...</pre> tags are not considered as javadoc tags
1729
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=239719"
1730
 */
1731
public void testBug239719() throws JavaModelException {
1732
	String source = 
1733
		"/**\n" + 
1734
		" * <pre>\n" + 
1735
		" *  public class Test implements Runnable\n" + 
1736
		" *  {\n" + 
1737
		" *    @Override\n" + 
1738
		" *    public void run()\n" + 
1739
		" *    { \n" + 
1740
		" *      // Hello really bad Ganymede formatter !!!\n" + 
1741
		" *      // Shit happens when somebody tries to change a running system\n" + 
1742
		" *      System.out.println(\"Press Shift+Ctrl+F to format\");\n" + 
1743
		" *    }\n" + 
1744
		" *  }</pre>\n" + 
1745
		" */\n" + 
1746
		" public class Test \n" + 
1747
		" {\n" + 
1748
		" }\n";
1749
	formatSource(source,
1750
		"/**\n" + 
1751
		" * <pre>\n" + 
1752
		" * public class Test implements Runnable {\n" + 
1753
		" * 	&#064;Override\n" + 
1754
		" * 	public void run() {\n" + 
1755
		" * 		// Hello really bad Ganymede formatter !!!\n" + 
1756
		" * 		// Shit happens when somebody tries to change a running system\n" + 
1757
		" * 		System.out.println(&quot;Press Shift+Ctrl+F to format&quot;);\n" + 
1758
		" * 	}\n" + 
1759
		" * }\n" + 
1760
		" * </pre>\n" + 
1761
		" */\n" + 
1762
		"public class Test {\n" + 
1763
		"}\n"
1764
	);
1765
}
1766
public void testBug239719b() throws JavaModelException {
1767
	String source = 
1768
		"public class X01 {\n" + 
1769
		"	\n" + 
1770
		"	private int fLength;\n" + 
1771
		"	private int fOffset;\n" + 
1772
		"\n" + 
1773
		"	/**\n" + 
1774
		"	 * Returns the inclusive end position of this edit. The inclusive end\n" + 
1775
		"	 * position denotes the last character of the region manipulated by\n" + 
1776
		"	 * this edit. The returned value is the result of the following\n" + 
1777
		"	 * calculation:\n" + 
1778
		"	 * <pre>\n" + 
1779
		"	 *   getOffset() + getLength() - 1;\n" + 
1780
		"	 * <pre>\n" + 
1781
		"	 * \n" + 
1782
		"	 * @return the inclusive end position\n" + 
1783
		"	 */\n" + 
1784
		"	public final int getInclusiveEnd() {\n" + 
1785
		"		return fOffset + fLength - 1;\n" + 
1786
		"	}\n" + 
1787
		"}\n";
1788
	formatSource(source,
1789
		"public class X01 {\n" + 
1790
		"\n" + 
1791
		"	private int fLength;\n" + 
1792
		"	private int fOffset;\n" + 
1793
		"\n" + 
1794
		"	/**\n" + 
1795
		"	 * Returns the inclusive end position of this edit. The inclusive end\n" + 
1796
		"	 * position denotes the last character of the region manipulated by this\n" + 
1797
		"	 * edit. The returned value is the result of the following calculation:\n" + 
1798
		"	 * \n" + 
1799
		"	 * <pre>\n" + 
1800
		"	 * getOffset() + getLength() - 1;\n" + 
1801
		"	 * \n" + 
1802
		"	 * <pre>\n" + 
1803
		"	 * \n" + 
1804
		"	 * @return the inclusive end position\n" + 
1805
		"	 */\n" + 
1806
		"	public final int getInclusiveEnd() {\n" + 
1807
		"		return fOffset + fLength - 1;\n" + 
1808
		"	}\n" + 
1809
		"}\n"
1810
	);
1811
}
1725
}
1812
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java (-2 / +13 lines)
Lines 371-379 Link Here
371
 * @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#parseTag(int)
371
 * @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#parseTag(int)
372
 */
372
 */
373
protected boolean parseTag(int previousPosition) throws InvalidInputException {
373
protected boolean parseTag(int previousPosition) throws InvalidInputException {
374
	int ptr = this.astPtr;
374
375
	
375
	// Do not parse javadoc tag inside <pre>...</pre> tags
376
	if (this.htmlTagsPtr >= 0) {
377
		int ptr = this.htmlTagsPtr;
378
   		while (ptr >= 0) {
379
			if (getHtmlTagIndex(this.htmlTags[ptr--]) == JAVADOC_CODE_TAGS_ID) {
380
				if (this.textStart == -1) this.textStart = previousPosition;
381
				return true;
382
			}
383
		}
384
	}
385
376
	// Read tag name
386
	// Read tag name
387
	int ptr = this.astPtr;
377
	this.tagSourceStart = previousPosition;
388
	this.tagSourceStart = previousPosition;
378
	this.scanner.startPosition = this.index;
389
	this.scanner.startPosition = this.index;
379
	this.scanner.currentCharacter = readChar();
390
	this.scanner.currentCharacter = readChar();

Return to bug 239719