BinaryName.java revision 1465:b52a38d4536c
1351280Sdim/*
2351280Sdim * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3351280Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4351280Sdim *
5351280Sdim * This code is free software; you can redistribute it and/or modify it
6351280Sdim * under the terms of the GNU General Public License version 2 only, as
7351280Sdim * published by the Free Software Foundation.
8351280Sdim *
9351280Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10351280Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11351280Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12351280Sdim * version 2 for more details (a copy is included in the LICENSE file that
13351280Sdim * accompanied this code).
14351280Sdim *
15351280Sdim * You should have received a copy of the GNU General Public License version
16351280Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17351280Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18351280Sdim *
19351280Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20351280Sdim * or visit www.oracle.com if you need additional information or have any
21351280Sdim * questions.
22351280Sdim */
23351280Sdim
24351280Sdim/*
25351280Sdim * @test
26351280Sdim * @bug     6346251
27351280Sdim * @summary Test Elements.getBinaryName
28351280Sdim * @author  Scott Seligman
29351280Sdim * @library /tools/javac/lib
30351280Sdim * @build   JavacTestingAbstractProcessor BinaryName
31351280Sdim * @compile -processor BinaryName -proc:only BinaryName.java
32351280Sdim */
33351280Sdim
34351280Sdimimport java.util.Set;
35351280Sdimimport javax.annotation.processing.*;
36351280Sdimimport javax.lang.model.element.*;
37351280Sdimimport javax.lang.model.type.*;
38351280Sdimimport javax.lang.model.util.*;
39351280Sdim
40351280Sdimimport static javax.lang.model.util.ElementFilter.typesIn;
41351280Sdim
42351280Sdim@HelloIm("BinaryName")
43351280Sdimpublic class BinaryName extends JavacTestingAbstractProcessor {
44351280Sdim    public boolean process(Set<? extends TypeElement> tes,
45351280Sdim                           RoundEnvironment round) {
46351280Sdim        if (round.processingOver()) return true;
47351280Sdim
48351280Sdim        Set<? extends TypeElement> ts = typesIn(round.getElementsAnnotatedWith(
49351280Sdim                elements.getTypeElement("HelloIm")));
50351280Sdim
51351280Sdim        boolean success = true;
52351280Sdim        for (TypeElement t : ts) {
53351280Sdim            String expected = t.getAnnotation(HelloIm.class).value();
54351280Sdim            CharSequence found = elements.getBinaryName(t);
55            if (expected.contentEquals(found)) {
56                System.out.println(expected + " == " + found);
57            } else {
58                success = false;
59                System.out.println(expected + " != " + found + "  [FAIL]");
60            }
61        }
62        if (! success)
63            throw new AssertionError();
64        return true;
65    }
66
67    @HelloIm("BinaryName$Nested")
68    private static class Nested {
69    }
70}
71
72@interface HelloIm {
73    String value();
74}
75