test/tools/javac/doctree/ReferenceTest.java

Thu, 21 Feb 2013 15:26:46 +0000

author
mcimadamore
date
Thu, 21 Feb 2013 15:26:46 +0000
changeset 1599
9f0ec00514b6
parent 1409
33abf479f202
child 1726
a7ff36d06fa2
permissions
-rw-r--r--

8007461: Regression: bad overload resolution when inner class and outer class have method with same name
Summary: Fix regression in varargs method resolution introduced by bad refactoring
Reviewed-by: jjg

jjg@1409 1 /*
jjg@1409 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
jjg@1409 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1409 4 *
jjg@1409 5 * This code is free software; you can redistribute it and/or modify it
jjg@1409 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1409 7 * published by the Free Software Foundation.
jjg@1409 8 *
jjg@1409 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1409 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1409 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1409 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1409 13 * accompanied this code).
jjg@1409 14 *
jjg@1409 15 * You should have received a copy of the GNU General Public License version
jjg@1409 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1409 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1409 18 *
jjg@1409 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1409 20 * or visit www.oracle.com if you need additional information or have any
jjg@1409 21 * questions.
jjg@1409 22 */
jjg@1409 23
jjg@1409 24 /*
jjg@1409 25 * @test
jjg@1409 26 * @bug 7021614
jjg@1409 27 * @summary extend com.sun.source API to support parsing javadoc comments
jjg@1409 28 * @summary check references in at-see and {at-link} tags
jjg@1409 29 * @build ReferenceTest
jjg@1409 30 * @compile -processor ReferenceTest -proc:only ReferenceTest.java
jjg@1409 31 */
jjg@1409 32
jjg@1409 33 import com.sun.source.doctree.DocCommentTree;
jjg@1409 34 import com.sun.source.doctree.DocTree;
jjg@1409 35 import com.sun.source.doctree.LinkTree;
jjg@1409 36 import com.sun.source.doctree.ReferenceTree;
jjg@1409 37 import com.sun.source.doctree.SeeTree;
jjg@1409 38 import com.sun.source.doctree.TextTree;
jjg@1409 39 import com.sun.source.util.DocTreeScanner;
jjg@1409 40 import com.sun.source.util.DocTrees;
jjg@1409 41 import com.sun.source.util.TreePath;
jjg@1409 42
jjg@1409 43 import java.util.List;
jjg@1409 44 import java.util.Set;
jjg@1409 45 import javax.annotation.processing.AbstractProcessor;
jjg@1409 46 import javax.annotation.processing.ProcessingEnvironment;
jjg@1409 47 import javax.annotation.processing.RoundEnvironment;
jjg@1409 48 import javax.annotation.processing.SupportedAnnotationTypes;
jjg@1409 49 import javax.lang.model.SourceVersion;
jjg@1409 50 import javax.lang.model.element.Element;
jjg@1409 51 import javax.lang.model.element.TypeElement;
jjg@1409 52 import javax.tools.Diagnostic.Kind;
jjg@1409 53
jjg@1409 54 /**
jjg@1409 55 * {@link java.lang Package}
jjg@1409 56 * {@link java.lang.ERROR Bad}
jjg@1409 57 *
jjg@1409 58 * {@link java.lang.String Class}
jjg@1409 59 * {@link String Class}
jjg@1409 60 * {@link java.lang.String#CASE_INSENSITIVE_ORDER Field}
jjg@1409 61 * {@link java.lang.String#String Constructor}
jjg@1409 62 * {@link java.lang.String#String(byte[]) Constructor}
jjg@1409 63 * {@link java.lang.String#String(byte[] bytes) Constructor}
jjg@1409 64 * {@link java.lang.String#String(byte[], String) Constructor}
jjg@1409 65 * {@link java.lang.String#String(byte[] bytes, String charSetName) Constructor}
jjg@1409 66 * {@link java.lang.String#isEmpty Method}
jjg@1409 67 * {@link java.lang.String#isEmpty() Method}
jjg@1409 68 * {@link java.lang.String#ERROR Bad}
jjg@1409 69 * {@link java.lang.String#equals(Object) Method}
jjg@1409 70 *
jjg@1409 71 * {@link AbstractProcessor Class}
jjg@1409 72 *
jjg@1409 73 * {@link List#add(Object) Method}
jjg@1409 74 *
jjg@1409 75 * {@link #trees Field}
jjg@1409 76 * {@link #getSupportedSourceVersion Method}
jjg@1409 77 * {@link #init(ProcessingEnvironment Method}
jjg@1409 78 *
jjg@1409 79 * @see java.lang Package
jjg@1409 80 * @see java.lang.ERROR Bad
jjg@1409 81 *
jjg@1409 82 * @see java.lang.String Class
jjg@1409 83 * @see String Class
jjg@1409 84 * @see java.lang.String#CASE_INSENSITIVE_ORDER Field
jjg@1409 85 * @see java.lang.String#String Constructor
jjg@1409 86 * @see java.lang.String#String(byte[]) Constructor
jjg@1409 87 * @see java.lang.String#String(byte[] bytes) Constructor
jjg@1409 88 * @see java.lang.String#String(byte[],String) Constructor
jjg@1409 89 * @see java.lang.String#String(byte[] bytes, String charsetName) Constructor
jjg@1409 90 * @see java.lang.String#isEmpty Method
jjg@1409 91 * @see java.lang.String#isEmpty() Method
jjg@1409 92 * @see java.lang.String#ERROR Bad
jjg@1409 93 * @see java.lang.String#equals(Object) Method
jjg@1409 94 *
jjg@1409 95 * @see AbstractProcessor Class
jjg@1409 96 *
jjg@1409 97 * @see List#add(Object) Method
jjg@1409 98 *
jjg@1409 99 * @see #trees Field
jjg@1409 100 * @see #getSupportedSourceVersion Method
jjg@1409 101 * @see #init(ProcessingEnvironment) Method
jjg@1409 102 *
jjg@1409 103 * @see java.io.BufferedInputStream#BufferedInputStream(InputStream) Constructor
jjg@1409 104 */
jjg@1409 105 @SupportedAnnotationTypes("*")
jjg@1409 106 public class ReferenceTest extends AbstractProcessor {
jjg@1409 107 DocTrees trees;
jjg@1409 108
jjg@1409 109 @Override
jjg@1409 110 public SourceVersion getSupportedSourceVersion() {
jjg@1409 111 return SourceVersion.latest();
jjg@1409 112 }
jjg@1409 113
jjg@1409 114 @Override
jjg@1409 115 public void init(ProcessingEnvironment pEnv) {
jjg@1409 116 super.init(pEnv);
jjg@1409 117 trees = DocTrees.instance(pEnv);
jjg@1409 118 }
jjg@1409 119
jjg@1409 120 @Override
jjg@1409 121 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
jjg@1409 122 for (Element e: roundEnv.getRootElements()) {
jjg@1409 123 new DocCommentScanner(trees.getPath(e)).scan();
jjg@1409 124 }
jjg@1409 125 return true;
jjg@1409 126 }
jjg@1409 127
jjg@1409 128 class DocCommentScanner extends DocTreeScanner<Void, Void> {
jjg@1409 129 TreePath path;
jjg@1409 130 DocCommentTree dc;
jjg@1409 131
jjg@1409 132 DocCommentScanner(TreePath path) {
jjg@1409 133 this.path = path;
jjg@1409 134 }
jjg@1409 135
jjg@1409 136 void scan() {
jjg@1409 137 dc = trees.getDocCommentTree(path);
jjg@1409 138 scan(dc, null);
jjg@1409 139 }
jjg@1409 140
jjg@1409 141 @Override
jjg@1409 142 public Void visitLink(LinkTree tree, Void ignore) {
jjg@1409 143 checkReference(tree.getReference(), tree.getLabel());
jjg@1409 144 return null;
jjg@1409 145 }
jjg@1409 146
jjg@1409 147 @Override
jjg@1409 148 public Void visitSee(SeeTree tree, Void ignore) {
jjg@1409 149 List<? extends DocTree> refLabel = tree.getReference();
jjg@1409 150 if (refLabel.size() > 1 && (refLabel.get(0) instanceof ReferenceTree)) {
jjg@1409 151 ReferenceTree ref = (ReferenceTree) refLabel.get(0);
jjg@1409 152 List<? extends DocTree> label = refLabel.subList(1, refLabel.size());
jjg@1409 153 checkReference(ref, label);
jjg@1409 154 }
jjg@1409 155 return null;
jjg@1409 156 }
jjg@1409 157
jjg@1409 158 void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
jjg@1409 159 String sig = tree.getSignature();
jjg@1409 160
jjg@1409 161 Element found = trees.getElement(path, tree);
jjg@1409 162 if (found == null) {
jjg@1409 163 System.err.println(sig + " NOT FOUND");
jjg@1409 164 } else {
jjg@1409 165 System.err.println(sig + " found " + found.getKind() + " " + found);
jjg@1409 166 }
jjg@1409 167
jjg@1409 168 String expect = "UNKNOWN";
jjg@1409 169 if (label.size() > 0 && label.get(0) instanceof TextTree)
jjg@1409 170 expect = ((TextTree) label.get(0)).getBody();
jjg@1409 171
jjg@1409 172 if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
jjg@1409 173 error(tree, "Unexpected value found: " + found +", expected: " + expect);
jjg@1409 174 }
jjg@1409 175 }
jjg@1409 176
jjg@1409 177 void error(DocTree tree, String msg) {
jjg@1409 178 trees.printMessage(Kind.ERROR, msg, tree, dc, path.getCompilationUnit());
jjg@1409 179 }
jjg@1409 180 }
jjg@1409 181 }
jjg@1409 182
jjg@1409 183 /**
jjg@1409 184 * @see ReferenceTestExtras Class
jjg@1409 185 * @see #ReferenceTestExtras Field
jjg@1409 186 * @see #ReferenceTestExtras() Constructor
jjg@1409 187 *
jjg@1409 188 * @see #X Field
jjg@1409 189 * @see #X() Method
jjg@1409 190 *
jjg@1409 191 * @see #m Method
jjg@1409 192 *
jjg@1409 193 * @see #varargs(int...) Method
jjg@1409 194 * @see #varargs(int... args) Method
jjg@1409 195 * @see #varargs(int[]) Method
jjg@1409 196 * @see #varargs(int[] args) Method
jjg@1409 197 */
jjg@1409 198 class ReferenceTestExtras {
jjg@1409 199 int ReferenceTestExtras; // field
jjg@1409 200 ReferenceTestExtras() { } // constructor
jjg@1409 201 void ReferenceTestExtras() { } // method
jjg@1409 202
jjg@1409 203 int X;
jjg@1409 204 void X() { }
jjg@1409 205 static class X { }
jjg@1409 206
jjg@1409 207 void m() { }
jjg@1409 208 void m(int i) { }
jjg@1409 209 void m(int i, int j) { }
jjg@1409 210
jjg@1409 211 void varargs(int... args) { }
jjg@1409 212 }
jjg@1409 213
jjg@1409 214

mercurial