src/share/classes/com/sun/tools/doclint/HtmlTag.java

Fri, 12 Jul 2013 13:11:12 -0700

author
jjg
date
Fri, 12 Jul 2013 13:11:12 -0700
changeset 1895
37031963493e
parent 1793
391f97e270c2
child 1964
79e341614c50
permissions
-rw-r--r--

8020278: NPE in javadoc
Reviewed-by: mcimadamore, vromero

jjg@1455 1 /*
jjg@1506 2 * Copyright (c) 2010, 2013, 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@1507 60 BIG(BlockType.INLINE, EndKind.REQUIRED,
jjg@1507 61 EnumSet.of(Flag.EXPECT_CONTENT)),
jjg@1507 62
jjg@1507 63 BLOCKQUOTE(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 64 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)),
jjg@1455 65
jjg@1455 66 BODY(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 67
jjg@1455 68 BR(BlockType.INLINE, EndKind.NONE,
jjg@1455 69 attrs(AttrKind.USE_CSS, CLEAR)),
jjg@1455 70
jjg@1507 71 CAPTION(BlockType.TABLE_ITEM, EndKind.REQUIRED,
jjg@1507 72 EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)),
jjg@1455 73
jjg@1507 74 CENTER(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 75 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)),
jjg@1455 76
jjg@1455 77 CITE(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 78 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 79
jjg@1455 80 CODE(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 81 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 82
jjg@1507 83 DD(BlockType.LIST_ITEM, EndKind.OPTIONAL,
jjg@1507 84 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)),
jjg@1455 85
jjg@1507 86 DIV(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 87 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)),
jjg@1455 88
jjg@1455 89 DL(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 90 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1507 91 attrs(AttrKind.USE_CSS, COMPACT)) {
jjg@1507 92 @Override
jjg@1507 93 public boolean accepts(HtmlTag t) {
jjg@1507 94 return (t == DT) || (t == DD);
jjg@1507 95 }
jjg@1507 96 },
jjg@1455 97
jjg@1507 98 DT(BlockType.LIST_ITEM, EndKind.OPTIONAL,
jjg@1507 99 EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)),
jjg@1455 100
jjg@1455 101 EM(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 102 EnumSet.of(Flag.NO_NEST)),
jjg@1455 103
jjg@1455 104 FONT(BlockType.INLINE, EndKind.REQUIRED, // tag itself is deprecated
jjg@1455 105 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1455 106 attrs(AttrKind.USE_CSS, SIZE, COLOR, FACE)),
jjg@1455 107
jjg@1455 108 FRAME(BlockType.OTHER, EndKind.NONE),
jjg@1455 109
jjg@1455 110 FRAMESET(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 111
jjg@1507 112 H1(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1507 113 H2(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1507 114 H3(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1507 115 H4(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1507 116 H5(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1507 117 H6(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1455 118
jjg@1455 119 HEAD(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 120
jjg@1455 121 HR(BlockType.BLOCK, EndKind.NONE),
jjg@1455 122
jjg@1455 123 HTML(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 124
jjg@1455 125 I(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 126 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 127
jjg@1455 128 IMG(BlockType.INLINE, EndKind.NONE,
jjg@1455 129 attrs(AttrKind.OK, SRC, ALT, HEIGHT, WIDTH),
jjg@1455 130 attrs(AttrKind.OBSOLETE, NAME),
jjg@1455 131 attrs(AttrKind.USE_CSS, ALIGN, HSPACE, VSPACE, BORDER)),
jjg@1455 132
jjg@1507 133 LI(BlockType.LIST_ITEM, EndKind.OPTIONAL,
jjg@1793 134 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE),
jjg@1793 135 attrs(AttrKind.OK, VALUE)),
jjg@1455 136
jjg@1455 137 LINK(BlockType.OTHER, EndKind.NONE),
jjg@1455 138
jjg@1507 139 MENU(BlockType.BLOCK, EndKind.REQUIRED) {
jjg@1507 140 @Override
jjg@1507 141 public boolean accepts(HtmlTag t) {
jjg@1507 142 return (t == LI);
jjg@1507 143 }
jjg@1507 144 },
jjg@1455 145
jjg@1455 146 META(BlockType.OTHER, EndKind.NONE),
jjg@1455 147
jjg@1455 148 NOFRAMES(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 149
jjg@1507 150 NOSCRIPT(BlockType.BLOCK, EndKind.REQUIRED),
jjg@1455 151
jjg@1455 152 OL(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 153 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1507 154 attrs(AttrKind.USE_CSS, START, TYPE)){
jjg@1507 155 @Override
jjg@1507 156 public boolean accepts(HtmlTag t) {
jjg@1507 157 return (t == LI);
jjg@1507 158 }
jjg@1507 159 },
jjg@1455 160
jjg@1455 161 P(BlockType.BLOCK, EndKind.OPTIONAL,
jjg@1455 162 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1455 163 attrs(AttrKind.USE_CSS, ALIGN)),
jjg@1455 164
jjg@1507 165 PRE(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 166 EnumSet.of(Flag.EXPECT_CONTENT)) {
jjg@1507 167 @Override
jjg@1507 168 public boolean accepts(HtmlTag t) {
jjg@1507 169 switch (t) {
jjg@1507 170 case IMG: case BIG: case SMALL: case SUB: case SUP:
jjg@1507 171 return false;
jjg@1507 172 default:
jjg@1507 173 return (t.blockType == BlockType.INLINE);
jjg@1507 174 }
jjg@1507 175 }
jjg@1507 176 },
jjg@1455 177
jjg@1455 178 SCRIPT(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 179
jjg@1507 180 SMALL(BlockType.INLINE, EndKind.REQUIRED,
jjg@1507 181 EnumSet.of(Flag.EXPECT_CONTENT)),
jjg@1455 182
jjg@1455 183 SPAN(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 184 EnumSet.of(Flag.EXPECT_CONTENT)),
jjg@1455 185
jjg@1455 186 STRONG(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 187 EnumSet.of(Flag.EXPECT_CONTENT)),
jjg@1455 188
jjg@1455 189 SUB(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 190 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 191
jjg@1455 192 SUP(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 193 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 194
jjg@1455 195 TABLE(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 196 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1455 197 attrs(AttrKind.OK, SUMMARY, Attr.FRAME, RULES, BORDER,
jjg@1455 198 CELLPADDING, CELLSPACING),
jjg@1507 199 attrs(AttrKind.USE_CSS, ALIGN, WIDTH, BGCOLOR)) {
jjg@1507 200 @Override
jjg@1507 201 public boolean accepts(HtmlTag t) {
jjg@1507 202 switch (t) {
jjg@1507 203 case CAPTION:
jjg@1507 204 case THEAD: case TBODY: case TFOOT:
jjg@1507 205 case TR: // HTML 3.2
jjg@1507 206 return true;
jjg@1507 207 default:
jjg@1507 208 return false;
jjg@1507 209 }
jjg@1507 210 }
jjg@1507 211 },
jjg@1455 212
jjg@1507 213 TBODY(BlockType.TABLE_ITEM, EndKind.REQUIRED,
jjg@1507 214 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1507 215 attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) {
jjg@1507 216 @Override
jjg@1507 217 public boolean accepts(HtmlTag t) {
jjg@1507 218 return (t == TR);
jjg@1507 219 }
jjg@1507 220 },
jjg@1455 221
jjg@1507 222 TD(BlockType.TABLE_ITEM, EndKind.OPTIONAL,
jjg@1507 223 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE),
jjg@1455 224 attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS,
jjg@1455 225 ALIGN, CHAR, CHAROFF, VALIGN),
jjg@1455 226 attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)),
jjg@1455 227
jjg@1507 228 TFOOT(BlockType.TABLE_ITEM, EndKind.REQUIRED,
jjg@1507 229 attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) {
jjg@1507 230 @Override
jjg@1507 231 public boolean accepts(HtmlTag t) {
jjg@1507 232 return (t == TR);
jjg@1507 233 }
jjg@1507 234 },
jjg@1455 235
jjg@1507 236 TH(BlockType.TABLE_ITEM, EndKind.OPTIONAL,
jjg@1507 237 EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE),
jjg@1455 238 attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS,
jjg@1455 239 ALIGN, CHAR, CHAROFF, VALIGN),
jjg@1455 240 attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)),
jjg@1455 241
jjg@1507 242 THEAD(BlockType.TABLE_ITEM, EndKind.REQUIRED,
jjg@1507 243 attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) {
jjg@1507 244 @Override
jjg@1507 245 public boolean accepts(HtmlTag t) {
jjg@1507 246 return (t == TR);
jjg@1507 247 }
jjg@1507 248 },
jjg@1455 249
jjg@1455 250 TITLE(BlockType.OTHER, EndKind.REQUIRED),
jjg@1455 251
jjg@1507 252 TR(BlockType.TABLE_ITEM, EndKind.OPTIONAL,
jjg@1455 253 attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN),
jjg@1507 254 attrs(AttrKind.USE_CSS, BGCOLOR)) {
jjg@1507 255 @Override
jjg@1507 256 public boolean accepts(HtmlTag t) {
jjg@1507 257 return (t == TH) || (t == TD);
jjg@1507 258 }
jjg@1507 259 },
jjg@1455 260
jjg@1455 261 TT(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 262 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 263
jjg@1455 264 U(BlockType.INLINE, EndKind.REQUIRED,
jjg@1455 265 EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)),
jjg@1455 266
jjg@1455 267 UL(BlockType.BLOCK, EndKind.REQUIRED,
jjg@1507 268 EnumSet.of(Flag.EXPECT_CONTENT),
jjg@1507 269 attrs(AttrKind.USE_CSS, COMPACT, TYPE)){
jjg@1507 270 @Override
jjg@1507 271 public boolean accepts(HtmlTag t) {
jjg@1507 272 return (t == LI);
jjg@1507 273 }
jjg@1507 274 },
jjg@1455 275
jjg@1455 276 VAR(BlockType.INLINE, EndKind.REQUIRED);
jjg@1455 277
jjg@1455 278 /**
jjg@1455 279 * Enum representing the type of HTML element.
jjg@1455 280 */
jjg@1455 281 public static enum BlockType {
jjg@1455 282 BLOCK,
jjg@1455 283 INLINE,
jjg@1507 284 LIST_ITEM,
jjg@1507 285 TABLE_ITEM,
jjg@1455 286 OTHER;
jjg@1455 287 }
jjg@1455 288
jjg@1455 289 /**
jjg@1455 290 * Enum representing HTML end tag requirement.
jjg@1455 291 */
jjg@1455 292 public static enum EndKind {
jjg@1455 293 NONE,
jjg@1455 294 OPTIONAL,
jjg@1455 295 REQUIRED;
jjg@1455 296 }
jjg@1455 297
jjg@1455 298 public static enum Flag {
jjg@1507 299 ACCEPTS_BLOCK,
jjg@1507 300 ACCEPTS_INLINE,
jjg@1455 301 EXPECT_CONTENT,
jjg@1507 302 NO_NEST
jjg@1455 303 }
jjg@1455 304
jjg@1455 305 public static enum Attr {
jjg@1455 306 ABBR,
jjg@1455 307 ALIGN,
jjg@1455 308 ALT,
jjg@1455 309 AXIS,
jjg@1455 310 BGCOLOR,
jjg@1455 311 BORDER,
jjg@1455 312 CELLSPACING,
jjg@1455 313 CELLPADDING,
jjg@1455 314 CHAR,
jjg@1455 315 CHAROFF,
jjg@1455 316 CLEAR,
jjg@1455 317 CLASS,
jjg@1455 318 COLOR,
jjg@1455 319 COLSPAN,
jjg@1455 320 COMPACT,
jjg@1455 321 FACE,
jjg@1455 322 FRAME,
jjg@1455 323 HEADERS,
jjg@1455 324 HEIGHT,
jjg@1455 325 HREF,
jjg@1455 326 HSPACE,
jjg@1455 327 ID,
jjg@1455 328 NAME,
jjg@1455 329 NOWRAP,
jjg@1455 330 REVERSED,
jjg@1455 331 ROWSPAN,
jjg@1455 332 RULES,
jjg@1455 333 SCOPE,
jjg@1455 334 SIZE,
jjg@1455 335 SPACE,
jjg@1455 336 SRC,
jjg@1455 337 START,
jjg@1455 338 STYLE,
jjg@1455 339 SUMMARY,
jjg@1455 340 TARGET,
jjg@1455 341 TYPE,
jjg@1455 342 VALIGN,
jjg@1793 343 VALUE,
jjg@1455 344 VSPACE,
jjg@1455 345 WIDTH;
jjg@1455 346
jjg@1455 347 public String getText() {
jjg@1455 348 return name().toLowerCase();
jjg@1455 349 }
jjg@1455 350
jjg@1455 351 static final Map<String,Attr> index = new HashMap<String,Attr>();
jjg@1455 352 static {
jjg@1455 353 for (Attr t: values()) {
jjg@1506 354 index.put(t.getText(), t);
jjg@1455 355 }
jjg@1455 356 }
jjg@1455 357 }
jjg@1455 358
jjg@1455 359 public static enum AttrKind {
jjg@1455 360 INVALID,
jjg@1455 361 OBSOLETE,
jjg@1455 362 USE_CSS,
jjg@1455 363 OK
jjg@1455 364 }
jjg@1455 365
jjg@1455 366 // This class exists to avoid warnings from using parameterized vararg type
jjg@1455 367 // Map<Attr,AttrKind> in signature of HtmlTag constructor.
jjg@1455 368 private static class AttrMap extends EnumMap<Attr,AttrKind> {
jjg@1455 369 private static final long serialVersionUID = 0;
jjg@1455 370 AttrMap() {
jjg@1455 371 super(Attr.class);
jjg@1455 372 }
jjg@1455 373 }
jjg@1455 374
jjg@1455 375
jjg@1455 376 public final BlockType blockType;
jjg@1455 377 public final EndKind endKind;
jjg@1455 378 public final Set<Flag> flags;
jjg@1455 379 private final Map<Attr,AttrKind> attrs;
jjg@1455 380
jjg@1455 381 HtmlTag(BlockType blockType, EndKind endKind, AttrMap... attrMaps) {
jjg@1455 382 this(blockType, endKind, Collections.<Flag>emptySet(), attrMaps);
jjg@1455 383 }
jjg@1455 384
jjg@1455 385 HtmlTag(BlockType blockType, EndKind endKind, Set<Flag> flags, AttrMap... attrMaps) {
jjg@1455 386 this.blockType = blockType;
jjg@1507 387 this.endKind = endKind;
jjg@1507 388 this.flags = flags;
jjg@1455 389 this.attrs = new EnumMap<Attr,AttrKind>(Attr.class);
jjg@1455 390 for (Map<Attr,AttrKind> m: attrMaps)
jjg@1455 391 this.attrs.putAll(m);
jjg@1455 392 attrs.put(Attr.CLASS, AttrKind.OK);
jjg@1455 393 attrs.put(Attr.ID, AttrKind.OK);
jjg@1455 394 attrs.put(Attr.STYLE, AttrKind.OK);
jjg@1455 395 }
jjg@1455 396
jjg@1507 397 public boolean accepts(HtmlTag t) {
jjg@1507 398 if (flags.contains(Flag.ACCEPTS_BLOCK) && flags.contains(Flag.ACCEPTS_INLINE)) {
jjg@1507 399 return (t.blockType == BlockType.BLOCK) || (t.blockType == BlockType.INLINE);
jjg@1507 400 } else if (flags.contains(Flag.ACCEPTS_BLOCK)) {
jjg@1507 401 return (t.blockType == BlockType.BLOCK);
jjg@1507 402 } else if (flags.contains(Flag.ACCEPTS_INLINE)) {
jjg@1507 403 return (t.blockType == BlockType.INLINE);
jjg@1507 404 } else
jjg@1507 405 switch (blockType) {
jjg@1507 406 case BLOCK:
jjg@1507 407 case INLINE:
jjg@1507 408 return (t.blockType == BlockType.INLINE);
jjg@1507 409 case OTHER:
jjg@1507 410 // OTHER tags are invalid in doc comments, and will be
jjg@1507 411 // reported separately, so silently accept/ignore any content
jjg@1507 412 return true;
jjg@1507 413 default:
jjg@1507 414 // any combination which could otherwise arrive here
jjg@1507 415 // ought to have been handled in an overriding method
jjg@1507 416 throw new AssertionError(this + ":" + t);
jjg@1507 417 }
jjg@1507 418 }
jjg@1507 419
jjg@1507 420 public boolean acceptsText() {
jjg@1507 421 // generally, anywhere we can put text we can also put inline tag
jjg@1507 422 // so check if a typical inline tag is allowed
jjg@1507 423 return accepts(B);
jjg@1507 424 }
jjg@1507 425
jjg@1455 426 public String getText() {
jjg@1455 427 return name().toLowerCase();
jjg@1455 428 }
jjg@1455 429
jjg@1455 430 public Attr getAttr(Name attrName) {
jjg@1455 431 return Attr.index.get(attrName.toString().toLowerCase());
jjg@1455 432 }
jjg@1455 433
jjg@1455 434 public AttrKind getAttrKind(Name attrName) {
jjg@1455 435 AttrKind k = attrs.get(getAttr(attrName)); // null-safe
jjg@1455 436 return (k == null) ? AttrKind.INVALID : k;
jjg@1455 437 }
jjg@1455 438
jjg@1455 439 private static AttrMap attrs(AttrKind k, Attr... attrs) {
jjg@1455 440 AttrMap map = new AttrMap();
jjg@1455 441 for (Attr a: attrs) map.put(a, k);
jjg@1455 442 return map;
jjg@1455 443 }
jjg@1455 444
jjg@1455 445 private static final Map<String,HtmlTag> index = new HashMap<String,HtmlTag>();
jjg@1455 446 static {
jjg@1455 447 for (HtmlTag t: values()) {
jjg@1506 448 index.put(t.getText(), t);
jjg@1455 449 }
jjg@1455 450 }
jjg@1455 451
jjg@1455 452 static HtmlTag get(Name tagName) {
jjg@1455 453 return index.get(tagName.toString().toLowerCase());
jjg@1455 454 }
jjg@1455 455 }

mercurial