Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/langtools/jdk/javadoc/tool/sourceOption/SourceOption.java
66646 views
1
/*
2
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6507179
27
* @summary Ensure that "-source" option isn't ignored.
28
* @modules jdk.javadoc/jdk.javadoc.internal.tool
29
* @run main/fail SourceOption 7
30
* @run main SourceOption 9
31
* @run main SourceOption
32
*/
33
34
/*
35
* In order to test whether or not the -source option is working
36
* correctly, this test tries to parse source code that contains
37
* a feature that is not available in at least one of the currently
38
* supported previous versions.
39
*
40
* Parsing such code should be expected to fail; if the action
41
* passes, that means the -source option is (incorrectly) ineffective.
42
*
43
* Additional actions are performed to ensure that the source
44
* provided is valid for the current release of the JDK.
45
*
46
* As support for older versions of the platform are dropped, the
47
* source code (currently p/LambdaConstructTest.java) will need to
48
* be updated with a more recent feature.
49
*/
50
51
import java.util.ArrayList;
52
import java.util.Collections;
53
import java.util.List;
54
import java.util.Locale;
55
import java.util.Set;
56
57
import javax.lang.model.SourceVersion;
58
import javax.lang.model.util.ElementFilter;
59
import javax.tools.Diagnostic.Kind;
60
61
import jdk.javadoc.doclet.Doclet;
62
import jdk.javadoc.doclet.Doclet.Option;
63
import jdk.javadoc.doclet.DocletEnvironment;
64
import jdk.javadoc.doclet.Reporter;
65
66
public class SourceOption implements Doclet {
67
68
public static void main(String[] args) {
69
List<String> params = new ArrayList<>();
70
params.add("-sourcepath");
71
params.add(System.getProperty("test.src"));
72
params.add("-docletpath");
73
params.add(System.getProperty("test.classes"));
74
params.add("-doclet");
75
params.add("SourceOption");
76
if ((args == null) || (args.length==0)) {
77
System.out.println("NOTE : -source not provided, default taken");
78
} else {
79
params.add("-source");
80
params.add(args[0]);
81
System.out.println("NOTE : -source will be: " + args[0]);
82
}
83
params.add("p");
84
System.out.println("arguments: " + params);
85
if (jdk.javadoc.internal.tool.Main.execute(params.toArray(new String[params.size()])) != 0)
86
throw new Error("Javadoc encountered warnings or errors.");
87
}
88
89
public boolean run(DocletEnvironment root) {
90
ElementFilter.typesIn(root.getIncludedElements());
91
return true;
92
}
93
94
@Override
95
public String getName() {
96
return "Test";
97
}
98
99
@Override
100
public Set<Option> getSupportedOptions() {
101
return Collections.emptySet();
102
}
103
104
@Override
105
public SourceVersion getSupportedSourceVersion() {
106
return SourceVersion.latest();
107
}
108
109
@Override
110
public void init(Locale locale, Reporter reporter) {
111
reporter.print(Kind.NOTE, "init");
112
}
113
}
114
115