View | Details | Raw Unified | Return to bug 211054 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java (-9 / +89 lines)
Lines 1247-1265 Link Here
1247
	/**
1247
	/**
1248
	 * Bug 50695.
1248
	 * Bug 50695.
1249
	 * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=50695">50695</a>
1249
	 * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=50695">50695</a>
1250
	 * Since bug 211054 was fixed, expect warning to be raised when referencing packages others
1251
	 * than the current one.
1252
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=211054"
1250
	 */
1253
	 */
1251
	public void testBug50695() {
1254
	public void testBug50695() {
1252
		runConformTest(
1255
		runNegativeTest(
1253
			new String[] {
1256
			new String[] {
1254
				"X.java",
1257
				"X.java",
1255
				"public class X {\n" + 
1258
				"public class X {\n" + 
1256
					"	/**\n" + 
1259
				"	/**\n" + 
1257
					"	 * @see java\n" + 
1260
				"	 * @see java\n" + 
1258
					"	 * @see java.util\n" + 
1261
				"	 * @see java.util\n" + 
1259
					"	 */\n" + 
1262
				"	 */\n" + 
1260
					"	void foo() {}\n" + 
1263
				"	void foo() {}\n" + 
1261
					"}\n"
1264
				"}\n"
1262
		 });
1265
			},
1266
			"----------\n" + 
1267
			"1. ERROR in X.java (at line 3)\n" + 
1268
			"	* @see java\n" + 
1269
			"	       ^^^^\n" + 
1270
			"Javadoc: Invalid reference\n" + 
1271
			"----------\n" + 
1272
			"2. ERROR in X.java (at line 4)\n" + 
1273
			"	* @see java.util\n" + 
1274
			"	       ^^^^^^^^^\n" + 
1275
			"Javadoc: Invalid reference\n" + 
1276
			"----------\n"
1277
		);
1263
	}
1278
	}
1264
	public void testBug50695b() {
1279
	public void testBug50695b() {
1265
		runNegativeTest(
1280
		runNegativeTest(
Lines 1272-1278 Link Here
1272
					"	void foo() {}\n" + 
1287
					"	void foo() {}\n" + 
1273
					"}\n"
1288
					"}\n"
1274
			 },
1289
			 },
1275
			"----------\n" + 
1290
			 	"----------\n" + 
1276
				"1. ERROR in X.java (at line 3)\n" + 
1291
				"1. ERROR in X.java (at line 3)\n" + 
1277
				"	* @see java.unknown\n" + 
1292
				"	* @see java.unknown\n" + 
1278
				"	       ^^^^^^^^^^^^\n" + 
1293
				"	       ^^^^^^^^^^^^\n" + 
Lines 7284-7287 Link Here
7284
			expectedError
7299
			expectedError
7285
		);
7300
		);
7286
	}
7301
	}
7302
	
7303
	/**
7304
	 * @bug 211054: [javadoc] @see package reference should raise a warning except for the package declaration
7305
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=211054"
7306
	 */
7307
	public void testBug211054a() {
7308
		String[] units = new String[] {
7309
			"pkg/X.java",
7310
			"package pkg;\n" +
7311
			"\n" +
7312
			"public class X {\n" +
7313
			"	/**\n" +
7314
			"	 * @see java\n" +
7315
			"	 * @see java.lang\n" +
7316
			"	 * @see PKG\n" +
7317
			"	 * @see pkg\n" +
7318
			"	 */\n" +
7319
			"	public void foo() { \n" +
7320
			"	 \n" +
7321
			"	}\n" +
7322
			"}\n"
7323
		};
7324
		reportInvalidJavadoc = CompilerOptions.WARNING;
7325
		runNegativeTest(units,
7326
			// warning - Tag @see: reference not found: java
7327
			// warning - Tag @see: reference not found: java.lang
7328
			// warning - Tag @see: reference not found: PKG
7329
			"----------\n" + 
7330
			"1. WARNING in pkg\\X.java (at line 5)\n" + 
7331
			"	* @see java\n" + 
7332
			"	       ^^^^\n" + 
7333
			"Javadoc: Invalid reference\n" + 
7334
			"----------\n" + 
7335
			"2. WARNING in pkg\\X.java (at line 6)\n" + 
7336
			"	* @see java.lang\n" + 
7337
			"	       ^^^^^^^^^\n" + 
7338
			"Javadoc: Invalid reference\n" + 
7339
			"----------\n" + 
7340
			"3. WARNING in pkg\\X.java (at line 7)\n" + 
7341
			"	* @see PKG\n" + 
7342
			"	       ^^^\n" + 
7343
			"Javadoc: PKG cannot be resolved to a type\n" + 
7344
			"----------\n");
7345
	}
7346
	public void testBug211054b() {
7347
		String[] units = new String[] {
7348
			"pkg/X.java",
7349
			"package pkg;\n" +
7350
			"\n" +
7351
			"public class X {\n" +
7352
			"	/**\n" +
7353
			"	 * @see java\n" +
7354
			"	 * @see java.lang\n" +
7355
			"	 * @see PKG\n" +
7356
			"	 * @see pkg\n" +
7357
			"	 */\n" +
7358
			"	protected void foo() { \n" +
7359
			"	 \n" +
7360
			"	}\n" +
7361
			"}\n"
7362
		};
7363
		reportInvalidJavadoc = CompilerOptions.WARNING;
7364
		this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC;
7365
		runConformTest(units);
7366
	}
7287
}
7367
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/JavadocQualifiedTypeReference.java (+7 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
Lines 50-55 Link Here
50
			Binding binding = scope.getTypeOrPackage(this.tokens);
51
			Binding binding = scope.getTypeOrPackage(this.tokens);
51
			if (binding instanceof PackageBinding) {
52
			if (binding instanceof PackageBinding) {
52
				this.packageBinding = (PackageBinding) binding;
53
				this.packageBinding = (PackageBinding) binding;
54
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=211054
55
				// allow references to current package only. All other package references should be reported as invalid
56
				// @see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=50695
57
				if (! CharOperation.equals(scope.compilationUnitScope().currentPackageName, this.packageBinding.compoundName, true)) {
58
					scope.problemReporter().javadocInvalidReference(this.sourceStart, this.sourceEnd);
59
				}
53
			} else {
60
			} else {
54
				reportInvalidType(scope);
61
				reportInvalidType(scope);
55
			}
62
			}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/JavadocSingleTypeReference.java (+7 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
Lines 65-70 Link Here
65
			Binding binding = scope.getTypeOrPackage(tokens);
66
			Binding binding = scope.getTypeOrPackage(tokens);
66
			if (binding instanceof PackageBinding) {
67
			if (binding instanceof PackageBinding) {
67
				this.packageBinding = (PackageBinding) binding;
68
				this.packageBinding = (PackageBinding) binding;
69
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=211054
70
				// allow references to current package only. All other package references should be reported as invalid
71
				// @see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=50695
72
				if (! CharOperation.equals(scope.compilationUnitScope().currentPackageName, this.packageBinding.compoundName, true)) {
73
					scope.problemReporter().javadocInvalidReference(this.sourceStart, this.sourceEnd);
74
				}
68
			} else {
75
			} else {
69
				if (this.resolvedType.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
76
				if (this.resolvedType.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
70
					TypeBinding closestMatch = this.resolvedType.closestMatch();
77
					TypeBinding closestMatch = this.resolvedType.closestMatch();

Return to bug 211054