### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.377 diff -u -r1.377 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 28 Sep 2007 08:39:54 -0000 1.377 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 28 Sep 2007 10:10:26 -0000 @@ -1113,7 +1113,11 @@ if (lastComment >= 0 && this.javadocParser != null) { int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over, // do not report problem before last parsed comment while recovering code... - this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd; + if (this.javadocParser.shouldReportProblems) { + this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd; + } else { + this.javadocParser.reportProblems = false; + } if (this.javadocParser.checkDeprecation(lastComment)) { checkAndSetModifiers(ClassFileConstants.AccDeprecated); } Index: compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java,v retrieving revision 1.63 diff -u -r1.63 JavadocParser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java 27 Apr 2007 15:51:39 -0000 1.63 +++ compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java 28 Sep 2007 10:10:24 -0000 @@ -34,7 +34,11 @@ // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=153399 // Store value tag positions private long validValuePositions, invalidValuePositions; - + + // returns whether this JavadocParser should report errors or not (overrides reportProblems) + // see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=192449" + public boolean shouldReportProblems = true; + public JavadocParser(Parser sourceParser) { super(sourceParser); this.kind = COMPIL_PARSER | TEXT_VERIF; Index: model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java,v retrieving revision 1.23 diff -u -r1.23 CommentRecorderParser.java --- model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 27 Apr 2007 15:51:39 -0000 1.23 +++ model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 28 Sep 2007 10:10:26 -0000 @@ -63,11 +63,15 @@ } checkDeprecated = true; int commentSourceEnd = this.scanner.commentStops[lastCommentIndex] - 1; //stop is one over - // do not report problem before last parsed comment while recovering code... - this.javadocParser.reportProblems = this.currentElement == null || commentSourceEnd > this.lastJavadocEnd; + if (this.javadocParser.shouldReportProblems) { + this.javadocParser.reportProblems = this.currentElement == null || commentSourceEnd > this.lastJavadocEnd; + } else { + this.javadocParser.reportProblems = false; + } deprecated = this.javadocParser.checkDeprecation(lastCommentIndex); this.javadoc = this.javadocParser.docComment; + if (currentElement == null) this.lastJavadocEnd = commentSourceEnd; break nextComment; } if (deprecated) { Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v retrieving revision 1.75 diff -u -r1.75 SourceElementParser.java --- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 23 Jul 2007 18:42:09 -0000 1.75 +++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 28 Sep 2007 10:10:26 -0000 @@ -176,9 +176,13 @@ // check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored) while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions if (lastComment >= 0 && this.javadocParser != null) { - int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over, + int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over // do not report problem before last parsed comment while recovering code... - this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd; + if (this.javadocParser.shouldReportProblems) { + this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd; + } else { + this.javadocParser.reportProblems = false; + } if (this.javadocParser.checkDeprecation(lastComment)) { checkAndSetModifiers(ClassFileConstants.AccDeprecated); } Index: codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java,v retrieving revision 1.5 diff -u -r1.5 SelectionJavadocParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java 6 Mar 2007 02:38:50 -0000 1.5 +++ codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java 28 Sep 2007 10:10:24 -0000 @@ -28,6 +28,8 @@ public SelectionJavadocParser(SelectionParser sourceParser) { super(sourceParser); + this.shouldReportProblems = false; + this.reportProblems = false; this.kind = SELECTION_PARSER | TEXT_PARSE; } Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionJavadocParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionJavadocParser.java,v retrieving revision 1.28 diff -u -r1.28 CompletionJavadocParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionJavadocParser.java 6 Mar 2007 02:38:48 -0000 1.28 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionJavadocParser.java 28 Sep 2007 10:10:24 -0000 @@ -57,7 +57,6 @@ super(sourceParser); this.scanner = new CompletionScanner(ClassFileConstants.JDK1_3); this.kind = COMPLETION_PARSER | TEXT_PARSE; - this.reportProblems = false; initLevelTags(); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/SelectionJavadocTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionJavadocTest.java,v retrieving revision 1.5 diff -u -r1.5 SelectionJavadocTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/SelectionJavadocTest.java 29 Mar 2006 03:50:23 -0000 1.5 +++ src/org/eclipse/jdt/core/tests/compiler/parser/SelectionJavadocTest.java 28 Sep 2007 10:10:28 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.core.tests.compiler.parser; import java.util.Locale; +import java.util.Map; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.codeassist.select.SelectionJavadoc; @@ -42,8 +43,8 @@ public class SelectionJavadocTest extends AbstractSelectionTest { String source; - StringBuffer result; ICompilationUnit unit; + StringBuffer result; public SelectionJavadocTest(String testName) { super(testName); @@ -58,7 +59,7 @@ return buildAllCompliancesTestSuite(SelectionJavadocTest.class); } - class SelectionVisitor extends ASTVisitor { + class JavadocSelectionVisitor extends ASTVisitor { public boolean visit(ConstructorDeclaration constructor, ClassScope scope) { if (constructor.javadoc != null) { @@ -108,7 +109,7 @@ return super.visit(type, scope); } } - + protected void assertValid(String expected) { String actual = this.result.toString(); if (!actual.equals(expected)) { @@ -134,11 +135,11 @@ /* * Parse a method with selectionNode check */ - protected void findJavadoc(String selection) { - findJavadoc(selection, 1); + protected CompilationResult findJavadoc(String selection) { + return findJavadoc(selection, 1); } - protected void findJavadoc(String selection, int occurences) { + protected CompilationResult findJavadoc(String selection, int occurences) { // Verify unit assertNotNull("Missing compilation unit!", this.unit); @@ -161,9 +162,21 @@ parser.getMethodBodies(unitDecl); // Visit compilation unit declaration to find javadoc - unitDecl.traverse(new SelectionVisitor(), unitDecl.scope); + unitDecl.traverse(new JavadocSelectionVisitor(), unitDecl.scope); + + // Return the unit declaration result + return unitDecl.compilationResult(); } + protected Map getCompilerOptions() { + Map optionsMap = super.getCompilerOptions(); + optionsMap.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING); + optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + optionsMap.put(CompilerOptions.OPTION_ReportMissingJavadoc, CompilerOptions.WARNING); + return optionsMap; + } + public void test01() { setUnit("Test.java", "public class Test {\n" + @@ -861,4 +874,31 @@ "/***/\n" ); } + + /** + * @bug 192449: [javadoc][assist] SelectionJavadocParser should not report problems + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=192449" + */ + public void test26() { + setUnit("Test.java", + "/**\n" + + " * @see \n" + + " * @throws noException\n" + + " * @see Test\n" + + " * @see Other\n" + + " */\n" + + "public class Test {\n" + + " /**\n" + + " * @see\n" + + " * @param noParam\n" + + " * @throws noException\n" + + " */\n" + + " void bar() {}\n" + + "}" + ); + + // parse and check results + CompilationResult compilationResult = findJavadoc("Other"); + assertEquals("SelectionJavadocParser should not report errors", "", Util.getProblemLog(compilationResult, false, false)); + } } Index: src/org/eclipse/jdt/core/tests/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v retrieving revision 1.57 diff -u -r1.57 Util.java --- src/org/eclipse/jdt/core/tests/util/Util.java 5 Jul 2007 15:11:25 -0000 1.57 +++ src/org/eclipse/jdt/core/tests/util/Util.java 28 Sep 2007 10:10:28 -0000 @@ -20,8 +20,10 @@ import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.tests.compiler.regression.Requestor; +import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.Compiler; import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; import org.eclipse.jdt.internal.compiler.IProblemFactory; @@ -31,6 +33,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; public class Util { // Trace for delete operation /* @@ -1230,4 +1233,55 @@ } } } +/** + * Returns the compilation errors / warnings for the given CompilationResult. + * + * @param compilationResult the compilation result + * @param showCategory + * @param showWarningToken + * @return String the problem log + */ +public static String getProblemLog(CompilationResult compilationResult, boolean showCategory, boolean showWarningToken) { + StringBuffer buffer = new StringBuffer(100); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + CategorizedProblem[] problems = compilationResult.getAllProblems(); + int count = problems.length; + int problemCount = 0; + char[] unitSource = compilationResult.compilationUnit.getContents(); + for (int i = 0; i < count; i++) { + DefaultProblem problem = (DefaultProblem) problems[i]; + if (problem != null) { + if (problemCount == 0) + buffer.append("----------\n"); + problemCount++; + buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); + buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\')); + try { + buffer.append(problem.errorReportSource(unitSource)); + buffer.append("\n"); + if (showCategory) { + String category = problem.getInternalCategoryMessage(); + if (category != null) { + buffer.append("[@cat:").append(category).append("] "); + } + } + if (showWarningToken) { + long irritant = ProblemReporter.getIrritant(problem.getID()); + if (irritant != 0) { + String warningToken = CompilerOptions.warningTokenFromIrritant(irritant); + if (warningToken != null) { + buffer.append("[@sup:").append(warningToken).append("] "); + } + } + } + buffer.append(problem.getMessage()); + buffer.append("\n"); + } catch (Exception e) { + } + buffer.append("----------\n"); + } + } + } + return buffer.toString(); +} } Index: src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java,v retrieving revision 1.16 diff -u -r1.16 Requestor.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java 29 Mar 2006 03:50:23 -0000 1.16 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java 28 Sep 2007 10:10:28 -0000 @@ -16,14 +16,11 @@ import junit.framework.Assert; -import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse.jdt.internal.compiler.IProblemFactory; -import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; -import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; public class Requestor extends Assert implements ICompilerRequestor { public boolean hasErrors = false; @@ -45,48 +42,8 @@ this.showWarningToken = showWarningToken; } public void acceptResult(CompilationResult compilationResult) { - StringBuffer buffer = new StringBuffer(100); - hasErrors |= compilationResult.hasErrors(); - if (compilationResult.hasProblems() || compilationResult.hasTasks()) { - CategorizedProblem[] problems = compilationResult.getAllProblems(); - int count = problems.length; - int problemCount = 0; - char[] unitSource = compilationResult.compilationUnit.getContents(); - for (int i = 0; i < count; i++) { - DefaultProblem problem = (DefaultProblem) problems[i]; - if (problem != null) { - if (problemCount == 0) - buffer.append("----------\n"); - problemCount++; - buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); - buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\')); - try { - buffer.append(problem.errorReportSource(unitSource)); - buffer.append("\n"); - if (showCategory) { - String category = problem.getInternalCategoryMessage(); - if (category != null) { - buffer.append("[@cat:").append(category).append("] "); - } - } - if (showWarningToken) { - long irritant = ProblemReporter.getIrritant(problem.getID()); - if (irritant != 0) { - String warningToken = CompilerOptions.warningTokenFromIrritant(irritant); - if (warningToken != null) { - buffer.append("[@sup:").append(warningToken).append("] "); - } - } - } - buffer.append(problem.getMessage()); - buffer.append("\n"); - } catch (Exception e) { - } - buffer.append("----------\n"); - } - } - problemLog += buffer.toString(); - } + this.hasErrors |= compilationResult.hasErrors(); + this.problemLog += Util.getProblemLog(compilationResult, this.showCategory, this.showWarningToken); outputClassFiles(compilationResult); if (this.clientRequestor != null) { this.clientRequestor.acceptResult(compilationResult);