Thu, 18 Apr 2013 20:00:14 -0700
8012656: cache frequently used name strings for DocImpl classes
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1359 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javadoc; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | |
duke@1 | 30 | /** |
duke@1 | 31 | * Represents a documentation tag, e.g. @since, @author, @version. |
duke@1 | 32 | * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since") |
duke@1 | 33 | * and tag text (e.g. "1.2"). TagImpls with structure or which require |
duke@1 | 34 | * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl, |
duke@1 | 35 | * and ThrowsTagImpl |
duke@1 | 36 | * |
jjg@1359 | 37 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 38 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 39 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 40 | * deletion without notice.</b> |
jjg@1359 | 41 | * |
duke@1 | 42 | * @author Robert Field |
duke@1 | 43 | * @author Atul M Dambalkar |
duke@1 | 44 | * @author Neal M Gafter |
duke@1 | 45 | * @see SeeTagImpl |
duke@1 | 46 | * @see ParamTagImpl |
duke@1 | 47 | * @see ThrowsTagImpl |
duke@1 | 48 | * @see Doc#tags() |
duke@1 | 49 | * |
duke@1 | 50 | */ |
duke@1 | 51 | class TagImpl implements Tag { |
duke@1 | 52 | |
duke@1 | 53 | protected final String text; |
duke@1 | 54 | protected final String name; |
duke@1 | 55 | protected final DocImpl holder; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * Cached first sentence. |
duke@1 | 59 | */ |
duke@1 | 60 | private Tag[] firstSentence; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Cached inline tags. |
duke@1 | 64 | */ |
duke@1 | 65 | private Tag[] inlineTags; |
duke@1 | 66 | |
duke@1 | 67 | /** |
duke@1 | 68 | * Constructor |
duke@1 | 69 | */ |
duke@1 | 70 | TagImpl(DocImpl holder, String name, String text) { |
duke@1 | 71 | this.holder = holder; |
duke@1 | 72 | this.name = name; |
duke@1 | 73 | this.text = text; |
duke@1 | 74 | } |
duke@1 | 75 | |
duke@1 | 76 | /** |
duke@1 | 77 | * Return the name of this tag. |
duke@1 | 78 | */ |
duke@1 | 79 | public String name() { |
duke@1 | 80 | return name; |
duke@1 | 81 | } |
duke@1 | 82 | |
duke@1 | 83 | /** |
duke@1 | 84 | * Return the containing {@link Doc} of this Tag element. |
duke@1 | 85 | */ |
duke@1 | 86 | public Doc holder() { |
duke@1 | 87 | return holder; |
duke@1 | 88 | } |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Return the kind of this tag. |
duke@1 | 92 | */ |
duke@1 | 93 | public String kind() { |
duke@1 | 94 | return name; |
duke@1 | 95 | } |
duke@1 | 96 | |
duke@1 | 97 | /** |
duke@1 | 98 | * Return the text of this tag, that is, portion beyond tag name. |
duke@1 | 99 | */ |
duke@1 | 100 | public String text() { |
duke@1 | 101 | return text; |
duke@1 | 102 | } |
duke@1 | 103 | |
duke@1 | 104 | DocEnv docenv() { |
duke@1 | 105 | return holder.env; |
duke@1 | 106 | } |
duke@1 | 107 | |
duke@1 | 108 | /** |
duke@1 | 109 | * for use by subclasses which have two part tag text. |
duke@1 | 110 | */ |
duke@1 | 111 | String[] divideAtWhite() { |
duke@1 | 112 | String[] sa = new String[2]; |
duke@1 | 113 | int len = text.length(); |
duke@1 | 114 | // if no white space found |
duke@1 | 115 | sa[0] = text; |
duke@1 | 116 | sa[1] = ""; |
duke@1 | 117 | for (int inx = 0; inx < len; ++inx) { |
duke@1 | 118 | char ch = text.charAt(inx); |
duke@1 | 119 | if (Character.isWhitespace(ch)) { |
duke@1 | 120 | sa[0] = text.substring(0, inx); |
duke@1 | 121 | for (; inx < len; ++inx) { |
duke@1 | 122 | ch = text.charAt(inx); |
duke@1 | 123 | if (!Character.isWhitespace(ch)) { |
duke@1 | 124 | sa[1] = text.substring(inx, len); |
duke@1 | 125 | break; |
duke@1 | 126 | } |
duke@1 | 127 | } |
duke@1 | 128 | break; |
duke@1 | 129 | } |
duke@1 | 130 | } |
duke@1 | 131 | return sa; |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /** |
duke@1 | 135 | * convert this object to a string. |
duke@1 | 136 | */ |
duke@1 | 137 | public String toString() { |
duke@1 | 138 | return name + ":" + text; |
duke@1 | 139 | } |
duke@1 | 140 | |
duke@1 | 141 | /** |
duke@1 | 142 | * For documentation comment with embedded @link tags, return the array of |
duke@1 | 143 | * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s). |
duke@1 | 144 | * Within a comment string "This is an example of inline tags for a |
duke@1 | 145 | * documentation comment {@link Doc {@link Doc commentlabel}}", |
duke@1 | 146 | * where inside the inner braces, the first "Doc" carries exctly the same |
duke@1 | 147 | * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html |
duke@1 | 148 | * Link, will return an array of TagImpl(s) with first element as TagImpl with |
duke@1 | 149 | * comment text "This is an example of inline tags for a documentation |
duke@1 | 150 | * comment" and second element as SeeTagImpl with referenced class as "Doc" |
duke@1 | 151 | * and the label for the Html Link as "commentlabel". |
duke@1 | 152 | * |
duke@1 | 153 | * @return TagImpl[] Array of tags with inline SeeTagImpls. |
duke@1 | 154 | * @see ParamTagImpl |
duke@1 | 155 | * @see ThrowsTagImpl |
duke@1 | 156 | */ |
duke@1 | 157 | public Tag[] inlineTags() { |
duke@1 | 158 | if (inlineTags == null) { |
duke@1 | 159 | inlineTags = Comment.getInlineTags(holder, text); |
duke@1 | 160 | } |
duke@1 | 161 | return inlineTags; |
duke@1 | 162 | } |
duke@1 | 163 | |
duke@1 | 164 | /** |
duke@1 | 165 | * Return array of tags for the first sentence in the doc comment text. |
duke@1 | 166 | */ |
duke@1 | 167 | public Tag[] firstSentenceTags() { |
duke@1 | 168 | if (firstSentence == null) { |
duke@1 | 169 | //Parse all sentences first to avoid duplicate warnings. |
duke@1 | 170 | inlineTags(); |
duke@1 | 171 | try { |
duke@1 | 172 | docenv().setSilent(true); |
duke@1 | 173 | firstSentence = Comment.firstSentenceTags(holder, text); |
duke@1 | 174 | } finally { |
duke@1 | 175 | docenv().setSilent(false); |
duke@1 | 176 | } |
duke@1 | 177 | } |
duke@1 | 178 | return firstSentence; |
duke@1 | 179 | } |
duke@1 | 180 | |
duke@1 | 181 | /** |
duke@1 | 182 | * Return the doc item to which this tag is attached. |
duke@1 | 183 | * @return the doc item to which this tag is attached. |
duke@1 | 184 | */ |
duke@1 | 185 | public SourcePosition position() { |
duke@1 | 186 | return holder.position(); |
duke@1 | 187 | } |
duke@1 | 188 | } |