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

(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java (-64 / +184 lines)
Lines 73-78 Link Here
73
		options.put(CompilerOptions.OPTION_ReportDeprecation, reportDeprecation);
73
		options.put(CompilerOptions.OPTION_ReportDeprecation, reportDeprecation);
74
		options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
74
		options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
75
		options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
75
		options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
76
		options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
76
		return options;
77
		return options;
77
	}
78
	}
78
	/* (non-Javadoc)
79
	/* (non-Javadoc)
Lines 4811-4877 Link Here
4811
	}
4812
	}
4812
4813
4813
	/**
4814
	/**
4814
	 * @bug 160015: [1.5][javadoc] Missing warning on autoboxing compatible methods
4815
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=160015"
4816
	 */
4817
	public void testBug160015() {
4818
		runNegativeTest(new String[] {
4819
				"Test.java",
4820
				"/**\n" + 
4821
				" * @see #method(Long) Warning!\n" + 
4822
				" */\n" + 
4823
				"public class Test {\n" + 
4824
				"	public void method(long l) {}\n" + 
4825
				"	/**\n" + 
4826
				"	 * @see #method(Long) Warning!\n" + 
4827
				"	 */\n" + 
4828
				"	void bar() {}\n" + 
4829
				"}\n"
4830
			},
4831
			"----------\n" + 
4832
			"1. ERROR in Test.java (at line 2)\n" + 
4833
			"	* @see #method(Long) Warning!\n" + 
4834
			"	        ^^^^^^\n" + 
4835
			"Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + 
4836
			"----------\n" + 
4837
			"2. ERROR in Test.java (at line 7)\n" + 
4838
			"	* @see #method(Long) Warning!\n" + 
4839
			"	        ^^^^^^\n" + 
4840
			"Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + 
4841
			"----------\n"
4842
		);
4843
	}
4844
4845
	/**
4846
	 * @bug 163659: [javadoc] Compiler should warn when method parameters are not identical
4847
	 * @test Ensure that a warning is raised when method parameter types are not identical
4848
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=163659"
4849
	 */
4850
	public void testBug163659() {
4851
		runNegativeTest(
4852
			new String[] {
4853
				"Test.java",
4854
				"/**\n" + 
4855
				" * @see #foo(MyInterface)\n" + 
4856
				" * @see #foo(MySubInterface)\n" + 
4857
				" */\n" + 
4858
				"public class Test {\n" + 
4859
				"	public void foo(MyInterface mi) {\n" + 
4860
				"	}\n" + 
4861
				"}\n" + 
4862
				"interface MyInterface {}\n" + 
4863
				"interface MySubInterface extends MyInterface {} \n"
4864
			},
4865
			"----------\n" + 
4866
			"1. ERROR in Test.java (at line 3)\n" + 
4867
			"	* @see #foo(MySubInterface)\n" + 
4868
			"	        ^^^\n" + 
4869
			"Javadoc: The method foo(MyInterface) in the type Test is not applicable for the arguments (MySubInterface)\n" + 
4870
			"----------\n"
4871
		);
4872
	}
4873
4874
	/**
4875
	 * @bug 153399: [javadoc] JDT Core should warn if the @value tag is not used correctly
4815
	 * @bug 153399: [javadoc] JDT Core should warn if the @value tag is not used correctly
4876
	 * @test Ensure that 'value' tag is well warned when not used correctly
4816
	 * @test Ensure that 'value' tag is well warned when not used correctly
4877
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=153399"
4817
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=153399"
Lines 4981-4992 Link Here
4981
				"1. ERROR in X.java (at line 3)\n" + 
4921
				"1. ERROR in X.java (at line 3)\n" + 
4982
				"	* {@value #MY_VALUE}\n" + 
4922
				"	* {@value #MY_VALUE}\n" + 
4983
				"	    ^^^^^\n" + 
4923
				"	    ^^^^^\n" + 
4984
				"Javadoc: Unexpected duplicated tag @value\n" + 
4924
				"Javadoc: Unexpected tag\n" + 
4985
				"----------\n" + 
4925
				"----------\n" + 
4986
				"2. ERROR in X.java (at line 4)\n" + 
4926
				"2. ERROR in X.java (at line 4)\n" + 
4987
				"	* {@value}\n" + 
4927
				"	* {@value}\n" + 
4988
				"	    ^^^^^\n" + 
4928
				"	    ^^^^^\n" + 
4989
				"Javadoc: Unexpected duplicated tag @value\n" + 
4929
				"Javadoc: Unexpected tag\n" + 
4990
				"----------\n"
4930
				"----------\n"
4991
			);
4931
			);
4992
		} else {
4932
		} else {
Lines 5017-5023 Link Here
5017
				"1. ERROR in X.java (at line 3)\n" + 
4957
				"1. ERROR in X.java (at line 3)\n" + 
5018
				"	* {@value Invalid}\n" + 
4958
				"	* {@value Invalid}\n" + 
5019
				"	    ^^^^^\n" + 
4959
				"	    ^^^^^\n" + 
5020
				"Javadoc: Unexpected duplicated tag @value\n" + 
4960
				"Javadoc: Unexpected tag\n" + 
5021
				"----------\n"
4961
				"----------\n"
5022
			);
4962
			);
5023
		} else {
4963
		} else {
Lines 5033-5038 Link Here
5033
	}
4973
	}
5034
4974
5035
	/**
4975
	/**
4976
	 * @bug 160015: [1.5][javadoc] Missing warning on autoboxing compatible methods
4977
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=160015"
4978
	 */
