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

(-)compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java (-6 / +13 lines)
Lines 130-136 Link Here
130
			this.astPtr = -1;
130
			this.astPtr = -1;
131
			this.identifierPtr = -1;
131
			this.identifierPtr = -1;
132
			this.currentTokenType = -1;
132
			this.currentTokenType = -1;
133
			this.inlineTagStarted = false;
133
			setInlineTagStarted(false);
134
			this.inlineTagStart = -1;
134
			this.inlineTagStart = -1;
135
			this.lineStarted = false;
135
			this.lineStarted = false;
136
			this.returnStatement = null;
136
			this.returnStatement = null;
Lines 207-213 Link Here
207
						// Start tag parsing only if we are on line beginning or at inline tag beginning
207
						// Start tag parsing only if we are on line beginning or at inline tag beginning
208
						if ((!this.lineStarted || previousChar == '{')) {
208
						if ((!this.lineStarted || previousChar == '{')) {
209
							if (this.inlineTagStarted) {
209
							if (this.inlineTagStarted) {
210
								this.inlineTagStarted = false;
210
								setInlineTagStarted(false);
211
								// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279
211
								// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279
212
								// Cannot have @ inside inline comment
212
								// Cannot have @ inside inline comment
213
								if (this.reportProblems) {
213
								if (this.reportProblems) {
Lines 228-234 Link Here
228
										pushText(this.textStart, textEndPosition);
228
										pushText(this.textStart, textEndPosition);
229
									}
229
									}
230
								}
230
								}
231
								this.inlineTagStarted = true;
231
								setInlineTagStarted(true);
232
								invalidInlineTagLineEnd = this.lineEnd;
232
								invalidInlineTagLineEnd = this.lineEnd;
233
							} else if (this.textStart != -1 && this.textStart < invalidTagLineEnd) {
233
							} else if (this.textStart != -1 && this.textStart < invalidTagLineEnd) {
234
								pushText(this.textStart, invalidTagLineEnd);
234
								pushText(this.textStart, invalidTagLineEnd);
Lines 287-293 Link Here
287
							}
287
							}
288
							refreshInlineTagPosition(previousPosition);
288
							refreshInlineTagPosition(previousPosition);
289
							if (!isFormatterParser) this.textStart = this.index;
289
							if (!isFormatterParser) this.textStart = this.index;
290
							this.inlineTagStarted = false;
290
							setInlineTagStarted(false);
291
						} else {
291
						} else {
292
							if (!this.lineStarted) {
292
							if (!this.lineStarted) {
293
								this.textStart = previousPosition;
293
								this.textStart = previousPosition;
Lines 301-307 Link Here
301
							refreshReturnStatement();
301
							refreshReturnStatement();
302
						}
302
						}
303
						if (this.inlineTagStarted) {
303
						if (this.inlineTagStarted) {
304
							this.inlineTagStarted = false;
304
							setInlineTagStarted(false);
305
							// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279
305
							// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279
306
							// Cannot have opening brace in inline comment
306
							// Cannot have opening brace in inline comment
307
							if (this.reportProblems) {
307
							if (this.reportProblems) {
Lines 400-406 Link Here
400
					pushText(this.textStart, textEndPosition);
400
					pushText(this.textStart, textEndPosition);
401
				}
401
				}
402
				refreshInlineTagPosition(textEndPosition);
402
				refreshInlineTagPosition(textEndPosition);
403
				this.inlineTagStarted = false;
403
				setInlineTagStarted(false);
404
			} else if (this.lineStarted && this.textStart != -1 && this.textStart <= textEndPosition) {
404
			} else if (this.lineStarted && this.textStart != -1 && this.textStart <= textEndPosition) {
405
				pushText(this.textStart, textEndPosition);
405
				pushText(this.textStart, textEndPosition);
406
			}
406
			}
Lines 1544-1549 Link Here
1544
		// do nothing by default
1544
		// do nothing by default
1545
	}
1545
	}
1546
1546
1547
	/**
1548
	 * @param started the inlineTagStarted to set
1549
	 */
1550
	protected void setInlineTagStarted(boolean started) {
1551
		this.inlineTagStarted = started;
1552
	}
1553
1547
	/*
1554
	/*
1548
	 * Entry point for recovery on invalid syntax
1555
	 * Entry point for recovery on invalid syntax
1549
	 */
