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 1781-1784 Link Here
1781
		"}\n"
1781
		"}\n"
1782
	);
1782
	);
1783
}
1783
}
1784
1785
/**
1786
 * @bug 239719: [formatter] Code formatter destroys pre formatted javadoc comments
1787
 * @test Ensure that annotations inside <pre>...</pre> tags are not considered as javadoc tags
1788
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=239719"
1789
 */
1790
public void testBug239719() throws JavaModelException {
1791
	String source = 
1792
		"/**\n" + 
1793
		" * <pre>\n" + 
1794
		" *  public class Test implements Runnable\n" + 
1795
		" *  {\n" + 
1796
		" *    @Override\n" + 
1797
		" *    public void run()\n" + 
1798
		" *    { \n" + 
1799
		" *      // Hello really bad Ganymede formatter !!!\n" + 
1800
		" *      // Shit happens when somebody tries to change a running system\n" + 
1801
		" *      System.out.println(\"Press Shift+Ctrl+F to format\");\n" + 
1802
		" *    }\n" + 
1803
		" *  }</pre>\n" + 
1804
		" */\n" + 
1805
		" public class Test \n" + 
1806
		" {\n" + 
1807
		" }\n";
1808
	formatSource(source,
1809
		"/**\n" + 
1810
		" * <pre>\n" + 
1811
		" * public class Test implements Runnable {\n" + 
1812
		" * 	&#064;Override\n" + 
1813
		" * 	public void run() {\n" + 
1814
		" * 		// Hello really bad Ganymede formatter !!!\n" + 
1815
		" * 		// Shit happens when somebody tries to change a running system\n" + 
1816
		" * 		System.out.println(&quot;Press Shift+Ctrl+F to format&quot;);\n" + 
1817
		" * 	}\n" + 
1818
		" * }\n" + 
1819
		" * </pre>\n" + 
1820
		" */\n" + 
1821
		"public class Test {\n" + 
1822
		"}\n"
1823
	);
1824
}
1825
public void testBug239719b() throws JavaModelException {
1826
	String source = 
1827
		"public class X01 {\n" + 
1828
		"	\n" + 
1829
		"	private int fLength;\n" + 
1830
		"	private int fOffset;\n" + 
1831
		"\n" + 
1832
		"	/**\n" + 
1833
		"	 * Returns the inclusive end position of this edit. The inclusive end\n" + 
1834
		"	 * position denotes the last character of the region manipulated by\n" + 
1835
		"	 * this edit. The returned value is the result of the following\n" + 
1836
		"	 * calculation:\n" + 
1837
		"	 * <pre>\n" + 
1838
		"	 *   getOffset() + getLength() - 1;\n" + 
1839
		"	 * <pre>\n" + 
1840
		"	 * \n" + 
1841
		"	 * @return the inclusive end position\n" + 
1842
		"	 */\n" + 
1843
		"	public final int getInclusiveEnd() {\n" + 
1844
		"		return fOffset + fLength - 1;\n" + 
1845
		"	}\n" + 
1846
		"}\n";
1847
	formatSource(source,
1848
		"public class X01 {\n" + 
1849
		"\n" + 
1850
		"	private int fLength;\n" + 
1851
		"	private int fOffset;\n" + 
1852
		"\n" + 
1853
		"	/**\n" + 
1854
		"	 * Returns the inclusive end position of this edit. The inclusive end\n" + 
1855
		"	 * position denotes the last character of the region manipulated by this\n" + 
1856
		"	 * edit. The returned value is the result of the following calculation:\n" + 
1857
		"	 * \n" + 
1858
		"	 * <pre>\n" + 
1859
		"	 * getOffset() + getLength() - 1;\n" + 
1860
		"	 * \n" + 
1861
		"	 * <pre>\n" + 
1862
		"	 * \n" + 
1863
		"	 * @return the inclusive end position\n" + 
1864
		"	 */\n" + 
1865
		"	public final int getInclusiveEnd() {\n" + 
1866
		"		return fOffset + fLength - 1;\n" + 
1867
		"	}\n" + 
1868
		"}\n"
1869
	);
1870
}
1784
}
1871
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java (-1 / +12 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
	// 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
	}
375
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