Sun, 16 Dec 2012 11:09:36 +0100
8005098: Provide isSynthesized() information on Attribute.Compound
Reviewed-by: jjg
jjg@1455 | 1 | /* |
jjg@1455 | 2 | * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
jjg@1455 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1455 | 4 | * |
jjg@1455 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1455 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1455 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@1455 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@1455 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@1455 | 10 | * |
jjg@1455 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1455 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1455 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1455 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1455 | 15 | * accompanied this code). |
jjg@1455 | 16 | * |
jjg@1455 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@1455 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1455 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1455 | 20 | * |
jjg@1455 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1455 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@1455 | 23 | * questions. |
jjg@1455 | 24 | */ |
jjg@1455 | 25 | |
jjg@1455 | 26 | package com.sun.tools.doclint; |
jjg@1455 | 27 | |
jjg@1455 | 28 | import java.util.Set; |
jjg@1455 | 29 | import java.util.Collections; |
jjg@1455 | 30 | import java.util.EnumMap; |
jjg@1455 | 31 | import java.util.EnumSet; |
jjg@1455 | 32 | import java.util.HashMap; |
jjg@1455 | 33 | import java.util.Map; |
jjg@1455 | 34 | |
jjg@1455 | 35 | import javax.lang.model.element.Name; |
jjg@1455 | 36 | |
jjg@1455 | 37 | import static com.sun.tools.doclint.HtmlTag.Attr.*; |
jjg@1455 | 38 | |
jjg@1455 | 39 | /** |
jjg@1455 | 40 | * Enum representing HTML tags. |
jjg@1455 | 41 | * |
jjg@1455 | 42 | * The intent of this class is to embody the semantics of W3C HTML 4.01 |
jjg@1455 | 43 | * to the extent supported/used by javadoc. |
jjg@1455 | 44 | * |
jjg@1455 | 45 | * This is derivative of com.sun.tools.doclets.formats.html.markup.HtmlTag. |
jjg@1455 | 46 | * Eventually, these two should be merged back together, and possibly made |
jjg@1455 | 47 | * public. |
jjg@1455 | 48 | * |
jjg@1455 | 49 | * @see <a href="http://www.w3.org/TR/REC-html40/">HTML 4.01 Specification</a> |
jjg@1455 | 50 | * @author Bhavesh Patel |
jjg@1455 | 51 | * @author Jonathan Gibbons (revised) |
jjg@1455 | 52 | */ |
jjg@1455 | 53 | public enum HtmlTag { |
jjg@1455 | 54 | A(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 55 | attrs(AttrKind.OK, HREF, TARGET, NAME)), |
jjg@1455 | 56 | |
jjg@1455 | 57 | B(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 58 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 59 | |
jjg@1455 | 60 | BLOCKQUOTE, |
jjg@1455 | 61 | |
jjg@1455 | 62 | BODY(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 63 | |
jjg@1455 | 64 | BR(BlockType.INLINE, EndKind.NONE, |
jjg@1455 | 65 | attrs(AttrKind.USE_CSS, CLEAR)), |
jjg@1455 | 66 | |
jjg@1455 | 67 | CAPTION(EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 68 | |
jjg@1455 | 69 | CENTER, |
jjg@1455 | 70 | |
jjg@1455 | 71 | CITE(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 72 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 73 | |
jjg@1455 | 74 | CODE(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 75 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 76 | |
jjg@1455 | 77 | DD(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 78 | EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 79 | |
jjg@1455 | 80 | DIV, |
jjg@1455 | 81 | |
jjg@1455 | 82 | DL(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 83 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_TEXT), |
jjg@1455 | 84 | attrs(AttrKind.USE_CSS, COMPACT)), |
jjg@1455 | 85 | |
jjg@1455 | 86 | DT(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 87 | EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 88 | |
jjg@1455 | 89 | EM(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 90 | EnumSet.of(Flag.NO_NEST)), |
jjg@1455 | 91 | |
jjg@1455 | 92 | FONT(BlockType.INLINE, EndKind.REQUIRED, // tag itself is deprecated |
jjg@1455 | 93 | EnumSet.of(Flag.EXPECT_CONTENT), |
jjg@1455 | 94 | attrs(AttrKind.USE_CSS, SIZE, COLOR, FACE)), |
jjg@1455 | 95 | |
jjg@1455 | 96 | FRAME(BlockType.OTHER, EndKind.NONE), |
jjg@1455 | 97 | |
jjg@1455 | 98 | FRAMESET(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 99 | |
jjg@1455 | 100 | H1, |
jjg@1455 | 101 | H2, |
jjg@1455 | 102 | H3, |
jjg@1455 | 103 | H4, |
jjg@1455 | 104 | H5, |
jjg@1455 | 105 | H6, |
jjg@1455 | 106 | |
jjg@1455 | 107 | HEAD(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 108 | |
jjg@1455 | 109 | HR(BlockType.BLOCK, EndKind.NONE), |
jjg@1455 | 110 | |
jjg@1455 | 111 | HTML(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 112 | |
jjg@1455 | 113 | I(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 114 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 115 | |
jjg@1455 | 116 | IMG(BlockType.INLINE, EndKind.NONE, |
jjg@1455 | 117 | attrs(AttrKind.OK, SRC, ALT, HEIGHT, WIDTH), |
jjg@1455 | 118 | attrs(AttrKind.OBSOLETE, NAME), |
jjg@1455 | 119 | attrs(AttrKind.USE_CSS, ALIGN, HSPACE, VSPACE, BORDER)), |
jjg@1455 | 120 | |
jjg@1455 | 121 | LI(BlockType.BLOCK, EndKind.OPTIONAL), |
jjg@1455 | 122 | |
jjg@1455 | 123 | LINK(BlockType.OTHER, EndKind.NONE), |
jjg@1455 | 124 | |
jjg@1455 | 125 | MENU, |
jjg@1455 | 126 | |
jjg@1455 | 127 | META(BlockType.OTHER, EndKind.NONE), |
jjg@1455 | 128 | |
jjg@1455 | 129 | NOFRAMES(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 130 | |
jjg@1455 | 131 | NOSCRIPT(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 132 | |
jjg@1455 | 133 | OL(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 134 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_TEXT), |
jjg@1455 | 135 | attrs(AttrKind.USE_CSS, START, TYPE)), |
jjg@1455 | 136 | |
jjg@1455 | 137 | P(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 138 | EnumSet.of(Flag.EXPECT_CONTENT), |
jjg@1455 | 139 | attrs(AttrKind.USE_CSS, ALIGN)), |
jjg@1455 | 140 | |
jjg@1455 | 141 | PRE(EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 142 | |
jjg@1455 | 143 | SCRIPT(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 144 | |
jjg@1455 | 145 | SMALL(BlockType.INLINE, EndKind.REQUIRED), |
jjg@1455 | 146 | |
jjg@1455 | 147 | SPAN(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 148 | EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 149 | |
jjg@1455 | 150 | STRONG(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 151 | EnumSet.of(Flag.EXPECT_CONTENT)), |
jjg@1455 | 152 | |
jjg@1455 | 153 | SUB(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 154 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 155 | |
jjg@1455 | 156 | SUP(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 157 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 158 | |
jjg@1455 | 159 | TABLE(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 160 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_TEXT), |
jjg@1455 | 161 | attrs(AttrKind.OK, SUMMARY, Attr.FRAME, RULES, BORDER, |
jjg@1455 | 162 | CELLPADDING, CELLSPACING), |
jjg@1455 | 163 | attrs(AttrKind.USE_CSS, ALIGN, WIDTH, BGCOLOR)), |
jjg@1455 | 164 | |
jjg@1455 | 165 | TBODY(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 166 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_TEXT), |
jjg@1455 | 167 | attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)), |
jjg@1455 | 168 | |
jjg@1455 | 169 | TD(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 170 | attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS, |
jjg@1455 | 171 | ALIGN, CHAR, CHAROFF, VALIGN), |
jjg@1455 | 172 | attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), |
jjg@1455 | 173 | |
jjg@1455 | 174 | TFOOT(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 175 | attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)), |
jjg@1455 | 176 | |
jjg@1455 | 177 | TH(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 178 | attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS, |
jjg@1455 | 179 | ALIGN, CHAR, CHAROFF, VALIGN), |
jjg@1455 | 180 | attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), |
jjg@1455 | 181 | |
jjg@1455 | 182 | THEAD(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 183 | attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)), |
jjg@1455 | 184 | |
jjg@1455 | 185 | TITLE(BlockType.OTHER, EndKind.REQUIRED), |
jjg@1455 | 186 | |
jjg@1455 | 187 | TR(BlockType.BLOCK, EndKind.OPTIONAL, |
jjg@1455 | 188 | EnumSet.of(Flag.NO_TEXT), |
jjg@1455 | 189 | attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN), |
jjg@1455 | 190 | attrs(AttrKind.USE_CSS, BGCOLOR)), |
jjg@1455 | 191 | |
jjg@1455 | 192 | TT(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 193 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 194 | |
jjg@1455 | 195 | U(BlockType.INLINE, EndKind.REQUIRED, |
jjg@1455 | 196 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
jjg@1455 | 197 | |
jjg@1455 | 198 | UL(BlockType.BLOCK, EndKind.REQUIRED, |
jjg@1455 | 199 | EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_TEXT), |
jjg@1455 | 200 | attrs(AttrKind.USE_CSS, COMPACT, TYPE)), |
jjg@1455 | 201 | |
jjg@1455 | 202 | VAR(BlockType.INLINE, EndKind.REQUIRED); |
jjg@1455 | 203 | |
jjg@1455 | 204 | /** |
jjg@1455 | 205 | * Enum representing the type of HTML element. |
jjg@1455 | 206 | */ |
jjg@1455 | 207 | public static enum BlockType { |
jjg@1455 | 208 | BLOCK, |
jjg@1455 | 209 | INLINE, |
jjg@1455 | 210 | OTHER; |
jjg@1455 | 211 | } |
jjg@1455 | 212 | |
jjg@1455 | 213 | /** |
jjg@1455 | 214 | * Enum representing HTML end tag requirement. |
jjg@1455 | 215 | */ |
jjg@1455 | 216 | public static enum EndKind { |
jjg@1455 | 217 | NONE, |
jjg@1455 | 218 | OPTIONAL, |
jjg@1455 | 219 | REQUIRED; |
jjg@1455 | 220 | } |
jjg@1455 | 221 | |
jjg@1455 | 222 | public static enum Flag { |
jjg@1455 | 223 | EXPECT_CONTENT, |
jjg@1455 | 224 | NO_NEST, |
jjg@1455 | 225 | NO_TEXT |
jjg@1455 | 226 | } |
jjg@1455 | 227 | |
jjg@1455 | 228 | public static enum Attr { |
jjg@1455 | 229 | ABBR, |
jjg@1455 | 230 | ALIGN, |
jjg@1455 | 231 | ALT, |
jjg@1455 | 232 | AXIS, |
jjg@1455 | 233 | BGCOLOR, |
jjg@1455 | 234 | BORDER, |
jjg@1455 | 235 | CELLSPACING, |
jjg@1455 | 236 | CELLPADDING, |
jjg@1455 | 237 | CHAR, |
jjg@1455 | 238 | CHAROFF, |
jjg@1455 | 239 | CLEAR, |
jjg@1455 | 240 | CLASS, |
jjg@1455 | 241 | COLOR, |
jjg@1455 | 242 | COLSPAN, |
jjg@1455 | 243 | COMPACT, |
jjg@1455 | 244 | FACE, |
jjg@1455 | 245 | FRAME, |
jjg@1455 | 246 | HEADERS, |
jjg@1455 | 247 | HEIGHT, |
jjg@1455 | 248 | HREF, |
jjg@1455 | 249 | HSPACE, |
jjg@1455 | 250 | ID, |
jjg@1455 | 251 | NAME, |
jjg@1455 | 252 | NOWRAP, |
jjg@1455 | 253 | REVERSED, |
jjg@1455 | 254 | ROWSPAN, |
jjg@1455 | 255 | RULES, |
jjg@1455 | 256 | SCOPE, |
jjg@1455 | 257 | SIZE, |
jjg@1455 | 258 | SPACE, |
jjg@1455 | 259 | SRC, |
jjg@1455 | 260 | START, |
jjg@1455 | 261 | STYLE, |
jjg@1455 | 262 | SUMMARY, |
jjg@1455 | 263 | TARGET, |
jjg@1455 | 264 | TYPE, |
jjg@1455 | 265 | VALIGN, |
jjg@1455 | 266 | VSPACE, |
jjg@1455 | 267 | WIDTH; |
jjg@1455 | 268 | |
jjg@1455 | 269 | public String getText() { |
jjg@1455 | 270 | return name().toLowerCase(); |
jjg@1455 | 271 | } |
jjg@1455 | 272 | |
jjg@1455 | 273 | static final Map<String,Attr> index = new HashMap<String,Attr>(); |
jjg@1455 | 274 | static { |
jjg@1455 | 275 | for (Attr t: values()) { |
jjg@1455 | 276 | index.put(t.name().toLowerCase(), t); |
jjg@1455 | 277 | } |
jjg@1455 | 278 | } |
jjg@1455 | 279 | } |
jjg@1455 | 280 | |
jjg@1455 | 281 | public static enum AttrKind { |
jjg@1455 | 282 | INVALID, |
jjg@1455 | 283 | OBSOLETE, |
jjg@1455 | 284 | USE_CSS, |
jjg@1455 | 285 | OK |
jjg@1455 | 286 | } |
jjg@1455 | 287 | |
jjg@1455 | 288 | // This class exists to avoid warnings from using parameterized vararg type |
jjg@1455 | 289 | // Map<Attr,AttrKind> in signature of HtmlTag constructor. |
jjg@1455 | 290 | private static class AttrMap extends EnumMap<Attr,AttrKind> { |
jjg@1455 | 291 | private static final long serialVersionUID = 0; |
jjg@1455 | 292 | AttrMap() { |
jjg@1455 | 293 | super(Attr.class); |
jjg@1455 | 294 | } |
jjg@1455 | 295 | } |
jjg@1455 | 296 | |
jjg@1455 | 297 | |
jjg@1455 | 298 | public final BlockType blockType; |
jjg@1455 | 299 | public final EndKind endKind; |
jjg@1455 | 300 | public final Set<Flag> flags; |
jjg@1455 | 301 | private final Map<Attr,AttrKind> attrs; |
jjg@1455 | 302 | |
jjg@1455 | 303 | |
jjg@1455 | 304 | HtmlTag() { |
jjg@1455 | 305 | this(BlockType.BLOCK, EndKind.REQUIRED); |
jjg@1455 | 306 | } |
jjg@1455 | 307 | |
jjg@1455 | 308 | HtmlTag(Set<Flag> flags) { |
jjg@1455 | 309 | this(BlockType.BLOCK, EndKind.REQUIRED, flags); |
jjg@1455 | 310 | } |
jjg@1455 | 311 | |
jjg@1455 | 312 | HtmlTag(BlockType blockType, EndKind endKind, AttrMap... attrMaps) { |
jjg@1455 | 313 | this(blockType, endKind, Collections.<Flag>emptySet(), attrMaps); |
jjg@1455 | 314 | } |
jjg@1455 | 315 | |
jjg@1455 | 316 | HtmlTag(BlockType blockType, EndKind endKind, Set<Flag> flags, AttrMap... attrMaps) { |
jjg@1455 | 317 | this.blockType = blockType; |
jjg@1455 | 318 | this.endKind = endKind;this.flags = flags; |
jjg@1455 | 319 | this.attrs = new EnumMap<Attr,AttrKind>(Attr.class); |
jjg@1455 | 320 | for (Map<Attr,AttrKind> m: attrMaps) |
jjg@1455 | 321 | this.attrs.putAll(m); |
jjg@1455 | 322 | attrs.put(Attr.CLASS, AttrKind.OK); |
jjg@1455 | 323 | attrs.put(Attr.ID, AttrKind.OK); |
jjg@1455 | 324 | attrs.put(Attr.STYLE, AttrKind.OK); |
jjg@1455 | 325 | } |
jjg@1455 | 326 | |
jjg@1455 | 327 | public String getText() { |
jjg@1455 | 328 | return name().toLowerCase(); |
jjg@1455 | 329 | } |
jjg@1455 | 330 | |
jjg@1455 | 331 | public Attr getAttr(Name attrName) { |
jjg@1455 | 332 | return Attr.index.get(attrName.toString().toLowerCase()); |
jjg@1455 | 333 | } |
jjg@1455 | 334 | |
jjg@1455 | 335 | public AttrKind getAttrKind(Name attrName) { |
jjg@1455 | 336 | AttrKind k = attrs.get(getAttr(attrName)); // null-safe |
jjg@1455 | 337 | return (k == null) ? AttrKind.INVALID : k; |
jjg@1455 | 338 | } |
jjg@1455 | 339 | |
jjg@1455 | 340 | private static AttrMap attrs(AttrKind k, Attr... attrs) { |
jjg@1455 | 341 | AttrMap map = new AttrMap(); |
jjg@1455 | 342 | for (Attr a: attrs) map.put(a, k); |
jjg@1455 | 343 | return map; |
jjg@1455 | 344 | } |
jjg@1455 | 345 | |
jjg@1455 | 346 | private static final Map<String,HtmlTag> index = new HashMap<String,HtmlTag>(); |
jjg@1455 | 347 | static { |
jjg@1455 | 348 | for (HtmlTag t: values()) { |
jjg@1455 | 349 | index.put(t.name().toLowerCase(), t); |
jjg@1455 | 350 | } |
jjg@1455 | 351 | } |
jjg@1455 | 352 | |
jjg@1455 | 353 | static HtmlTag get(Name tagName) { |
jjg@1455 | 354 | return index.get(tagName.toString().toLowerCase()); |
jjg@1455 | 355 | } |
jjg@1455 | 356 | } |