Fri, 31 Aug 2012 10:37:46 +0100
7151010: Add compiler support for repeating annotations
Reviewed-by: jjg, mcimadamore
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 1997, 2004, 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 | * |
duke@1 | 37 | * @author Robert Field |
duke@1 | 38 | * @author Atul M Dambalkar |
duke@1 | 39 | * @author Neal M Gafter |
duke@1 | 40 | * @see SeeTagImpl |
duke@1 | 41 | * @see ParamTagImpl |
duke@1 | 42 | * @see ThrowsTagImpl |
duke@1 | 43 | * @see Doc#tags() |
duke@1 | 44 | * |
duke@1 | 45 | */ |
duke@1 | 46 | class TagImpl implements Tag { |
duke@1 | 47 | |
duke@1 | 48 | protected final String text; |
duke@1 | 49 | protected final String name; |
duke@1 | 50 | protected final DocImpl holder; |
duke@1 | 51 | |
duke@1 | 52 | /** |
duke@1 | 53 | * Cached first sentence. |
duke@1 | 54 | */ |
duke@1 | 55 | private Tag[] firstSentence; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * Cached inline tags. |
duke@1 | 59 | */ |
duke@1 | 60 | private Tag[] inlineTags; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Constructor |
duke@1 | 64 | */ |
duke@1 | 65 | TagImpl(DocImpl holder, String name, String text) { |
duke@1 | 66 | this.holder = holder; |
duke@1 | 67 | this.name = name; |
duke@1 | 68 | this.text = text; |
duke@1 | 69 | } |
duke@1 | 70 | |
duke@1 | 71 | /** |
duke@1 | 72 | * Return the name of this tag. |
duke@1 | 73 | */ |
duke@1 | 74 | public String name() { |
duke@1 | 75 | return name; |
duke@1 | 76 | } |
duke@1 | 77 | |
duke@1 | 78 | /** |
duke@1 | 79 | * Return the containing {@link Doc} of this Tag element. |
duke@1 | 80 | */ |
duke@1 | 81 | public Doc holder() { |
duke@1 | 82 | return holder; |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | /** |
duke@1 | 86 | * Return the kind of this tag. |
duke@1 | 87 | */ |
duke@1 | 88 | public String kind() { |
duke@1 | 89 | return name; |
duke@1 | 90 | } |
duke@1 | 91 | |
duke@1 | 92 | /** |
duke@1 | 93 | * Return the text of this tag, that is, portion beyond tag name. |
duke@1 | 94 | */ |
duke@1 | 95 | public String text() { |
duke@1 | 96 | return text; |
duke@1 | 97 | } |
duke@1 | 98 | |
duke@1 | 99 | DocEnv docenv() { |
duke@1 | 100 | return holder.env; |
duke@1 | 101 | } |
duke@1 | 102 | |
duke@1 | 103 | /** |
duke@1 | 104 | * for use by subclasses which have two part tag text. |
duke@1 | 105 | */ |
duke@1 | 106 | String[] divideAtWhite() { |
duke@1 | 107 | String[] sa = new String[2]; |
duke@1 | 108 | int len = text.length(); |
duke@1 | 109 | // if no white space found |
duke@1 | 110 | sa[0] = text; |
duke@1 | 111 | sa[1] = ""; |
duke@1 | 112 | for (int inx = 0; inx < len; ++inx) { |
duke@1 | 113 | char ch = text.charAt(inx); |
duke@1 | 114 | if (Character.isWhitespace(ch)) { |
duke@1 | 115 | sa[0] = text.substring(0, inx); |
duke@1 | 116 | for (; inx < len; ++inx) { |
duke@1 | 117 | ch = text.charAt(inx); |
duke@1 | 118 | if (!Character.isWhitespace(ch)) { |
duke@1 | 119 | sa[1] = text.substring(inx, len); |
duke@1 | 120 | break; |
duke@1 | 121 | } |
duke@1 | 122 | } |
duke@1 | 123 | break; |
duke@1 | 124 | } |
duke@1 | 125 | } |
duke@1 | 126 | return sa; |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | /** |
duke@1 | 130 | * convert this object to a string. |
duke@1 | 131 | */ |
duke@1 | 132 | public String toString() { |
duke@1 | 133 | return name + ":" + text; |
duke@1 | 134 | } |
duke@1 | 135 | |
duke@1 | 136 | /** |
duke@1 | 137 | * For documentation comment with embedded @link tags, return the array of |
duke@1 | 138 | * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s). |
duke@1 | 139 | * Within a comment string "This is an example of inline tags for a |
duke@1 | 140 | * documentation comment {@link Doc {@link Doc commentlabel}}", |
duke@1 | 141 | * where inside the inner braces, the first "Doc" carries exctly the same |
duke@1 | 142 | * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html |
duke@1 | 143 | * Link, will return an array of TagImpl(s) with first element as TagImpl with |
duke@1 | 144 | * comment text "This is an example of inline tags for a documentation |
duke@1 | 145 | * comment" and second element as SeeTagImpl with referenced class as "Doc" |
duke@1 | 146 | * and the label for the Html Link as "commentlabel". |
duke@1 | 147 | * |
duke@1 | 148 | * @return TagImpl[] Array of tags with inline SeeTagImpls. |
duke@1 | 149 | * @see ParamTagImpl |
duke@1 | 150 | * @see ThrowsTagImpl |
duke@1 | 151 | */ |
duke@1 | 152 | public Tag[] inlineTags() { |
duke@1 | 153 | if (inlineTags == null) { |
duke@1 | 154 | inlineTags = Comment.getInlineTags(holder, text); |
duke@1 | 155 | } |
duke@1 | 156 | return inlineTags; |
duke@1 | 157 | } |
duke@1 | 158 | |
duke@1 | 159 | /** |
duke@1 | 160 | * Return array of tags for the first sentence in the doc comment text. |
duke@1 | 161 | */ |
duke@1 | 162 | public Tag[] firstSentenceTags() { |
duke@1 | 163 | if (firstSentence == null) { |
duke@1 | 164 | //Parse all sentences first to avoid duplicate warnings. |
duke@1 | 165 | inlineTags(); |
duke@1 | 166 | try { |
duke@1 | 167 | docenv().setSilent(true); |
duke@1 | 168 | firstSentence = Comment.firstSentenceTags(holder, text); |
duke@1 | 169 | } finally { |
duke@1 | 170 | docenv().setSilent(false); |
duke@1 | 171 | } |
duke@1 | 172 | } |
duke@1 | 173 | return firstSentence; |
duke@1 | 174 | } |
duke@1 | 175 | |
duke@1 | 176 | /** |
duke@1 | 177 | * Return the doc item to which this tag is attached. |
duke@1 | 178 | * @return the doc item to which this tag is attached. |
duke@1 | 179 | */ |
duke@1 | 180 | public SourcePosition position() { |
duke@1 | 181 | return holder.position(); |
duke@1 | 182 | } |
duke@1 | 183 | } |