### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java,v retrieving revision 1.90 diff -u -r1.90 AbstractCommentParser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java 26 Jun 2009 09:49:37 -0000 1.90 +++ compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java 9 Nov 2009 12:17:53 -0000 @@ -130,7 +130,7 @@ this.astPtr = -1; this.identifierPtr = -1; this.currentTokenType = -1; - this.inlineTagStarted = false; + setInlineTagStarted(false); this.inlineTagStart = -1; this.lineStarted = false; this.returnStatement = null; @@ -207,7 +207,7 @@ // Start tag parsing only if we are on line beginning or at inline tag beginning if ((!this.lineStarted || previousChar == '{')) { if (this.inlineTagStarted) { - this.inlineTagStarted = false; + setInlineTagStarted(false); // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279 // Cannot have @ inside inline comment if (this.reportProblems) { @@ -228,7 +228,7 @@ pushText(this.textStart, textEndPosition); } } - this.inlineTagStarted = true; + setInlineTagStarted(true); invalidInlineTagLineEnd = this.lineEnd; } else if (this.textStart != -1 && this.textStart < invalidTagLineEnd) { pushText(this.textStart, invalidTagLineEnd); @@ -287,7 +287,7 @@ } refreshInlineTagPosition(previousPosition); if (!isFormatterParser) this.textStart = this.index; - this.inlineTagStarted = false; + setInlineTagStarted(false); } else { if (!this.lineStarted) { this.textStart = previousPosition; @@ -301,7 +301,7 @@ refreshReturnStatement(); } if (this.inlineTagStarted) { - this.inlineTagStarted = false; + setInlineTagStarted(false); // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279 // Cannot have opening brace in inline comment if (this.reportProblems) { @@ -400,7 +400,7 @@ pushText(this.textStart, textEndPosition); } refreshInlineTagPosition(textEndPosition); - this.inlineTagStarted = false; + setInlineTagStarted(false); } else if (this.lineStarted && this.textStart != -1 && this.textStart <= textEndPosition) { pushText(this.textStart, textEndPosition); } @@ -1544,6 +1544,13 @@ // do nothing by default } + /** + * @param started the inlineTagStarted to set + */ + protected void setInlineTagStarted(boolean started) { + this.inlineTagStarted = started; + } + /* * Entry point for recovery on invalid syntax */ Index: formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java,v retrieving revision 1.25 diff -u -r1.25 FormatterCommentParser.java --- formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java 24 Mar 2009 08:51:02 -0000 1.25 +++ formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java 9 Nov 2009 12:17:54 -0000 @@ -26,6 +26,7 @@ public class FormatterCommentParser extends JavadocParser implements IJavaDocTagConstants { char[][] htmlTags; int htmlTagsPtr = -1; + int inlineHtmlTagsPtr = -1; private boolean invalidTagName; public boolean parseHtmlTags; @@ -747,6 +748,23 @@ } } +/* + * Store the html tags level when entering an inline tag in case a wrong sequence + * of opening/closing tags is defined inside it. Then, when leaving the inline tag + * the level is reset to the entering value and avoid to wrongly attach subsequent + * html tags to node inside the inline tag last node... + */ +protected void setInlineTagStarted(boolean started) { + super.setInlineTagStarted(started); + if (started) { + this.inlineHtmlTagsPtr = this.htmlTagsPtr; + } else { + if (this.htmlTagsPtr > this.inlineHtmlTagsPtr) { + this.htmlTagsPtr = this.inlineHtmlTagsPtr; + } + } +} + public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("FormatterCommentParser\n"); //$NON-NLS-1$ #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v retrieving revision 1.6 diff -u -r1.6 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 5 Nov 2009 17:41:02 -0000 1.6 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 9 Nov 2009 12:17:56 -0000 @@ -1568,4 +1568,78 @@ DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); assertEquals("wrong indentation string", org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING, codeFormatter.createIndentationString(0)); } + +/** + * @bug 294500: [formatter] MalformedTreeException when formatting an invalid sequence of tags in a javadoc comment + * @test Verify that no MalformedTreeException occurs while formatting bug test cases + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=294500" + */ +public void testBug294500a() { + String source = + "package wkps3;\n" + + "/**\n" + + " * This sample produce an MalformedTreeException\n" + + " * when formatted.\n" + + " *\n" + + " *

First paragraph\n" + + " * {@link java.lang.String a simple\n" + + " * string}.\n" + + " *\n" + + " *

Second paragraph.\n" + + " *\n" + + " *

Third paragraph.

\n" + + " *\n" + + " */\n" + + "public class X01 {\n" + + "\n" + + "}\n"; + formatSource(source, + "package wkps3;\n" + + "\n" + + "/**\n" + + " * This sample produce an MalformedTreeException when formatted.\n" + + " * \n" + + " *

\n" + + " * First paragraph {@link java.lang.String a simple string}.\n" + + " * \n" + + " *

\n" + + " * Second paragraph.\n" + + " * \n" + + " *

\n" + + " * Third paragraph.\n" + + " *

\n" + + " * \n" + + " */\n" + + "public class X01 {\n" + + "\n" + + "}\n" + ); +} +public void testBug294500b() { + String source = + "package wkps3;\n" + + "/**\n" + + " * This sample produce an AIIOBE when formatting.\n" + + " *\n" + + " *

First paragraph\n" + + " * {@link java.lang.String a simple\n" + + " * string}.\n" + + " */\n" + + "public class X02 {\n" + + "\n" + + "}\n"; + formatSource(source, + "package wkps3;\n" + + "\n" + + "/**\n" + + " * This sample produce an AIIOBE when formatting.\n" + + " * \n" + + " *

\n" + + " * First paragraph {@link java.lang.String a simple string}.\n" + + " */\n" + + "public class X02 {\n" + + "\n" + + "}\n" + ); +} }