# HG changeset patch # User jjg # Date 1380045088 25200 # Node ID 8246fe4d663890c7034a8688daa12d8f33f89fd9 # Parent 8e84701d7da0193dba170bfacefe6d56f48fc4bb 8025246: [doclint] doclint is showing error on anchor already defined when it's not Reviewed-by: bpatel diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/src/share/classes/com/sun/tools/doclint/Checker.java --- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Tue Sep 24 10:48:11 2013 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Tue Sep 24 10:51:28 2013 -0700 @@ -93,7 +93,7 @@ Set foundParams = new HashSet<>(); Set foundThrows = new HashSet<>(); - Map> foundAnchors = new HashMap<>(); + Map> foundAnchors = new HashMap<>(); boolean foundInheritDoc = false; boolean foundReturn = false; @@ -576,13 +576,30 @@ } private boolean checkAnchor(String name) { - JavaFileObject fo = env.currPath.getCompilationUnit().getSourceFile(); - Set set = foundAnchors.get(fo); + Element e = getEnclosingPackageOrClass(env.currElement); + if (e == null) + return true; + Set set = foundAnchors.get(e); if (set == null) - foundAnchors.put(fo, set = new HashSet<>()); + foundAnchors.put(e, set = new HashSet<>()); return set.add(name); } + private Element getEnclosingPackageOrClass(Element e) { + while (e != null) { + switch (e.getKind()) { + case CLASS: + case ENUM: + case INTERFACE: + case PACKAGE: + return e; + default: + e = e.getEnclosingElement(); + } + } + return e; + } + // http://www.w3.org/TR/html401/types.html#type-name private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*"); diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/Test.java Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,53 @@ +/* @test /nodynamiccopyright/ + * @bug 8025246 + * @summary doclint is showing error on anchor already defined when it's not + * @library ../.. + * @build DocLintTester + * @run main DocLintTester -ref Test.out Test.java + * @compile/fail/ref=Test.javac.out -XDrawDiagnostics -Werror -Xdoclint:all Test.java + */ + +package p; + +/** + * dupTest + * dupTest again + * + * dupTestField + * dupTestMethod + + * okClass + * okField + * okMethod + */ +public class Test { + /** dupTestField again */ + public int f; + + /** dupTestMethod again */ + public void m() { } + + /** + * dupNested + * dupNested again + * dupNestedField + * dupNestedMethod + * + * okClass again + */ + public class Nested { + /** + * dupNestedField + * + * okField again + */ + public int f; + + /** + * dupNestedMethod + * + * okMethod again + */ + public void m() { } + } +} diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/Test.javac.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/Test.javac.out Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,7 @@ +Test.java:14:7: compiler.err.proc.messager: anchor already defined: dupTest +Test.java:24:12: compiler.err.proc.messager: anchor already defined: dupTestField +Test.java:27:12: compiler.err.proc.messager: anchor already defined: dupTestMethod +Test.java:32:11: compiler.err.proc.messager: anchor already defined: dupNested +Test.java:40:15: compiler.err.proc.messager: anchor already defined: dupNestedField +Test.java:47:15: compiler.err.proc.messager: anchor already defined: dupNestedMethod +6 errors diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/Test.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/Test.out Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,19 @@ +Test.java:14: error: anchor already defined: dupTest + * dupTest again + ^ +Test.java:24: error: anchor already defined: dupTestField + /** dupTestField again */ + ^ +Test.java:27: error: anchor already defined: dupTestMethod + /** dupTestMethod again */ + ^ +Test.java:32: error: anchor already defined: dupNested + * dupNested again + ^ +Test.java:40: error: anchor already defined: dupNestedField + * dupNestedField + ^ +Test.java:47: error: anchor already defined: dupNestedMethod + * dupNestedMethod + ^ +6 errors diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/package-info.java Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,15 @@ +/* @test /nodynamiccopyright/ + * @bug 8025246 + * @summary doclint is showing error on anchor already defined when it's not + * @library ../.. + * @build DocLintTester + * @run main DocLintTester -ref package-info.out package-info.java + * @compile/fail/ref=package-info.javac.out -XDrawDiagnostics -Werror -Xdoclint:all package-info.java + */ + +/** + * here + * here again + */ +package p; + diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/package-info.javac.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/package-info.javac.out Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,2 @@ +package-info.java:12:7: compiler.err.proc.messager: anchor already defined: here +1 error diff -r 8e84701d7da0 -r 8246fe4d6638 langtools/test/tools/doclint/anchorTests/p/package-info.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/doclint/anchorTests/p/package-info.out Tue Sep 24 10:51:28 2013 -0700 @@ -0,0 +1,4 @@ +package-info.java:12: error: anchor already defined: here + * here again + ^ +1 error