author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 7681 | 1f0819a3341f |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
7681
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
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 |
* |
|
5520 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6423583 |
|
27 |
* @summary LiteralTree.getValue() should return Boolean for Kind.BOOLEAN_LITERAL literals |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
7681
diff
changeset
|
28 |
* @modules jdk.compiler |
10 | 29 |
* @build T6423583 |
30 |
* @compile -proc:only -processor T6423583 T6423583.java |
|
31 |
*/ |
|
32 |
||
33 |
import java.util.*; |
|
34 |
import javax.annotation.processing.*; |
|
35 |
import javax.lang.model.*; |
|
36 |
import javax.lang.model.element.*; |
|
37 |
import com.sun.source.tree.*; |
|
38 |
import com.sun.source.util.*; |
|
39 |
||
40 |
@SupportedAnnotationTypes("*") |
|
41 |
public class T6423583 extends AbstractProcessor { |
|
42 |
boolean b1 = true; |
|
43 |
boolean b2 = false; |
|
44 |
String s = "s"; |
|
45 |
char c = 'c'; |
|
46 |
int i = 0; |
|
47 |
long l = 0l; |
|
48 |
float f = 0f; |
|
49 |
double d = 0d; |
|
50 |
Void v = null; |
|
51 |
||
52 |
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) { |
|
53 |
Trees trees = Trees.instance(processingEnv); |
|
54 |
Test test = new Test(); |
|
55 |
for (Element e: rEnv.getRootElements()) { |
|
56 |
Tree t = trees.getTree(e); |
|
57 |
test.scan(t, null); |
|
58 |
} |
|
59 |
return true; |
|
60 |
} |
|
61 |
||
4935
ff8adaa7bb8e
6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents:
10
diff
changeset
|
62 |
@Override |
ff8adaa7bb8e
6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents:
10
diff
changeset
|
63 |
public SourceVersion getSupportedSourceVersion() { |
ff8adaa7bb8e
6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents:
10
diff
changeset
|
64 |
return SourceVersion.latest(); |
ff8adaa7bb8e
6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents:
10
diff
changeset
|
65 |
} |
10 | 66 |
|
67 |
private static class Test extends TreeScanner<Void,Void> { |
|
68 |
||
69 |
private static Map<Tree.Kind, Class> map = new HashMap<Tree.Kind, Class>(); |
|
70 |
static { |
|
71 |
map.put(Tree.Kind.BOOLEAN_LITERAL, Boolean.class); |
|
72 |
map.put(Tree.Kind.CHAR_LITERAL, Character.class); |
|
73 |
map.put(Tree.Kind.STRING_LITERAL, String.class); |
|
74 |
map.put(Tree.Kind.INT_LITERAL, Integer.class); |
|
75 |
map.put(Tree.Kind.LONG_LITERAL, Long.class); |
|
76 |
map.put(Tree.Kind.FLOAT_LITERAL, Float.class); |
|
77 |
map.put(Tree.Kind.DOUBLE_LITERAL, Double.class); |
|
78 |
} |
|
79 |
||
80 |
public Void visitLiteral(LiteralTree tree, Void ignore) { |
|
81 |
System.err.println(tree); |
|
82 |
Class expect = map.get(tree.getKind()); |
|
83 |
if (!check(tree.getValue(), expect)) { |
|
84 |
System.err.println("tree: " + tree); |
|
85 |
System.err.println("expected class: " + expect); |
|
86 |
if (tree.getValue() != null) |
|
87 |
System.err.println("actual class: " + tree.getValue().getClass()); |
|
88 |
throw new AssertionError("unexpected value for literal"); |
|
89 |
} |
|
90 |
return null; |
|
91 |
} |
|
92 |
||
93 |
private boolean check(Object value, Class<?> expectedClass) { |
|
94 |
return (value == null ? expectedClass == null : value.getClass().equals(expectedClass)); |
|
95 |
} |
|
96 |
} |
|
97 |
} |