1556
	 */
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java (+18 lines)
Lines 26-31 Link Here
26
public class FormatterCommentParser extends JavadocParser implements IJavaDocTagConstants {
26
public class FormatterCommentParser extends JavadocParser implements IJavaDocTagConstants {
27
	char[][] htmlTags;
27
	char[][] htmlTags;
28
	int htmlTagsPtr = -1;
28
	int htmlTagsPtr = -1;
29
	int inlineHtmlTagsPtr = -1;
29
	private boolean invalidTagName;
30
	private boolean invalidTagName;
30
	public boolean parseHtmlTags;
31
	public boolean parseHtmlTags;
31
32
Lines 747-752 Link Here
747
	}
748
	}
748
}
749
}
749
750
751
/*
752
 * Store the html tags level when entering an inline tag in case a wrong sequence
753
 * of opening/closing tags is defined inside it. Then, when leaving the inline tag
754
 * the level is reset to the entering value and avoid to wrongly attach subsequent
755
 * html tags to node inside the inline tag last node...
756
 */
757
protected void setInlineTagStarted(boolean started) {
758
	super.setInlineTagStarted(started);
759
	if (started) {
760
		this.inlineHtmlTagsPtr = this.htmlTagsPtr;
761
	} else {
762
		if (this.htmlTagsPtr > this.inlineHtmlTagsPtr) {
763
			this.htmlTagsPtr = this.inlineHtmlTagsPtr;
764
		}
765
	}
766
}
767
750
public String toString() {
768
public String toString() {
751
	StringBuffer buffer = new StringBuffer();
769
	StringBuffer buffer = new StringBuffer();
752
	buffer.append("FormatterCommentParser\n"); //$NON-NLS-1$
770
	buffer.append("FormatterCommentParser\n"); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+74 lines)
Lines 1568-1571 Link Here
1568
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1568
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1569
	assertEquals("wrong indentation string", org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING, codeFormatter.createIndentationString(0));
1569
	assertEquals("wrong indentation string", org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING, codeFormatter.createIndentationString(0));
1570
}
1570
}
1571
1572
/**
1573
 * @bug 294500: [formatter] MalformedTreeException when formatting an invalid sequence of <code> tags in a javadoc comment
1574
 * @test Verify that no MalformedTreeException occurs while formatting bug test cases
1575
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=294500"
1576
 */
1577
public void testBug294500a() {
1578
	String source =
1579
		"package wkps3;\n" + 
1580
		"/**\n" + 
1581
		" * This sample produce an MalformedTreeException\n" + 
1582
		" * when formatted.\n" + 
1583
		" *\n" + 
1584
		" * <p> First paragraph\n" + 
1585
		" * {@link java.lang.String </code>a simple\n" + 
1586
		" * string<code>}.\n" + 
1587
		" *\n" + 
1588
		" * <p> Second paragraph.\n" + 
1589
		" *\n" + 
1590
		" * <p> Third paragraph. </p>\n" + 
1591
		" *\n" + 
1592
		" */\n" + 
1593
		"public class X01 {\n" + 
1594
		"\n" + 
1595
		"}\n";
1596
	formatSource(source,
1597
		"package wkps3;\n" + 
1598
		"\n" + 
1599
		"/**\n" + 
1600
		" * This sample produce an MalformedTreeException when formatted.\n" + 
1601
		" * \n" + 
1602
		" * <p>\n" + 
1603
		" * First paragraph {@link java.lang.String </code>a simple string<code>}.\n" + 
1604
		" * \n" + 
1605
		" * <p>\n" + 
1606
		" * Second paragraph.\n" + 
1607
		" * \n" + 
1608
		" * <p>\n" + 
1609
		" * Third paragraph.\n" + 
1610
		" * </p>\n" + 
1611
		" * \n" + 
1612
		" */\n" + 
1613
		"public class X01 {\n" + 
1614
		"\n" + 
1615
		"}\n"
1616
	);
1617
}
1618
public void testBug294500b() {
1619
	String source =
1620
		"package wkps3;\n" + 
1621
		"/**\n" + 
1622
		" * This sample produce an AIIOBE when formatting.\n" + 
1623
		" *\n" + 
1624
		" * <p> First paragraph\n" + 
1625
		" * {@link java.lang.String </code>a simple\n" + 
1626
		" * string<code>}.\n" + 
1627
		" */\n" + 
1628
		"public class X02 {\n" + 
1629
		"\n" + 
1630
		"}\n";
1631
	formatSource(source,
1632
		"package wkps3;\n" + 
1633
		"\n" + 
1634
		"/**\n" + 
1635
		" * This sample produce an AIIOBE when formatting.\n" + 
1636
		" * \n" + 
1637
		" * <p>\n" + 
1638
		" * First paragraph {@link java.lang.String </code>a simple string<code>}.\n" + 
1639
		" */\n" + 
1640
		"public class X02 {\n" + 
1641
		"\n" + 
1642
		"}\n"
1643
	);
1644
}
1571
}
1645
}

Return to bug 294500