test/tools/javac/T6423583.java

changeset 1
9a66ca7c79fa
child 495
fe17a9dbef03
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/T6423583.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,93 @@
     1.4 +/*
     1.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6423583
    1.30 + * @summary LiteralTree.getValue() should return Boolean for Kind.BOOLEAN_LITERAL literals
    1.31 + * @build T6423583
    1.32 + * @compile -proc:only -processor T6423583 T6423583.java
    1.33 + */
    1.34 +
    1.35 +import java.util.*;
    1.36 +import javax.annotation.processing.*;
    1.37 +import javax.lang.model.*;
    1.38 +import javax.lang.model.element.*;
    1.39 +import com.sun.source.tree.*;
    1.40 +import com.sun.source.util.*;
    1.41 +
    1.42 +@SupportedAnnotationTypes("*")
    1.43 +@SupportedSourceVersion(SourceVersion.RELEASE_6)
    1.44 +public class T6423583 extends AbstractProcessor {
    1.45 +    boolean b1 = true;
    1.46 +    boolean b2 = false;
    1.47 +    String s = "s";
    1.48 +    char c = 'c';
    1.49 +    int i = 0;
    1.50 +    long l = 0l;
    1.51 +    float f = 0f;
    1.52 +    double d = 0d;
    1.53 +    Void v = null;
    1.54 +
    1.55 +    public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
    1.56 +        Trees trees = Trees.instance(processingEnv);
    1.57 +        Test test = new Test();
    1.58 +        for (Element e: rEnv.getRootElements()) {
    1.59 +            Tree t = trees.getTree(e);
    1.60 +            test.scan(t, null);
    1.61 +        }
    1.62 +        return true;
    1.63 +    }
    1.64 +
    1.65 +
    1.66 +    private static class Test extends TreeScanner<Void,Void> {
    1.67 +
    1.68 +        private static Map<Tree.Kind, Class> map = new HashMap<Tree.Kind, Class>();
    1.69 +        static {
    1.70 +            map.put(Tree.Kind.BOOLEAN_LITERAL, Boolean.class);
    1.71 +            map.put(Tree.Kind.CHAR_LITERAL, Character.class);
    1.72 +            map.put(Tree.Kind.STRING_LITERAL, String.class);
    1.73 +            map.put(Tree.Kind.INT_LITERAL, Integer.class);
    1.74 +            map.put(Tree.Kind.LONG_LITERAL, Long.class);
    1.75 +            map.put(Tree.Kind.FLOAT_LITERAL, Float.class);
    1.76 +            map.put(Tree.Kind.DOUBLE_LITERAL, Double.class);
    1.77 +        }
    1.78 +
    1.79 +        public Void visitLiteral(LiteralTree tree, Void ignore) {
    1.80 +            System.err.println(tree);
    1.81 +            Class expect = map.get(tree.getKind());
    1.82 +            if (!check(tree.getValue(), expect)) {
    1.83 +                System.err.println("tree: " + tree);
    1.84 +                System.err.println("expected class: " + expect);
    1.85 +                if (tree.getValue() != null)
    1.86 +                    System.err.println("actual class: " + tree.getValue().getClass());
    1.87 +                throw new AssertionError("unexpected value for literal");
    1.88 +            }
    1.89 +            return null;
    1.90 +        }
    1.91 +
    1.92 +        private boolean check(Object value, Class<?> expectedClass) {
    1.93 +            return (value == null ? expectedClass == null : value.getClass().equals(expectedClass));
    1.94 +        }
    1.95 +    }
    1.96 +}

mercurial