test/tools/javac/T6423583.java

Print this page




  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  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  */
  31 
  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.*;
  38 
  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;
  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 




  62 
  63     private static class Test extends TreeScanner<Void,Void> {
  64 
  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         }
  75 
  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);


  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  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  */
  31 
  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.*;
  38 
  39 @SupportedAnnotationTypes("*")

  40 public class T6423583 extends AbstractProcessor {
  41     boolean b1 = true;
  42     boolean b2 = false;
  43     String s = "s";
  44     char c = 'c';
  45     int i = 0;
  46     long l = 0l;
  47     float f = 0f;
  48     double d = 0d;
  49     Void v = null;
  50 
  51     public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
  52         Trees trees = Trees.instance(processingEnv);
  53         Test test = new Test();
  54         for (Element e: rEnv.getRootElements()) {
  55             Tree t = trees.getTree(e);
  56             test.scan(t, null);
  57         }
  58         return true;
  59     }
  60 
  61     @Override
  62     public SourceVersion getSupportedSourceVersion() {
  63         return SourceVersion.latest();
  64     }
  65 
  66     private static class Test extends TreeScanner<Void,Void> {
  67 
  68         private static Map<Tree.Kind, Class> map = new HashMap<Tree.Kind, Class>();
  69         static {
  70             map.put(Tree.Kind.BOOLEAN_LITERAL, Boolean.class);
  71             map.put(Tree.Kind.CHAR_LITERAL, Character.class);
  72             map.put(Tree.Kind.STRING_LITERAL, String.class);
  73             map.put(Tree.Kind.INT_LITERAL, Integer.class);
  74             map.put(Tree.Kind.LONG_LITERAL, Long.class);
  75             map.put(Tree.Kind.FLOAT_LITERAL, Float.class);
  76             map.put(Tree.Kind.DOUBLE_LITERAL, Double.class);
  77         }
  78 
  79         public Void visitLiteral(LiteralTree tree, Void ignore) {
  80             System.err.println(tree);
  81             Class expect = map.get(tree.getKind());
  82             if (!check(tree.getValue(), expect)) {
  83                 System.err.println("tree: " + tree);
  84                 System.err.println("expected class: " + expect);