7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 /*
26 * @test
27 * @bug 6639645 7026414
28 * @summary Modeling type implementing missing interfaces
29 * @library ../../../../lib
30 * @build JavacTestingAbstractProcessor TestMissingElement
31 * @compile -proc:only -XprintRounds -processor TestMissingElement InvalidSource.java
32 */
33
34 import java.util.*;
35 import javax.annotation.processing.*;
36 import javax.lang.model.element.*;
37 import javax.lang.model.type.*;
38 import javax.lang.model.util.*;
39 import static javax.tools.Diagnostic.Kind.*;
40
41 public class TestMissingElement extends JavacTestingAbstractProcessor {
42 @Override
43 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
44 for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) {
45 if (isSimpleName(te, "InvalidSource")) {
46 for (Element c: te.getEnclosedElements()) {
47 for (AnnotationMirror am: c.getAnnotationMirrors()) {
48 Element ate = am.getAnnotationType().asElement();
49 if (isSimpleName(ate, "ExpectInterfaces")) {
50 checkInterfaces((TypeElement) c, getValue(am));
51 } else if (isSimpleName(ate, "ExpectSupertype")) {
52 checkSupertype((TypeElement) c, getValue(am));
53 }
54 }
55 }
56 }
57 }
58 return true;
59 }
87 } else {
88 System.err.println("unexpected " + label + ": " + te + "\n"
89 + " found: " + found + "\n"
90 + "expect: " + expect);
91 messager.printMessage(ERROR, "unexpected " + label + " found: " + found + "; expected: " + expect, te);
92 }
93 }
94
95 private String asString(List<? extends TypeMirror> ts, String sep) {
96 StringBuilder sb = new StringBuilder();
97 for (TypeMirror t: ts) {
98 if (sb.length() != 0) sb.append(sep);
99 sb.append(asString(t));
100 }
101 return sb.toString();
102 }
103
104 private String asString(TypeMirror t) {
105 if (t == null)
106 return "[typ:null]";
107 return t.accept(new SimpleTypeVisitor7<String, Void>() {
108 @Override
109 public String defaultAction(TypeMirror t, Void ignore) {
110 return "[typ:" + t.toString() + "]";
111 }
112
113 @Override
114 public String visitDeclared(DeclaredType t, Void ignore) {
115 checkEqual(t.asElement(), types.asElement(t));
116 String s = asString(t.asElement());
117 List<? extends TypeMirror> args = t.getTypeArguments();
118 if (!args.isEmpty())
119 s += "<" + asString(args, ",") + ">";
120 return s;
121 }
122
123 @Override
124 public String visitTypeVariable(TypeVariable t, Void ignore) {
125 return "tvar " + t;
126 }
127
128 @Override
129 public String visitError(ErrorType t, Void ignore) {
130 return "!:" + visitDeclared(t, ignore);
131 }
132 }, null);
133 }
134
135 private String asString(Element e) {
136 if (e == null)
137 return "[elt:null]";
138 return e.accept(new SimpleElementVisitor7<String, Void>() {
139 @Override
140 public String defaultAction(Element e, Void ignore) {
141 return "[elt:" + e.getKind() + " " + e.toString() + "]";
142 }
143 @Override
144 public String visitPackage(PackageElement e, Void ignore) {
145 return "pkg " + e.getQualifiedName();
146 }
147 @Override
148 public String visitType(TypeElement e, Void ignore) {
149 StringBuilder sb = new StringBuilder();
150 if (e.getEnclosedElements().isEmpty())
151 sb.append("empty ");
152 ElementKind ek = e.getKind();
153 switch (ek) {
154 case CLASS:
155 sb.append("clss");
156 break;
157 case INTERFACE:
158 sb.append("intf");
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 /*
26 * @test
27 * @bug 6639645 7026414 7025809
28 * @summary Modeling type implementing missing interfaces
29 * @library ../../../../lib
30 * @build JavacTestingAbstractProcessor TestMissingElement
31 * @compile -proc:only -XprintRounds -processor TestMissingElement InvalidSource.java
32 */
33
34 import java.util.*;
35 import javax.annotation.processing.*;
36 import javax.lang.model.element.*;
37 import javax.lang.model.type.*;
38 import javax.lang.model.util.*;
39 import static javax.tools.Diagnostic.Kind.*;
40 import static JavacTestingAbstractProcessor.*;
41
42 public class TestMissingElement extends JavacTestingAbstractProcessor {
43 @Override
44 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
45 for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) {
46 if (isSimpleName(te, "InvalidSource")) {
47 for (Element c: te.getEnclosedElements()) {
48 for (AnnotationMirror am: c.getAnnotationMirrors()) {
49 Element ate = am.getAnnotationType().asElement();
50 if (isSimpleName(ate, "ExpectInterfaces")) {
51 checkInterfaces((TypeElement) c, getValue(am));
52 } else if (isSimpleName(ate, "ExpectSupertype")) {
53 checkSupertype((TypeElement) c, getValue(am));
54 }
55 }
56 }
57 }
58 }
59 return true;
60 }
88 } else {
89 System.err.println("unexpected " + label + ": " + te + "\n"
90 + " found: " + found + "\n"
91 + "expect: " + expect);
92 messager.printMessage(ERROR, "unexpected " + label + " found: " + found + "; expected: " + expect, te);
93 }
94 }
95
96 private String asString(List<? extends TypeMirror> ts, String sep) {
97 StringBuilder sb = new StringBuilder();
98 for (TypeMirror t: ts) {
99 if (sb.length() != 0) sb.append(sep);
100 sb.append(asString(t));
101 }
102 return sb.toString();
103 }
104
105 private String asString(TypeMirror t) {
106 if (t == null)
107 return "[typ:null]";
108 return t.accept(new SimpleTypeVisitor<String, Void>() {
109 @Override
110 public String defaultAction(TypeMirror t, Void ignore) {
111 return "[typ:" + t.toString() + "]";
112 }
113
114 @Override
115 public String visitDeclared(DeclaredType t, Void ignore) {
116 checkEqual(t.asElement(), types.asElement(t));
117 String s = asString(t.asElement());
118 List<? extends TypeMirror> args = t.getTypeArguments();
119 if (!args.isEmpty())
120 s += "<" + asString(args, ",") + ">";
121 return s;
122 }
123
124 @Override
125 public String visitTypeVariable(TypeVariable t, Void ignore) {
126 return "tvar " + t;
127 }
128
129 @Override
130 public String visitError(ErrorType t, Void ignore) {
131 return "!:" + visitDeclared(t, ignore);
132 }
133 }, null);
134 }
135
136 private String asString(Element e) {
137 if (e == null)
138 return "[elt:null]";
139 return e.accept(new SimpleElementVisitor<String, Void>() {
140 @Override
141 public String defaultAction(Element e, Void ignore) {
142 return "[elt:" + e.getKind() + " " + e.toString() + "]";
143 }
144 @Override
145 public String visitPackage(PackageElement e, Void ignore) {
146 return "pkg " + e.getQualifiedName();
147 }
148 @Override
149 public String visitType(TypeElement e, Void ignore) {
150 StringBuilder sb = new StringBuilder();
151 if (e.getEnclosedElements().isEmpty())
152 sb.append("empty ");
153 ElementKind ek = e.getKind();
154 switch (ek) {
155 case CLASS:
156 sb.append("clss");
157 break;
158 case INTERFACE:
159 sb.append("intf");
|