test/jdk/javadoc/tool/api/basic/taglets/UnderlineTaglet.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
@@ -34,17 +34,24 @@
* You acknowledge that Software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
-import com.sun.tools.doclets.Taglet;
-import com.sun.javadoc.*;
-import java.util.Map;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.TextTree;
+import com.sun.source.doctree.UnknownBlockTagTree;
+import com.sun.source.doctree.UnknownInlineTagTree;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import jdk.javadoc.doclet.taglet.Taglet;
+
/**
* A sample Inline Taglet representing {@underline ...}. This tag can
- * be used in any kind of {@link com.sun.javadoc.Doc}.
+ * be used in any kind of {@link javax.lang.model.Element}.
* The text is underlined. For example,
* "@underline UNDERLINE ME" would be shown as: <u>UNDERLINE ME</u>.
*
* @author Jamie Ho
* @since 1.4
@@ -59,94 +66,72 @@
*/
public String getName() {
return NAME;
}
- /**
- * @return true since this tag can be used in a field
- * doc comment
- */
- public boolean inField() {
- return true;
- }
+ private final EnumSet<Location> allowedSet = EnumSet.allOf(Location.class);
- /**
- * @return true since this tag can be used in a constructor
- * doc comment
- */
- public boolean inConstructor() {
- return true;
+ @Override
+ public Set<Taglet.Location> getAllowedLocations() {
+ return allowedSet;
}
/**
- * @return true since this tag can be used in a method
- * doc comment
- */
- public boolean inMethod() {
- return true;
- }
-
- /**
- * @return true since this tag can be used in an overview
- * doc comment
- */
- public boolean inOverview() {
- return true;
- }
-
- /**
- * @return true since this tag can be used in a package
- * doc comment
- */
- public boolean inPackage() {
- return true;
- }
-
- /**
- * @return true since this
- */
- public boolean inType() {
- return true;
- }
-
- /**
* Will return true since this is an inline tag.
* @return true since this is an inline tag.
*/
public boolean isInlineTag() {
return true;
}
/**
- * Register this Taglet.
- * @param tagletMap the map to register this tag to.
- */
- public static void register(Map tagletMap) {
- UnderlineTaglet tag = new UnderlineTaglet();
- Taglet t = (Taglet) tagletMap.get(tag.getName());
- if (t != null) {
- tagletMap.remove(tag.getName());
- }
- tagletMap.put(tag.getName(), tag);
- }
-
- /**
* Given the <code>Tag</code> representation of this custom
* tag, return its string representation.
* @param tag he <code>Tag</code> representation of this custom tag.
*/
- public String toString(Tag tag) {
- return "<u>" + tag.text() + "</u>";
+ public String toString(DocTree tag) {
+ return "<u>" + getText(tag) + "</u>";
}
/**
* This method should not be called since arrays of inline tags do not
* exist. Method {@link #tostring(Tag)} should be used to convert this
* inline tag to a string.
* @param tags the array of <code>Tag</code>s representing of this custom tag.
*/
- public String toString(Tag[] tags) {
+ public String toString(List<? extends DocTree> tags) {
return null;
}
+
+ static String getText(DocTree dt) {
+ return new SimpleDocTreeVisitor<String, Void>() {
+ @Override
+ public String visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
+ for (DocTree dt : node.getContent()) {
+ return dt.accept(this, null);
+ }
+ return "";
+ }
+
+ @Override
+ public String visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
+ for (DocTree dt : node.getContent()) {
+ return dt.accept(this, null);
+ }
+ return "";
+ }
+
+ @Override
+ public String visitText(TextTree node, Void p) {
+ return node.getBody();
+ }
+
+ @Override
+ protected String defaultAction(DocTree node, Void p) {
+ return "";
+ }
+
+ }.visit(dt, null);
+ }
}