4979
	public void testBug160015() {
4980
		runNegativeTest(new String[] {
4981
				"Test.java",
4982
				"/**\n" + 
4983
				" * @see #method(Long) Warning!\n" + 
4984
				" */\n" + 
4985
				"public class Test {\n" + 
4986
				"	public void method(long l) {}\n" + 
4987
				"	/**\n" + 
4988
				"	 * @see #method(Long) Warning!\n" + 
4989
				"	 */\n" + 
4990
				"	void bar() {}\n" + 
4991
				"}\n"
4992
			},
4993
			"----------\n" + 
4994
			"1. ERROR in Test.java (at line 2)\n" + 
4995
			"	* @see #method(Long) Warning!\n" + 
4996
			"	        ^^^^^^\n" + 
4997
			"Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + 
4998
			"----------\n" + 
4999
			"2. ERROR in Test.java (at line 7)\n" + 
5000
			"	* @see #method(Long) Warning!\n" + 
5001
			"	        ^^^^^^\n" + 
5002
			"Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + 
5003
			"----------\n"
5004
		);
5005
	}
5006
5007
	/**
5008
	 * @bug 163659: [javadoc] Compiler should warn when method parameters are not identical
5009
	 * @test Ensure that a warning is raised when method parameter types are not identical
5010
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=163659"
5011
	 */
5012
	public void testBug163659() {
5013
		runNegativeTest(
5014
			new String[] {
5015
				"Test.java",
5016
				"/**\n" + 
5017
				" * @see #foo(MyInterface)\n" + 
5018
				" * @see #foo(MySubInterface)\n" + 
5019
				" */\n" + 
5020
				"public class Test {\n" + 
5021
				"	public void foo(MyInterface mi) {\n" + 
5022
				"	}\n" + 
5023
				"}\n" + 
5024
				"interface MyInterface {}\n" + 
5025
				"interface MySubInterface extends MyInterface {} \n"
5026
			},
5027
			"----------\n" + 
5028
			"1. ERROR in Test.java (at line 3)\n" + 
5029
			"	* @see #foo(MySubInterface)\n" + 
5030
			"	        ^^^\n" + 
5031
			"Javadoc: The method foo(MyInterface) in the type Test is not applicable for the arguments (MySubInterface)\n" + 
5032
			"----------\n"
5033
		);
5034
	}
5035
5036
	/**
5036
	 * @bug 165794: [javadoc] Should not report ambiguous on method with parameterized types as parameters
5037
	 * @bug 165794: [javadoc] Should not report ambiguous on method with parameterized types as parameters
5037
	 * @test Ensure that no warning are raised when ambiguous parameterized methods are present in javadoc comments
5038
	 * @test Ensure that no warning are raised when ambiguous parameterized methods are present in javadoc comments
5038
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=165794"
5039
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=165794"
Lines 5071-5074 Link Here
5071
		}
5072
		}
5072
		runConformTest(testFiles);
5073
		runConformTest(testFiles);
5073
	}
5074
	}
5075
5076
	/**
5077
	 * @bug 166365: [javadoc] severity level of malformed javadoc comments did not work properly
5078
	 * @test Ensure that no warning is raised when visibility is lower than the javadoc option one
5079
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=166365"
5080
	 */
