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