SourceOnly.java revision 3595:81692f730015
1230557Sjimharris/*
2230557Sjimharris * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3230557Sjimharris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4230557Sjimharris *
5230557Sjimharris * This code is free software; you can redistribute it and/or modify it
6230557Sjimharris * under the terms of the GNU General Public License version 2 only, as
7230557Sjimharris * published by the Free Software Foundation.
8230557Sjimharris *
9230557Sjimharris * This code is distributed in the hope that it will be useful, but WITHOUT
10230557Sjimharris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11230557Sjimharris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12230557Sjimharris * version 2 for more details (a copy is included in the LICENSE file that
13230557Sjimharris * accompanied this code).
14230557Sjimharris *
15230557Sjimharris * You should have received a copy of the GNU General Public License version
16230557Sjimharris * 2 along with this work; if not, write to the Free Software Foundation,
17230557Sjimharris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18230557Sjimharris *
19230557Sjimharris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20230557Sjimharris * or visit www.oracle.com if you need additional information or have any
21230557Sjimharris * questions.
22230557Sjimharris */
23230557Sjimharris
24230557Sjimharrispackage p;
25230557Sjimharris
26230557Sjimharrisimport java.util.Arrays;
27230557Sjimharrisimport java.util.Collections;
28230557Sjimharrisimport java.util.Locale;
29230557Sjimharrisimport java.util.Set;
30230557Sjimharris
31230557Sjimharrisimport javax.lang.model.SourceVersion;
32230557Sjimharris
33230557Sjimharrisimport jdk.javadoc.doclet.Doclet;
34230557Sjimharrisimport jdk.javadoc.doclet.DocletEnvironment;
35230557Sjimharrisimport jdk.javadoc.doclet.Reporter;
36230557Sjimharris
37230557Sjimharris/** Test that when running javadoc on a package, we only get
38230557Sjimharris *  documentation for those classes for which source was provided.
39230557Sjimharris */
40230557Sjimharrispublic class SourceOnly implements Doclet {
41230557Sjimharris    NonSource dependency; // force a compilation error if not on classpath.
42230557Sjimharris
43230557Sjimharris    @Override
44230557Sjimharris    public boolean run(DocletEnvironment root) {
45230557Sjimharris        if (root.getIncludedTypeElements().size() != 1)
46230557Sjimharris            throw new Error("wrong set of classes documented: " +
47230557Sjimharris                    Arrays.asList(root.getIncludedTypeElements()));
48230557Sjimharris        return true;
49230557Sjimharris    }
50230557Sjimharris
51230557Sjimharris    @Override
52230557Sjimharris    public String getName() {
53230557Sjimharris        return "Test";
54230557Sjimharris    }
55230557Sjimharris
56230557Sjimharris    @Override
57230557Sjimharris    public Set<Option> getSupportedOptions() {
58230557Sjimharris        return Collections.emptySet();
59230557Sjimharris    }
60230557Sjimharris
61230557Sjimharris    @Override
62230557Sjimharris    public SourceVersion getSupportedSourceVersion() {
63230557Sjimharris        return SourceVersion.latest();
64230557Sjimharris    }
65230557Sjimharris
66230557Sjimharris    @Override
67230557Sjimharris    public void init(Locale locale, Reporter reporter) {
68230557Sjimharris        // do nothing
69230557Sjimharris    }
70230557Sjimharris}
71230557Sjimharris