langtools/test/tools/javac/api/TestTrees.java
author jlahoda
Fri, 21 Feb 2014 10:35:19 +0100
changeset 23122 02c931d49ad2
parent 5520 86e4b9a9da40
child 27319 030080f03e4f
permissions -rw-r--r--
6411385: Trees.getPath does not work for constructors Summary: Enhancing TestTrees test to ensure proper function of Trees.getPath/getTree, fixing cases where getTree did not work properly. Reviewed-by: jjg Contributed-by: jan.lahoda@oracle.com, dusan.balek@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    26
 * @bug 6346249 6392177 6411385
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary new Trees API
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.source.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.source.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.lang.annotation.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.annotation.processing.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import javax.lang.model.SourceVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import javax.lang.model.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import javax.tools.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.api.JavacTool;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.tree.TreeInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
@Anno
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
@SupportedAnnotationTypes("*")
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class TestTrees extends AbstractProcessor {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    @Anno
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    void annoMethod() { }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    @Anno
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    int annoField;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    54
    @Anno
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    55
    public TestTrees() {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    56
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    static final String testSrcDir = System.getProperty("test.src");
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    static final String testClassDir = System.getProperty("test.classes");
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    static final String self = TestTrees.class.getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    static PrintWriter out = new PrintWriter(System.err, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public static void main(String[] args) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        new TestTrees().run();
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    void run() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        JavacTool tool = JavacTool.create();
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                public void report(Diagnostic d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
                    error(d.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        Iterable<? extends JavaFileObject> files =
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    81
        Iterable<String> opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        System.err.println("simple compilation, no processing");
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        task.setTaskListener(new MyTaskListener(task));
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        if (!task.call())
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            throw new AssertionError("compilation failed");
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    89
        opts =  Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self,
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
    90
            "-XDcompilePolicy=simple");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        System.err.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        System.err.println("compilation with processing");
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        task = tool.getTask(out, fm, dl,opts, null, files);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        if (!task.call())
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            throw new AssertionError("compilation failed");
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        if (errors > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            throw new AssertionError(errors + " errors occurred");
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    void testElement(Trees trees, Element e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        trees.getClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        e.getClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        System.err.println("testElement: " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        Tree tree = trees.getTree(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        //System.err.println(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        if (TreeInfo.symbolFor((JCTree)tree) != e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            error("bad result from getTree");
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        TreePath path = trees.getPath(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        if (path == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            error("getPath returned null");
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        if (path.getLeaf() != tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            error("bad result from getPath");
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        Element e2 = trees.getElement(path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        if (e2 == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            error("getElement returned null");
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        if (e2 != e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            error("bad result from getElement");
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        // The TypeMirror is not available yet when annotation processing;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        // it is set up later during ANALYSE.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        TypeMirror t = trees.getTypeMirror(path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        if (t != null && t.getKind() == TypeKind.DECLARED &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                ((DeclaredType)t).asElement() != e2)
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            error("bad result from getTypeMirror");
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        for (AnnotationMirror m: e.getAnnotationMirrors()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            testAnnotation(trees, e, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    void testAnnotation(Trees trees, Element e, AnnotationMirror a) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        System.err.println("testAnnotation: " + e + " " + a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        Tree tree = trees.getTree(e, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   145
        if (tree.getKind() != Tree.Kind.ANNOTATION && tree.getKind() != Tree.Kind.TYPE_ANNOTATION)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            error("bad result from getTree");
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        TreePath path = trees.getPath(e, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        if (path.getLeaf() != tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
            error("bad result from getPath");
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   153
    void testAllDeclarations(Trees trees, CompilationUnitTree cut) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   154
        new TreePathScanner<Void, Void>() {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   155
            @Override public Void scan(Tree tree, Void p) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   156
                if (tree == null) return null;
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   157
                switch (tree.getKind()) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   158
                    case METHOD: case CLASS: case VARIABLE: case TYPE_PARAMETER:
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   159
                        TreePath path = new TreePath(getCurrentPath(), tree);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   160
                        Element el = trees.getElement(path);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   161
                        if (el == null) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   162
                            error("null element");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   163
                        } else {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   164
                            TreePath inferred = trees.getPath(el);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   165
                            if (inferred == null) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   166
                                error("null path");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   167
                            } else {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   168
                                if (inferred.getLeaf() != path.getLeaf())
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   169
                                    error("bad result from getPath");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   170
                            }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   171
                            if (trees.getTree(el) != path.getLeaf())
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   172
                                error("bad result from getTree");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   173
                            for (AnnotationMirror m: el.getAnnotationMirrors()) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   174
                                testAnnotation(trees, el, m);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   175
                            }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   176
                        }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   177
                }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   178
                return super.scan(tree, p);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   179
            }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   180
        }.scan(cut, null);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   181
    }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   182
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    void error(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        if (messager != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            // annotation processing will happen in a separate instance/classloader
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            // so pass the message back to the calling instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            messager.printMessage(Diagnostic.Kind.ERROR, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            System.err.println(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            errors++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    Messager messager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    int errors;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        Trees trees = Trees.instance(processingEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        messager = processingEnv.getMessager();
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        for (Element e: rEnv.getRootElements()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            testElement(trees, e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        for (TypeElement anno: annos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            System.err.println("anno: " + anno);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            System.err.println("elts: " + elts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            if (elts != null) { // 6397298, should return empty set
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                for (Element e: rEnv.getElementsAnnotatedWith(anno))
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                    testElement(trees, e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    public SourceVersion getSupportedSourceVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        return SourceVersion.latest();
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    class MyTaskListener implements TaskListener {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        MyTaskListener(JavacTask task) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            this.task = task;
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        public void started(TaskEvent e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            System.err.println("started " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        public void finished(TaskEvent e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            //System.err.println("finished " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            switch (e.getKind()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            case ANALYZE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                testElement(Trees.instance(task), e.getTypeElement());
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   239
                testAllDeclarations(Trees.instance(task), e.getCompilationUnit());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        private final JavacTask task;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   247
    public static class TestTypeParams<@Anno T extends CharSequence> {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   248
        public <@Anno T extends Object> TestTypeParams(T param) { }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   249
        public <@Anno T extends Number> void m(T param) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   250
            int local;
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   251
            try {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   252
                new String();
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   253
            } catch (Exception exc) { }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   254
        }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   255
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
@Retention(RetentionPolicy.SOURCE)
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   259
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE_PARAMETER,
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   260
         ElementType.FIELD, ElementType.LOCAL_VARIABLE})
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
@interface Anno {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
}