Tue, 03 Jun 2008 13:26:47 -0700
4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini
1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
24 /*
25 * @test
26 * @bug 6423583
27 * @summary LiteralTree.getValue() should return Boolean for Kind.BOOLEAN_LITERAL literals
28 * @build T6423583
29 * @compile -proc:only -processor T6423583 T6423583.java
30 */
32 import java.util.*;
33 import javax.annotation.processing.*;
34 import javax.lang.model.*;
35 import javax.lang.model.element.*;
36 import com.sun.source.tree.*;
37 import com.sun.source.util.*;
39 @SupportedAnnotationTypes("*")
40 @SupportedSourceVersion(SourceVersion.RELEASE_6)
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;
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 }
63 private static class Test extends TreeScanner<Void,Void> {
65 private static Map<Tree.Kind, Class> map = new HashMap<Tree.Kind, Class>();
66 static {
67 map.put(Tree.Kind.BOOLEAN_LITERAL, Boolean.class);
68 map.put(Tree.Kind.CHAR_LITERAL, Character.class);
69 map.put(Tree.Kind.STRING_LITERAL, String.class);
70 map.put(Tree.Kind.INT_LITERAL, Integer.class);
71 map.put(Tree.Kind.LONG_LITERAL, Long.class);
72 map.put(Tree.Kind.FLOAT_LITERAL, Float.class);
73 map.put(Tree.Kind.DOUBLE_LITERAL, Double.class);
74 }
76 public Void visitLiteral(LiteralTree tree, Void ignore) {
77 System.err.println(tree);
78 Class expect = map.get(tree.getKind());
79 if (!check(tree.getValue(), expect)) {
80 System.err.println("tree: " + tree);
81 System.err.println("expected class: " + expect);
82 if (tree.getValue() != null)
83 System.err.println("actual class: " + tree.getValue().getClass());
84 throw new AssertionError("unexpected value for literal");
85 }
86 return null;
87 }
89 private boolean check(Object value, Class<?> expectedClass) {
90 return (value == null ? expectedClass == null : value.getClass().equals(expectedClass));
91 }
92 }
93 }