5081
	public void testBug166365() {
5082
		String[] testFiles = new String[] {
5083
			"X.java",
5084
			"public class X {\n" + 
5085
			"    /**\n" + 
5086
			"     * @return\n" + 
5087
			"     */\n" + 
5088
			"    private String getSomePrivate() {\n" + 
5089
			"        return \"SomePrivate\";\n" + 
5090
			"    }\n" + 
5091
			"    /**\n" + 
5092
			"     * @return\n" + 
5093
			"     */\n" + 
5094
			"    protected String getSomeProtected() {\n" + 
5095
			"        return \"SomeProtected\";\n" + 
5096
			"    }\n" + 
5097
			"    /**\n" + 
5098
			"     * @return\n" + 
5099
			"     */\n" + 
5100
			"    String getSomeDefault() {\n" + 
5101
			"        return \"SomeDefault\";\n" + 
5102
			"    }\n" + 
5103
			"    /**\n" + 
5104
			"     * @return\n" + 
5105
			"     */\n" + 
5106
			"    public String getSomePublic() {\n" + 
5107
			"        return \"SomePublic\";\n" + 
5108
			"    }\n" + 
5109
			"}\n"
5110
		};
5111
		this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC;
5112
		runNegativeTest(testFiles,
5113
			"----------\n" + 
5114
			"1. ERROR in X.java (at line 21)\n" + 
5115
			"	* @return\n" + 
5116
			"	   ^^^^^^\n" + 
5117
			"Javadoc: Missing return type description\n" + 
5118
			"----------\n"
5119
		);
5120
	}
5121
5122
	/**
5123
	 * @bug 166436: [javadoc] Potentially wrong javadoc warning for unexpected duplicate tag value
5124
	 * @test Ensure that no duplicate warning is raised for value tag
5125
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=166436"
5126
	 */
5127
	public void testBug166436() {
5128
		String[] testFiles = new String[] {
5129
			"X.java",
5130
			"public class X {\n" + 
5131
			"	public static final String PUBLIC_CONST = \"public\";\n" + 
5132
			"	protected static final String PROTECTED_CONST = \"protected\";\n" + 
5133
			"	static final String DEFAULT_CONST = \"default\"; \n" + 
5134
			"	private static final String PRIVATE_CONST = \"private\"; \n" + 
5135
			"	/**\n" + 
5136
			"	 * Values:\n" + 
5137
			"	 * <ul>\n" + 
5138
			"	 * 	<li>{@value #PUBLIC_CONST}</li>\n" + 
5139
			"	 * 	<li>{@value #PROTECTED_CONST}</li>\n" + 
5140
			"	 * 	<li>{@value #DEFAULT_CONST}</li>\n" + 
5141
			"	 * 	<li>{@value #PRIVATE_CONST}</li>\n" + 
5142
			"	 * </ul>\n" + 
5143
			"	 */\n" + 
5144
			"	public X() {\n" + 
5145
			"	}\n" + 
5146
			"}\n"
5147
		};
5148
		this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC;
5149
		if (complianceLevel.equals(COMPLIANCE_1_3) || complianceLevel.equals(COMPLIANCE_1_4)) {
5150
			runNegativeTest(testFiles,
5151
				"----------\n" + 
5152
				"1. ERROR in X.java (at line 9)\n" + 
5153
				"	* 	<li>{@value #PUBLIC_CONST}</li>\n" + 
5154
				"	  	      ^^^^^\n" + 
5155
				"Javadoc: Unexpected tag\n" + 
5156
				"----------\n" + 
5157
				"2. ERROR in X.java (at line 10)\n" + 
5158
				"	* 	<li>{@value #PROTECTED_CONST}</li>\n" + 
5159
				"	  	      ^^^^^\n" + 
5160
				"Javadoc: Unexpected tag\n" + 
5161
				"----------\n" + 
5162
				"3. ERROR in X.java (at line 11)\n" + 
5163
				"	* 	<li>{@value #DEFAULT_CONST}</li>\n" + 
5164
				"	  	      ^^^^^\n" + 
5165
				"Javadoc: Unexpected tag\n" + 
5166
				"----------\n" + 
5167
				"4. ERROR in X.java (at line 12)\n" + 
5168
				"	* 	<li>{@value #PRIVATE_CONST}</li>\n" + 
5169
				"	  	      ^^^^^\n" + 
5170
				"Javadoc: Unexpected tag\n" + 
5171
				"----------\n"
5172
			);
5173
		} else {
5174
			runNegativeTest(testFiles,
5175
				"----------\n" + 
5176
				"1. ERROR in X.java (at line 10)\n" + 
5177
				"	* 	<li>{@value #PROTECTED_CONST}</li>\n" + 
5178
				"	  	            ^^^^^^^^^^^^^^^^\n" + 
5179
				"Javadoc: \'public\' visibility for malformed doc comments hides this \'protected\' reference\n" + 
5180
				"----------\n" + 
5181
				"2. ERROR in X.java (at line 11)\n" + 
5182
				"	* 	<li>{@value #DEFAULT_CONST}</li>\n" + 
5183
				"	  	            ^^^^^^^^^^^^^^\n" + 
5184
				"Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + 
5185
				"----------\n" + 
5186
				"3. ERROR in X.java (at line 12)\n" + 
5187
				"	* 	<li>{@value #PRIVATE_CONST}</li>\n" + 
5188
				"	  	            ^^^^^^^^^^^^^^\n" + 
5189
				"Javadoc: \'public\' visibility for malformed doc comments hides this \'private\' reference\n" + 
5190
				"----------\n"
5191
			);
5192
		}
5193
	}
