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

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

mercurial