test/tools/javac/processing/model/element/TestResourceVariable.java

changeset 1054
111bbf1ad913
parent 851
cad51b6eb7a6
child 1466
b52a38d4536c
equal deleted inserted replaced
1053:0d8edba73d70 1054:111bbf1ad913
21 * questions. 21 * questions.
22 */ 22 */
23 23
24 /* 24 /*
25 * @test 25 * @test
26 * @bug 6911256 6964740 6967842 6961571 26 * @bug 6911256 6964740 6967842 6961571 7025809
27 * @summary Test that the resource variable kind is appropriately set 27 * @summary Test that the resource variable kind is appropriately set
28 * @author Joseph D. Darcy 28 * @author Joseph D. Darcy
29 * @library ../../../lib 29 * @library ../../../lib
30 * @build JavacTestingAbstractProcessor TestResourceVariable 30 * @build JavacTestingAbstractProcessor TestResourceVariable
31 * @compile -processor TestResourceVariable -proc:only TestResourceVariable.java 31 * @compile -processor TestResourceVariable -proc:only TestResourceVariable.java
42 import com.sun.source.util.*; 42 import com.sun.source.util.*;
43 import static javax.tools.Diagnostic.Kind.*; 43 import static javax.tools.Diagnostic.Kind.*;
44 44
45 /** 45 /**
46 * Using the tree API, retrieve element representations of the 46 * Using the tree API, retrieve element representations of the
47 * resource of an ARM block and verify their kind tags are set 47 * resource of a try-with-resources statement and verify their kind
48 * appropriately. 48 * tags are set appropriately.
49 */ 49 */
50 public class TestResourceVariable extends JavacTestingAbstractProcessor implements AutoCloseable { 50 public class TestResourceVariable extends JavacTestingAbstractProcessor implements AutoCloseable {
51 int resourceVariableCount = 0; 51 int resourceVariableCount = 0;
52 52
53 public boolean process(Set<? extends TypeElement> annotations, 53 public boolean process(Set<? extends TypeElement> annotations,
80 try(TestResourceVariable trv1 = this; TestResourceVariable trv2 = trv1) {} 80 try(TestResourceVariable trv1 = this; TestResourceVariable trv2 = trv1) {}
81 } 81 }
82 82
83 /** 83 /**
84 * Verify that a resource variable modeled as an element behaves 84 * Verify that a resource variable modeled as an element behaves
85 * as expected under 6 and 7 specific visitors. 85 * as expected under 6 and latest specific visitors.
86 */ 86 */
87 private static void testResourceVariable(Element element) { 87 private static void testResourceVariable(Element element) {
88 ElementVisitor visitor6 = new ElementKindVisitor6<Void, Void>() {}; 88 ElementVisitor visitor6 = new ElementKindVisitor6<Void, Void>() {};
89 89
90 try { 90 try {
92 throw new RuntimeException("Expected UnknownElementException not thrown."); 92 throw new RuntimeException("Expected UnknownElementException not thrown.");
93 } catch (UnknownElementException uee) { 93 } catch (UnknownElementException uee) {
94 ; // Expected. 94 ; // Expected.
95 } 95 }
96 96
97 ElementKindVisitor7 visitor7 = new ElementKindVisitor7<Object, Void>() { 97 ElementKindVisitor visitorLatest =
98 new ElementKindVisitor<Object, Void>() {
98 @Override 99 @Override
99 public Object visitVariableAsResourceVariable(VariableElement e, 100 public Object visitVariableAsResourceVariable(VariableElement e,
100 Void p) { 101 Void p) {
101 return e; // a non-null value 102 return e; // a non-null value
102 } 103 }
103 }; 104 };
104 105
105 if (visitor7.visit(element) == null) { 106 if (visitorLatest.visit(element) == null) {
106 throw new RuntimeException("Null result of resource variable visitation."); 107 throw new RuntimeException("Null result of resource variable visitation.");
107 } 108 }
108 } 109 }
109 110
110 class ResourceVariableScanner extends TreeScanner<Void, CompilationUnitTree> { 111 class ResourceVariableScanner extends TreeScanner<Void, CompilationUnitTree> {

mercurial