5074
}
5194
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java (-1 / +1 lines)
Lines 37-43 Link Here
37
		if (methodType == null || methodType == TypeBinding.VOID) {
37
		if (methodType == null || methodType == TypeBinding.VOID) {
38
			scope.problemReporter().javadocUnexpectedTag(this.sourceStart, this.sourceEnd);
38
			scope.problemReporter().javadocUnexpectedTag(this.sourceStart, this.sourceEnd);
39
		} else if (this.empty) {
39
		} else if (this.empty) {
40
			scope.problemReporter().javadocEmptyReturnTag(this.sourceStart, this.sourceEnd);
40
			scope.problemReporter().javadocEmptyReturnTag(this.sourceStart, this.sourceEnd, scope.getDeclarationModifiers());
41
		}
41
		}
42
	}
42
	}
43
43
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-2 / +7 lines)
Lines 1044-1049 Link Here
1044
		case IProblem.JavadocIncorrectArityForParameterizedConstructor:
1044
		case IProblem.JavadocIncorrectArityForParameterizedConstructor:
1045
		case IProblem.JavadocParameterizedConstructorArgumentTypeMismatch:
1045
		case IProblem.JavadocParameterizedConstructorArgumentTypeMismatch:
1046
		case IProblem.JavadocTypeArgumentsForRawGenericConstructor:
1046
		case IProblem.JavadocTypeArgumentsForRawGenericConstructor:
1047
		case IProblem.JavadocEmptyReturnTag:
1047
			if (!this.options.reportInvalidJavadocTags) {
1048
			if (!this.options.reportInvalidJavadocTags) {
1048
				return ProblemSeverities.Ignore;		
1049
				return ProblemSeverities.Ignore;		
1049
			}
1050
			}
Lines 3649-3656 Link Here
3649
			typeReference.sourceEnd);
3650
			typeReference.sourceEnd);
3650
	}
3651
	}
3651
}
3652
}
3652
public void javadocEmptyReturnTag(int sourceStart, int sourceEnd) {
3653
public void javadocEmptyReturnTag(int sourceStart, int sourceEnd, int modifiers) {
3653
	this.handle(IProblem.JavadocEmptyReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
3654
	int severity = computeSeverity(IProblem.JavadocEmptyReturnTag);
3655
	if (severity == ProblemSeverities.Ignore) return;
3656
	if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
3657
		this.handle(IProblem.JavadocEmptyReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
3658
	}
3654
}
3659
}
3655
public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
3660
public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
3656
	int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
3661
	int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +2 lines)
Lines 20-25 Link Here
20
import org.eclipse.jdt.internal.compiler.Compiler;
20
import org.eclipse.jdt.internal.compiler.Compiler;
21
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
21
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
23
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
23
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
24
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
24
import org.eclipse.jdt.internal.compiler.util.Util;
25
import org.eclipse.jdt.internal.compiler.util.Util;
25
26
Lines 434-440 Link Here
434
	}
435
	}
435
	
436
	
436
	public String getVisibilityString(int level) {
437
	public String getVisibilityString(int level) {
437
		switch (level) {
438
		switch (level & ExtraCompilerModifiers.AccVisibilityMASK) {
438
			case ClassFileConstants.AccPublic:
439
			case ClassFileConstants.AccPublic:
439
				return PUBLIC;
440
				return PUBLIC;
440
			case ClassFileConstants.AccProtected:
441
			case ClassFileConstants.AccProtected:

Return to bug 166365