langtools/test/tools/javac/api/TestTrees.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 36526 3b41f1c69604
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
     2
 * Copyright (c) 2006, 2016, 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
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.tree
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.lang.annotation.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.annotation.processing.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.lang.model.SourceVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import javax.lang.model.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import javax.tools.*;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    39
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    40
import com.sun.source.tree.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    41
import com.sun.source.util.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.tree.TreeInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
@Anno
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
@SupportedAnnotationTypes("*")
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public class TestTrees extends AbstractProcessor {
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
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    69
        JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
10
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
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    77
        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    78
            Iterable<? extends JavaFileObject> files =
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    79
                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    81
            Iterable<String> opts = Arrays.asList(
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    82
                "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    83
                "-d", ".",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    84
                "-XDcompilePolicy=simple");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    86
            System.err.println("simple compilation, no processing");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    87
            JavacTask task = (JavacTask) tool.getTask(out, fm, dl, opts, null, files);
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    88
            task.setTaskListener(new MyTaskListener(task));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    89
            if (!task.call())
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    90
                throw new AssertionError("compilation failed");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    92
            opts =  Arrays.asList(
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    93
                "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    94
                "-XDaccessInternalAPI",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    95
                "-d", ".",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    96
                "-processorpath", testClassDir,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    97
                "-processor", self,
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
    98
                "-XDcompilePolicy=simple");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   100
            System.err.println();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   101
            System.err.println("compilation with processing");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
   102
            task = (JavacTask) tool.getTask(out, fm, dl,opts, null, files);
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   103
            if (!task.call())
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   104
                throw new AssertionError("compilation failed");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   106
            if (errors > 0)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   107
                throw new AssertionError(errors + " errors occurred");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 23122
diff changeset
   108
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    void testElement(Trees trees, Element e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        trees.getClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        e.getClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        System.err.println("testElement: " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        Tree tree = trees.getTree(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        //System.err.println(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        if (TreeInfo.symbolFor((JCTree)tree) != e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            error("bad result from getTree");
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        TreePath path = trees.getPath(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        if (path == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            error("getPath returned null");
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        if (path.getLeaf() != tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            error("bad result from getPath");
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        Element e2 = trees.getElement(path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        if (e2 == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            error("getElement returned null");
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        if (e2 != e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            error("bad result from getElement");
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        // The TypeMirror is not available yet when annotation processing;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        // it is set up later during ANALYSE.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        TypeMirror t = trees.getTypeMirror(path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        if (t != null && t.getKind() == TypeKind.DECLARED &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                ((DeclaredType)t).asElement() != e2)
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            error("bad result from getTypeMirror");
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        for (AnnotationMirror m: e.getAnnotationMirrors()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            testAnnotation(trees, e, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    void testAnnotation(Trees trees, Element e, AnnotationMirror a) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        System.err.println("testAnnotation: " + e + " " + a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        Tree tree = trees.getTree(e, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   154
        if (tree.getKind() != Tree.Kind.ANNOTATION && tree.getKind() != Tree.Kind.TYPE_ANNOTATION)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            error("bad result from getTree");
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        TreePath path = trees.getPath(e, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        if (path.getLeaf() != tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            error("bad result from getPath");
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   162
    void testAllDeclarations(Trees trees, CompilationUnitTree cut) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   163
        new TreePathScanner<Void, Void>() {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   164
            @Override public Void scan(Tree tree, Void p) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   165
                if (tree == null) return null;
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   166
                switch (tree.getKind()) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   167
                    case METHOD: case CLASS: case VARIABLE: case TYPE_PARAMETER:
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   168
                        TreePath path = new TreePath(getCurrentPath(), tree);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   169
                        Element el = trees.getElement(path);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   170
                        if (el == null) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   171
                            error("null element");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   172
                        } else {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   173
                            TreePath inferred = trees.getPath(el);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   174
                            if (inferred == null) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   175
                                error("null path");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   176
                            } else {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   177
                                if (inferred.getLeaf() != path.getLeaf())
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   178
                                    error("bad result from getPath");
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
                            if (trees.getTree(el) != path.getLeaf())
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   181
                                error("bad result from getTree");
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   182
                            for (AnnotationMirror m: el.getAnnotationMirrors()) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   183
                                testAnnotation(trees, el, m);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   184
                            }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   185
                        }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   186
                }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   187
                return super.scan(tree, p);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   188
            }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   189
        }.scan(cut, null);
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   190
    }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   191
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    void error(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        if (messager != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            // annotation processing will happen in a separate instance/classloader
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            // so pass the message back to the calling instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            messager.printMessage(Diagnostic.Kind.ERROR, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            System.err.println(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            errors++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    Messager messager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    int errors;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        Trees trees = Trees.instance(processingEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        messager = processingEnv.getMessager();
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        for (Element e: rEnv.getRootElements()) {
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
        for (TypeElement anno: annos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            System.err.println("anno: " + anno);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            System.err.println("elts: " + elts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            if (elts != null) { // 6397298, should return empty set
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                for (Element e: rEnv.getElementsAnnotatedWith(anno))
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                    testElement(trees, e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public SourceVersion getSupportedSourceVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        return SourceVersion.latest();
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    class MyTaskListener implements TaskListener {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        MyTaskListener(JavacTask task) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            this.task = task;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        public void started(TaskEvent e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            System.err.println("started " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        public void finished(TaskEvent e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            //System.err.println("finished " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            switch (e.getKind()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            case ANALYZE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                testElement(Trees.instance(task), e.getTypeElement());
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   248
                testAllDeclarations(Trees.instance(task), e.getCompilationUnit());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        private final JavacTask task;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   256
    public static class TestTypeParams<@Anno T extends CharSequence> {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   257
        public <@Anno T extends Object> TestTypeParams(T param) { }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   258
        public <@Anno T extends Number> void m(T param) {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   259
            int local;
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   260
            try {
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   261
                new String();
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   262
            } catch (Exception exc) { }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   263
        }
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   264
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
@Retention(RetentionPolicy.SOURCE)
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   268
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE_PARAMETER,
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 5520
diff changeset
   269
         ElementType.FIELD, ElementType.LOCAL_VARIABLE})
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
@interface Anno {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
}