author | avstepan |
Tue, 19 May 2015 16:04:14 +0400 | |
changeset 30655 | d83f50188ca9 |
parent 27319 | 030080f03e4f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
4 |
* |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
8 |
* |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
14 |
* |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
18 |
* |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
21 |
* questions. |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
22 |
*/ |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
23 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
24 |
/* |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
25 |
* @test |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
26 |
* @bug 7090249 |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
27 |
* @summary IllegalStateException from Trees.getScope when called from JSR 199 |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
28 |
*/ |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
29 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
30 |
import com.sun.source.tree.IdentifierTree; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
31 |
import java.io.File; |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
32 |
import java.io.IOException; |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
34 |
import java.util.Collections; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
35 |
import java.util.List; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
36 |
import java.util.Set; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
37 |
import javax.annotation.processing.AbstractProcessor; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
38 |
import javax.annotation.processing.RoundEnvironment; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
39 |
import javax.lang.model.element.Element; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
40 |
import javax.lang.model.element.TypeElement; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
41 |
import javax.tools.JavaCompiler; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
42 |
import javax.tools.JavaFileObject; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
43 |
import javax.tools.StandardJavaFileManager; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
44 |
import javax.tools.ToolProvider; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
45 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
46 |
import com.sun.source.util.JavacTask; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
47 |
import com.sun.source.util.TreePath; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
48 |
import com.sun.source.util.TreePathScanner; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
49 |
import com.sun.source.util.Trees; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
50 |
import javax.annotation.processing.SupportedAnnotationTypes; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
51 |
import javax.lang.model.SourceVersion; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
52 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
53 |
@SupportedAnnotationTypes("*") |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
54 |
public class TestGetScope extends AbstractProcessor { |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
55 |
public static void main(String... args) throws IOException { |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
56 |
new TestGetScope().run(); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
57 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
58 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
59 |
public void run() throws IOException { |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
60 |
File srcDir = new File(System.getProperty("test.src")); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
61 |
File thisFile = new File(srcDir, getClass().getName() + ".java"); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
62 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
63 |
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
64 |
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) { |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
65 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
66 |
List<String> opts = Arrays.asList("-proc:only", "-doe"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
67 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
68 |
JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
69 |
t.setProcessors(Collections.singleton(this)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
70 |
boolean ok = t.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
71 |
if (!ok) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
72 |
throw new Error("compilation failed"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
10631
diff
changeset
|
73 |
} |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
74 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
75 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
76 |
@Override |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
77 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
78 |
Trees trees = Trees.instance(processingEnv); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
79 |
if (round++ == 0) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
80 |
for (Element e: roundEnv.getRootElements()) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
81 |
TreePath p = trees.getPath(e); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
82 |
new Scanner().scan(p, trees); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
83 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
84 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
85 |
return false; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
86 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
87 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
88 |
@Override |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
89 |
public SourceVersion getSupportedSourceVersion() { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
90 |
return SourceVersion.latest(); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
91 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
92 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
93 |
int round; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
94 |
|
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
95 |
static class Scanner extends TreePathScanner<Void,Trees> { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
96 |
@Override |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
97 |
public Void visitIdentifier(IdentifierTree t, Trees trees) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
98 |
System.err.println("visitIdentifier: " + t); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
99 |
trees.getScope(getCurrentPath()); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
100 |
return null; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
101 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
102 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
diff
changeset
|
103 |
} |