author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 23810 | b92eb80925f0 |
permissions | -rw-r--r-- |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
23810
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
4 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
8 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
14 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
18 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
22 |
*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
23 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
24 |
/* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
25 |
* @test |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8038455 |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
27 |
* @summary Verify that Types caches (in particular MembersClosureCache) get cleared between rounds. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
28 |
* @library /tools/javac/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
23810
diff
changeset
|
29 |
* @modules jdk.compiler |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
30 |
* @build JavacTestingAbstractProcessor TypesCachesCleared |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
31 |
* @compile/process -processor TypesCachesCleared TypesCachesCleared.java |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
32 |
*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
33 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
34 |
import java.util.*; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
35 |
import javax.annotation.processing.*; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
36 |
import javax.lang.model.element.*; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
37 |
import static javax.lang.model.util.ElementFilter.constructorsIn; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
38 |
import javax.lang.model.util.Elements; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
39 |
import com.sun.source.tree.ClassTree; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
40 |
import com.sun.source.tree.NewClassTree; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
41 |
import com.sun.source.util.TreePath; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
42 |
import com.sun.source.util.TreePathScanner; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
43 |
import com.sun.source.util.Trees; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
44 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
45 |
public class TypesCachesCleared extends JavacTestingAbstractProcessor { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
46 |
int round = 1; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
47 |
public boolean process(Set<? extends TypeElement> annotations, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
48 |
RoundEnvironment roundEnv) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
49 |
new TestPathScanner<Void>() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
50 |
@Override |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
51 |
public void visit(Void t) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
52 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
53 |
}; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
54 |
TypeElement currentClass = elements.getTypeElement("TypesCachesCleared"); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
55 |
Trees trees = Trees.instance(processingEnv); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
56 |
TreePath path = trees.getPath(currentClass); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
57 |
new TreePathScanner<Void, Void>() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
58 |
@Override public Void visitClass(ClassTree node, Void p) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
59 |
trees.getElement(getCurrentPath()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
60 |
return super.visitClass(node, p); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
61 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
62 |
}.scan(path, null); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
63 |
return false; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
64 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
65 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
66 |
public TypesCachesCleared() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
67 |
class Local { } |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
68 |
new Object() { }; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
69 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
70 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
71 |
public boolean process(Elements elements) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
72 |
TypeElement currentClass = elements.getTypeElement("OnDemandAttribution"); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
73 |
ExecutableElement constr = constructorsIn(currentClass.getEnclosedElements()).get(0); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
74 |
Trees trees = Trees.instance(processingEnv); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
75 |
TreePath path = trees.getPath(constr); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
76 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
77 |
new TreePathScanner<Void, Void>() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
78 |
@Override public Void visitClass(ClassTree node, Void p) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
79 |
if (node.getSimpleName().contentEquals("Local")) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
80 |
//will also attribute the body on demand: |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
81 |
Element el = trees.getElement(getCurrentPath()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
82 |
Name binaryName = elements.getBinaryName((TypeElement) el); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
83 |
if (!binaryName.contentEquals("OnDemandAttribution$1Local")) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
84 |
throw new IllegalStateException("Incorrect binary name=" + binaryName); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
85 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
86 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
87 |
return super.visitClass(node, p); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
88 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
89 |
@Override public Void visitNewClass(NewClassTree node, Void p) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
90 |
Element el = trees.getElement(getCurrentPath()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
91 |
Name binaryName = elements.getBinaryName((TypeElement) el.getEnclosingElement()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
92 |
if (!binaryName.contentEquals("OnDemandAttribution$1")) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
93 |
throw new IllegalStateException("Incorrect binary name=" + binaryName); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
94 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
95 |
return super.visitNewClass(node, p); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
96 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
97 |
}.scan(path, null); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
98 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
99 |
return true; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
100 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
101 |
public static interface TestVisitor<T> { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
102 |
public void visit(T t); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
103 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
104 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
105 |
public static class TestScanner<T> implements TestVisitor<T> { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
106 |
public void visit(T t) { } |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
107 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
108 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
109 |
public static class TestPathScanner<T> extends TestScanner<T> { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
110 |
public void visit(T t) { } |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
111 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
112 |
} |