TestPackageElement.java revision 1465:b52a38d4536c
1283514Sarybchik/*
2283514Sarybchik * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3283514Sarybchik * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4283514Sarybchik *
5283514Sarybchik * This code is free software; you can redistribute it and/or modify it
6283514Sarybchik * under the terms of the GNU General Public License version 2 only, as
7283514Sarybchik * published by the Free Software Foundation.
8283514Sarybchik *
9283514Sarybchik * This code is distributed in the hope that it will be useful, but WITHOUT
10283514Sarybchik * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11283514Sarybchik * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12283514Sarybchik * version 2 for more details (a copy is included in the LICENSE file that
13283514Sarybchik * accompanied this code).
14283514Sarybchik *
15283514Sarybchik * You should have received a copy of the GNU General Public License version
16283514Sarybchik * 2 along with this work; if not, write to the Free Software Foundation,
17283514Sarybchik * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18283514Sarybchik *
19283514Sarybchik * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20283514Sarybchik * or visit www.oracle.com if you need additional information or have any
21283514Sarybchik * questions.
22283514Sarybchik */
23283514Sarybchik
24283514Sarybchik/*
25283514Sarybchik * @test
26283514Sarybchik * @bug 6449798 6399404
27283514Sarybchik * @summary Test basic workings of PackageElement
28283514Sarybchik * @author  Joseph D. Darcy
29283514Sarybchik * @library /tools/javac/lib
30283514Sarybchik * @build   JavacTestingAbstractProcessor TestPackageElement
31283514Sarybchik * @compile -processor TestPackageElement -proc:only TestPackageElement.java
32283514Sarybchik */
33283514Sarybchik
34283514Sarybchikimport java.util.Set;
35283514Sarybchikimport javax.annotation.processing.*;
36283514Sarybchikimport javax.lang.model.SourceVersion;
37283514Sarybchikimport static javax.lang.model.SourceVersion.*;
38283514Sarybchikimport javax.lang.model.element.*;
39283514Sarybchikimport javax.lang.model.util.*;
40283514Sarybchikimport static javax.lang.model.util.ElementFilter.*;
41283514Sarybchikimport static javax.tools.Diagnostic.Kind.*;
42283514Sarybchikimport static javax.tools.StandardLocation.*;
43283514Sarybchik
44283514Sarybchik/**
45283514Sarybchik * Test basic workings of PackageElement.
46283514Sarybchik */
47283514Sarybchikpublic class TestPackageElement extends JavacTestingAbstractProcessor {
48283514Sarybchik    public boolean process(Set<? extends TypeElement> annotations,
49283514Sarybchik                           RoundEnvironment roundEnv) {
50283514Sarybchik        if (!roundEnv.processingOver()) {
51283514Sarybchik            PackageElement unnamedPkg = eltUtils.getPackageElement("");
52283514Sarybchik
53283514Sarybchik            if (!unnamedPkg.getQualifiedName().contentEquals(""))
54283514Sarybchik                throw new RuntimeException("The unnamed package is named!");
55283514Sarybchik
56283514Sarybchik            // The next line tests an implementation detail upon which
57283514Sarybchik            // some diagnostics depend.
58283514Sarybchik            if (!unnamedPkg.toString().equals("unnamed package"))
59283514Sarybchik                throw new RuntimeException(
60283514Sarybchik                                "toString on unnamed package: " + unnamedPkg);
61283514Sarybchik
62283514Sarybchik            if (!unnamedPkg.isUnnamed())
63283514Sarybchik                throw new RuntimeException("The isUnnamed method on the unnamed package returned false!");
64283514Sarybchik
65283514Sarybchik            PackageElement javaLang = eltUtils.getPackageElement("java.lang");
66283514Sarybchik            if (javaLang.isUnnamed())
67283514Sarybchik                throw new RuntimeException("Package java.lang is unnamed!");
68283514Sarybchik        }
69283514Sarybchik        return true;
70283514Sarybchik    }
71283514Sarybchik}
72283514Sarybchik