1 /* 2 * Copyright (c) 2003, 2017, 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 package jdk.javadoc.internal.doclets.toolkit.taglets; 26 27 import java.util.Collections; 28 import java.util.List; 29 30 import javax.lang.model.element.Element; 31 32 import com.sun.source.doctree.DocTree; 33 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 34 import jdk.javadoc.internal.doclets.toolkit.Content; 35 import jdk.javadoc.internal.doclets.toolkit.util.Utils; 36 37 import static jdk.javadoc.doclet.Taglet.Location.*; 38 39 /** 40 * A taglet wrapper, allows the public taglet {@link jdk.javadoc.doclet.Taglet} 41 * wrapped into an internal Taglet representation. 42 * 43 * <p><b>This is NOT part of any supported API. 44 * If you write code that depends on this, you do so at your own risk. 45 * This code and its internal interfaces are subject to change or 46 * deletion without notice.</b> 47 * 48 * @author Jamie Ho 49 */ 50 public class UserTaglet implements Taglet { 51 52 final private jdk.javadoc.doclet.Taglet userTaglet; 53 UserTaglet(jdk.javadoc.doclet.Taglet t)54 public UserTaglet(jdk.javadoc.doclet.Taglet t) { 55 userTaglet = t; 56 } 57 58 /** 59 * {@inheritDoc} 60 */ inField()61 public boolean inField() { 62 return userTaglet.isInlineTag() 63 || userTaglet.getAllowedLocations().contains(FIELD); 64 } 65 66 /** 67 * {@inheritDoc} 68 */ inConstructor()69 public boolean inConstructor() { 70 return userTaglet.isInlineTag() 71 || userTaglet.getAllowedLocations().contains(CONSTRUCTOR); 72 } 73 74 /** 75 * {@inheritDoc} 76 */ inMethod()77 public boolean inMethod() { 78 return userTaglet.isInlineTag() 79 || userTaglet.getAllowedLocations().contains(METHOD); 80 } 81 82 /** 83 * {@inheritDoc} 84 */ inOverview()85 public boolean inOverview() { 86 return userTaglet.isInlineTag() 87 || userTaglet.getAllowedLocations().contains(OVERVIEW); 88 } 89 90 /** 91 * {@inheritDoc} 92 */ inModule()93 public boolean inModule() { 94 return userTaglet.isInlineTag() 95 || userTaglet.getAllowedLocations().contains(MODULE); 96 } 97 98 /** 99 * {@inheritDoc} 100 */ inPackage()101 public boolean inPackage() { 102 return userTaglet.isInlineTag() 103 || userTaglet.getAllowedLocations().contains(PACKAGE); 104 } 105 106 /** 107 * {@inheritDoc} 108 */ inType()109 public boolean inType() { 110 return userTaglet.isInlineTag() 111 || userTaglet.getAllowedLocations().contains(TYPE); 112 } 113 114 /** 115 * Return true if this <code>Taglet</code> is an inline tag. 116 * 117 * @return true if this <code>Taglet</code> is an inline tag and false otherwise. 118 */ isInlineTag()119 public boolean isInlineTag() { 120 return userTaglet.isInlineTag(); 121 } 122 123 /** 124 * {@inheritDoc} 125 */ getName()126 public String getName() { 127 return userTaglet.getName(); 128 } 129 130 /** 131 * {@inheritDoc} 132 */ getTagletOutput(Element element, DocTree tag, TagletWriter writer)133 public Content getTagletOutput(Element element, DocTree tag, TagletWriter writer){ 134 Content output = writer.getOutputInstance(); 135 output.addContent(new RawHtml(userTaglet.toString(Collections.singletonList(tag), element))); 136 return output; 137 } 138 139 /** 140 * {@inheritDoc} 141 */ getTagletOutput(Element holder, TagletWriter writer)142 public Content getTagletOutput(Element holder, TagletWriter writer) { 143 Content output = writer.getOutputInstance(); 144 Utils utils = writer.configuration().utils; 145 List<? extends DocTree> tags = utils.getBlockTags(holder, getName()); 146 if (!tags.isEmpty()) { 147 String tagString = userTaglet.toString(tags, holder); 148 if (tagString != null) { 149 output.addContent(new RawHtml(tagString)); 150 } 151 } 152 return output; 153 } 154 } 155