Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/internal/api/JavadocTaskImpl.java
41171 views
1
/*
2
* Copyright (c) 2012, 2020, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.javadoc.internal.api;
27
28
import java.util.ArrayList;
29
import java.util.Collections;
30
import java.util.List;
31
import java.util.Locale;
32
import java.util.concurrent.atomic.AtomicBoolean;
33
34
import javax.tools.DocumentationTool.DocumentationTask;
35
import javax.tools.JavaFileObject;
36
37
import com.sun.tools.javac.main.Option;
38
import com.sun.tools.javac.util.ClientCodeException;
39
import com.sun.tools.javac.util.Context;
40
import com.sun.tools.javac.util.Options;
41
import jdk.javadoc.internal.tool.Start;
42
43
/**
44
* Provides access to functionality specific to the JDK documentation tool,
45
* javadoc.
46
*
47
* <p><b>This is NOT part of any supported API.
48
* If you write code that depends on this, you do so at your own
49
* risk. This code and its internal interfaces are subject to change
50
* or deletion without notice.</b></p>
51
*/
52
public class JavadocTaskImpl implements DocumentationTask {
53
private final AtomicBoolean used = new AtomicBoolean();
54
55
private final Context context;
56
private final Class<?> docletClass;
57
private final Iterable<String> options;
58
private final Iterable<? extends JavaFileObject> fileObjects;
59
private Locale locale;
60
private final List<String> addModules = new ArrayList<>();
61
62
public JavadocTaskImpl(Context context,
63
Class<?> docletClass,
64
Iterable<String> options,
65
Iterable<? extends JavaFileObject> fileObjects)
66
{
67
this.context = context;
68
this.docletClass = docletClass;
69
70
this.options = (options == null) ? Collections.emptySet()
71
: nullCheck(options);
72
this.fileObjects = (fileObjects == null) ? Collections.emptySet()
73
: nullCheck(fileObjects);
74
setLocale(Locale.getDefault());
75
}
76
77
@Override
78
public void setLocale(Locale locale) {
79
if (used.get()) {
80
throw new IllegalStateException();
81
}
82
this.locale = locale;
83
}
84
85
@Override
86
public void addModules(Iterable<String> moduleNames) {
87
nullCheck(moduleNames);
88
if (used.get()) {
89
throw new IllegalStateException();
90
}
91
for (String name : moduleNames) {
92
addModules.add(name);
93
}
94
}
95
96
@Override
97
public Boolean call() {
98
if (used.getAndSet(true)) {
99
throw new IllegalStateException("multiple calls to method 'call'");
100
}
101
initContext();
102
Start jdoc = new Start(context);
103
try {
104
return jdoc.begin(docletClass, options, fileObjects);
105
} catch (ClientCodeException e) {
106
throw new RuntimeException(e.getCause());
107
}
108
}
109
110
private void initContext() {
111
//initialize compiler's default locale
112
context.put(Locale.class, locale);
113
if (!addModules.isEmpty()) {
114
String names = String.join(",", addModules);
115
Options opts = Options.instance(context);
116
String prev = opts.get(Option.ADD_MODULES);
117
opts.put(Option.ADD_MODULES, (prev == null) ? names : prev + "," + names);
118
}
119
}
120
121
private static <T> Iterable<T> nullCheck(Iterable<T> items) {
122
for (T item : items) {
123
if (item == null)
124
throw new NullPointerException();
125
}
126
return items;
127
}
128
}
129
130