Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptff2004-09-20 04:54:18 -0400
committerptff2004-09-20 04:54:18 -0400
commite5bfb5b8c46b2fe09294f92989edfab52d5d2f0c (patch)
tree4535ad83d578f3dcde940f48eb2024e70ed8ff91
parent753eb607da2330ab34bba435627056e2e0dd9105 (diff)
downloadeclipse.jdt.core-e5bfb5b8c46b2fe09294f92989edfab52d5d2f0c.tar.gz
eclipse.jdt.core-e5bfb5b8c46b2fe09294f92989edfab52d5d2f0c.tar.xz
eclipse.jdt.core-e5bfb5b8c46b2fe09294f92989edfab52d5d2f0c.zip
73348, 73995
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java8
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java101
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java56
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java30
6 files changed, 159 insertions, 41 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java
index 7cf6f15141..26b2d80f29 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java
@@ -1077,7 +1077,7 @@ public class JavadocTestForInterface extends JavadocTest {
+ " * Invalid javadoc tags with valid deprecation\n"
+ " *\n"
+ " * @param\n"
- + " * @return\n"
+ + " * @return String\n"
+ " * @throws Unknown\n"
+ " * @see \"Invalid\n"
+ " * @see Unknown\n"
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java
index de09cae88e..2c2716c8ad 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java
@@ -180,7 +180,7 @@ public class JavadocTestForMethod extends JavadocTest {
+ " * Invalid javadoc tags with valid deprecation at end\n"
+ " *\n"
+ " * @param\n"
- + " * @return\n"
+ + " * @return String\n"
+ " * @throws Unknown\n"
+ " * @see \"Invalid\n"
+ " * @see Unknown\n"
@@ -285,7 +285,7 @@ public class JavadocTestForMethod extends JavadocTest {
+ " *\n"
+ " * @deprecated\n"
+ " * @param\n"
- + " * @return\n"
+ + " * @return String\n"
+ " * @throws Unknown\n"
+ " * @exception IllegalArgumentException Valid throws tag\n"
+ " * @see \"Invalid\n"
@@ -389,7 +389,7 @@ public class JavadocTestForMethod extends JavadocTest {
+ " * Invalid javadoc tags with valid deprecation in the middle\n"
+ " *\n"
+ " * @param\n"
- + " * @return\n"
+ + " * @return String\n"
+ " * @throws Unknown\n"
+ " * @exception IllegalArgumentException Valid throws tag\n"
+ " * @see \"Invalid\n"
@@ -1658,7 +1658,7 @@ public class JavadocTestForMethod extends JavadocTest {
+ " /**\n"
+ " * Invalid return declaration\n"
+ " *\n"
- + " * @return\n"
+ + " * @return String\n"
+ " * @return Dimension\n"
+ " */\n"
+ " public double s_foo() {\n"
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java
index 548bc450d9..acda1062ea 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java
@@ -36,7 +36,7 @@ public class JavadocTestMixed extends JavadocTest {
static {
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
// testsNames = new String[] {
-// "Bug68726conform1", "Bug68726conform2", "Bug68726negative1", "Bug68726negative2"
+// "Bug73995"
// };
// Numbers of tests to run: "test<number>" will be run for each number of this array
// testsNumbers = new int[] { 3, 7, 10, 21 };
@@ -1771,7 +1771,7 @@ public class JavadocTestMixed extends JavadocTest {
" * IllegalAccessException\n" +
" * @throws\n" +
" * NullPointerException tag description not empty\n" +
- " * @return\n" +
+ " * @return int\n" +
" * an integer\n" +
" * @see\n" +
" * String\n" +
@@ -3071,17 +3071,17 @@ public class JavadocTestMixed extends JavadocTest {
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" /**@return*/\n" +
- " ^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" /**@return */\n" +
- " ^^^^^^^^^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" /**@return****/\n" +
- " ^^^^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n" +
"4. ERROR in X.java (at line 9)\n" +
@@ -3109,12 +3109,12 @@ public class JavadocTestMixed extends JavadocTest {
"----------\n" +
"1. ERROR in X.java (at line 3)\n" +
" * @return* */\n" +
- " ^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" /**@return** **/\n" +
- " ^^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n"
);
@@ -3135,7 +3135,7 @@ public class JavadocTestMixed extends JavadocTest {
"----------\n" +
"1. ERROR in X.java (at line 3)\n" +
" * @return#\n" +
- " ^^^^^^^\n" +
+ " ^^^^^^\n" +
"Javadoc: Invalid tag\n" +
"----------\n"
);
@@ -3723,4 +3723,89 @@ public class JavadocTestMixed extends JavadocTest {
"----------\n"
);
}
+
+ /**
+ * Test fix for bug 73348: [Javadoc] Missing description for return tag is not always warned
+ * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=73348">73348</a>
+ */
+ public void testBug73348conform() {
+ reportMissingJavadocTags = CompilerOptions.IGNORE;
+ reportMissingJavadocComments = CompilerOptions.IGNORE;
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " /**\n" +
+ " * @return \n" +
+ " * int\n" +
+ " */\n" +
+ " public int foo1() {return 0; }\n" +
+ " /**\n" +
+ " * @return \n" +
+ " * int\n" +
+ " * @see Object\n" +
+ " */\n" +
+ " public int foo2() {return 0; }\n" +
+ "}\n",
+ }
+ );
+ }
+ public void testBug73348negative() {
+ reportMissingJavadocComments = CompilerOptions.IGNORE;
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " /**\n" +
+ " * @return\n" +
+ " * @see Object\n" +
+ " */\n" +
+ " public int foo1() {return 0; }\n" +
+ " /**\n" +
+ " * @return \n" +
+ " * @see Object\n" +
+ " */\n" +
+ " public int foo2() {return 0; }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " * @return\n" +
+ " ^^^^^^\n" +
+ "Javadoc: Invalid tag\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " * @return \n" +
+ " ^^^^^^\n" +
+ "Javadoc: Invalid tag\n" +
+ "----------\n"
+ );
+ }
+
+ /**
+ * Test fix for bug 73995: [Javadoc] Wrong warning for missing return type description for @return {@inheritDoc}
+ * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=73995">73995</a>
+ */
+ public void testBug73995() {
+ reportMissingJavadocTags = CompilerOptions.IGNORE;
+ reportMissingJavadocComments = CompilerOptions.IGNORE;
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " /**\n" +
+ " * @return {@link Object} \n" +
+ " */\n" +
+ " public int foo1() {return 0; }\n" +
+ " /** @return {@inheritedDoc} */\n" +
+ " public int foo2() {return 0; }\n" +
+ " /**\n" +
+ " * @return\n" +
+ " * {@unknown_tag}\n" +
+ " */\n" +
+ " public int foo3() {return 0; }\n" +
+ "}\n",
+ }
+ );
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java
index 8a53e1bac7..4633195db6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java
@@ -16,6 +16,7 @@ import org.eclipse.jdt.internal.compiler.lookup.*;
public class JavadocReturnStatement extends ReturnStatement {
public char[] description;
+ public boolean empty = true;
public JavadocReturnStatement(int s, int e, char[] descr) {
super(null, s, e);
@@ -34,6 +35,8 @@ public class JavadocReturnStatement extends ReturnStatement {
: VoidBinding;
if (methodType == null || methodType == VoidBinding) {
scope.problemReporter().javadocUnexpectedTag(this.sourceStart, this.sourceEnd);
+ } else if (this.empty) {
+ scope.problemReporter().javadocInvalidTag(this.sourceStart, this.sourceEnd);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
index ca99505046..ba54dd0819 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
@@ -15,6 +15,7 @@ import java.util.List;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.InvalidInputException;
+import org.eclipse.jdt.internal.compiler.ast.JavadocReturnStatement;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
/**
@@ -60,6 +61,9 @@ public abstract class AbstractCommentParser {
protected boolean lineStarted = false, inlineTagStarted = false;
protected int kind;
protected int[] lineEnds;
+
+ // Store when return tag is parsed
+ protected int returnTagPtr= -2;
// Private fields
private int currentTokenType = -1;
@@ -109,7 +113,7 @@ public abstract class AbstractCommentParser {
readChar(); // first '*'
char nextCharacter= readChar(); // second '*'
- // Init local variables
+ // Init variables
this.astLengthPtr = -1;
this.astPtr = -1;
this.currentTokenType = -1;
@@ -119,6 +123,7 @@ public abstract class AbstractCommentParser {
this.returnStatement = null;
this.inherited = false;
this.deprecated = false;
+ this.returnTagPtr = -2;
this.linePtr = getLineNumber(javadocStart);
this.lastLinePtr = getLineNumber(javadocEnd);
this.lineEnd = (this.linePtr == this.lastLinePtr) ? this.endComment : this.scanner.getLineEnd(this.linePtr);
@@ -191,6 +196,14 @@ public abstract class AbstractCommentParser {
this.scanner.resetTo(this.index, this.endComment);
this.currentTokenType = -1; // flush token cache at line begin
try {
+ // In case of previous return tag, set it to not empty if parsing an inline tag
+ if (this.kind == COMPIL_PARSER && this.returnTagPtr != -2 && this.returnStatement != null) {
+ this.returnTagPtr = -2;
+ JavadocReturnStatement javadocReturn = (JavadocReturnStatement) this.returnStatement;
+ javadocReturn.empty = javadocReturn.empty && !this.inlineTagStarted;
+ }
+
+ // Read tag name
int token = readTokenAndConsume();
this.tagSourceStart = this.scanner.getCurrentTokenStartPosition();
this.tagSourceEnd = this.scanner.getCurrentTokenEndPosition();
@@ -289,13 +302,14 @@ public abstract class AbstractCommentParser {
break;
case TerminalTokens.TokenNamereturn :
valid = parseReturn();
- // verify characters after return tag (we're expecting text description)
+ /* verify characters after return tag (we're expecting text description)
if(!verifyCharsAfterReturnTag(this.index)) {
if (this.sourceParser != null) {
int end = this.starPosition == -1 || this.lineEnd<this.starPosition ? this.lineEnd : this.starPosition;
this.sourceParser.problemReporter().javadocInvalidTag(this.tagSourceStart, end);
}
}
+ */
break;
case TerminalTokens.TokenNamethrows :
valid = parseThrows(true);
@@ -1318,40 +1332,28 @@ public abstract class AbstractCommentParser {
/*
* Verify that some text exists after a @return tag. Text must be different than
* end of comment which may be preceeding by several '*' chars.
- */
+ *
private boolean verifyCharsAfterReturnTag(int startPosition) {
// Whitespace or inline tag closing brace
int previousPosition = this.index;
char ch = readChar();
- boolean malformed = true;
- while (Character.isWhitespace(ch)) {
- malformed = false;
+ this.starPosition = -1;
+ while (Character.isWhitespace(ch) || ch == '*') {
previousPosition = this.index;
+ if (ch == '*') {
+ // valid whatever the number of star before last '/'
+ this.starPosition = previousPosition;
+ }
ch = readChar();
}
- // End of comment
- this.starPosition = -1;
- nextChar: while (this.index<this.source.length) {
- switch (ch) {
- case '*':
- // valid whatever the number of star before last '/'
- this.starPosition = previousPosition;
- break;
- case '/':
- if (this.starPosition >= startPosition) { // valid only if a star was previous character
- return false;
- }
- default :
- // valid if any other character is encountered, even white spaces
- this.index = startPosition;
- return !malformed;
-
- }
- previousPosition = this.index;
- ch = readChar();
+ // Look at possible end of comment
+ if (this.starPosition >= startPosition) { // valid only if a star was previous character
+ return ch == '/';
}
+
+ // valid if next encountered is not, even white spaces
this.index = startPosition;
- return false;
+ return ch != '@';
}
/*
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
index 7786636fff..58727cbf1d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
@@ -271,6 +271,7 @@ public class JavadocParser extends AbstractCommentParser {
protected boolean parseReturn() {
if (this.returnStatement == null) {
this.returnStatement = createReturnStatement();
+ this.returnTagPtr = this.astPtr;
return true;
}
if (this.sourceParser != null) this.sourceParser.problemReporter().javadocDuplicatedReturnTag(
@@ -370,7 +371,34 @@ public class JavadocParser extends AbstractCommentParser {
* @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushText(int, int)
*/
protected void pushText(int start, int end) {
- // compiler does not matter of text
+ // In case of previous return tag, verify that text make it not empty
+ if (this.returnTagPtr != -2 && this.returnStatement != null) {
+ int position = this.index;
+ this.index = start;
+ boolean empty = true;
+ boolean star = false;
+ char ch = readChar();
+ // Look for first character other than white or '*'
+ if (Character.isWhitespace(ch) || start>(this.tagSourceEnd+1)) {
+ while (this.index <= end && empty) {
+ if (!star) {
+ empty = Character.isWhitespace(ch) || ch == '*';
+ star = ch == '*';
+ } else if (ch != '*') {
+ empty = false;
+ break;
+ }
+ ch = readChar();
+ }
+ }
+ // Store result in previous return tag
+ ((JavadocReturnStatement)this.returnStatement).empty = empty;
+ // Reset position and current ast ptr if we are on a different tag than previous return one
+ this.index = position;
+ if (this.returnTagPtr != this.astPtr) {
+ this.returnTagPtr = -2;
+ }
+ }
}
/*

Back to the top