author | jlahoda |
Wed, 02 Oct 2019 10:59:40 +0200 | |
branch | JDK-8226585-branch |
changeset 58440 | 4c8a6d1d066c |
parent 58342 | ebb1ff3d6707 |
child 58441 | 82f43796b28c |
permissions | -rw-r--r-- |
58342 | 1 |
/* |
2 |
* Copyright (c) 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. 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 build.tools.taglet; |
|
27 |
||
58440
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
28 |
import java.util.Arrays; |
58342 | 29 |
import java.util.EnumSet; |
30 |
import java.util.List; |
|
31 |
import java.util.Set; |
|
32 |
import javax.lang.model.element.Element; |
|
33 |
import com.sun.source.doctree.DocTree; |
|
58440
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
34 |
import com.sun.source.doctree.TextTree; |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
35 |
import com.sun.source.doctree.UnknownInlineTagTree; |
58342 | 36 |
import jdk.javadoc.doclet.Taglet; |
37 |
import static jdk.javadoc.doclet.Taglet.Location.*; |
|
38 |
||
39 |
/** |
|
40 |
* An block tag to insert a standard warning about a preview API. |
|
41 |
*/ |
|
42 |
public class Preview implements Taglet { |
|
43 |
||
44 |
/** Returns the set of locations in which a taglet may be used. */ |
|
45 |
@Override |
|
46 |
public Set<Location> getAllowedLocations() { |
|
47 |
return EnumSet.of(MODULE, PACKAGE, TYPE, CONSTRUCTOR, METHOD, FIELD); |
|
48 |
} |
|
49 |
||
50 |
@Override |
|
51 |
public boolean isInlineTag() { |
|
58440
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
52 |
return true; |
58342 | 53 |
} |
54 |
||
55 |
@Override |
|
56 |
public String getName() { |
|
57 |
return "preview"; |
|
58 |
} |
|
59 |
||
60 |
@Override |
|
61 |
public String toString(List<? extends DocTree> tags, Element elem) { |
|
58440
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
62 |
UnknownInlineTagTree previewTag = (UnknownInlineTagTree) tags.get(0); |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
63 |
List<? extends DocTree> previewContent = previewTag.getContent(); |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
64 |
String previewText = ((TextTree) previewContent.get(0)).getBody(); |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
65 |
String[] summaryAndDetails = previewText.split("\n\r?\n\r?"); |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
66 |
String summary = summaryAndDetails[0]; |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
67 |
String details = summaryAndDetails.length > 1 ? summaryAndDetails[1] : summaryAndDetails[0]; |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
68 |
if (Arrays.stream(new Exception().getStackTrace()).anyMatch(el -> el.getClassName().endsWith("HtmlDocletWriter") && el.getMethodName().equals("addSummaryComment"))) { |
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
69 |
return "<div style=\"display:inline-block; font-weight:bold\">" + summary + "</div><br>"; |
58342 | 70 |
} |
58440
4c8a6d1d066c
Improving appearance of javadoc of the APIs associated with preview features.
jlahoda
parents:
58342
diff
changeset
|
71 |
return "<div style=\"border: 1px solid red; border-radius: 25px; padding: 5px; display:inline-block; font-size: larger\">" + details + "</div><br>"; |
58342 | 72 |
} |
73 |
} |
|
74 |