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

Thu, 24 Oct 2013 11:22:50 -0700

author
bpatel
date
Thu, 24 Oct 2013 11:22:50 -0700
changeset 2169
667843bd2193
parent 2051
96dcb66e6b0a
child 2413
fe033d997ddf
permissions
-rw-r--r--

8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
Reviewed-by: jjg

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

mercurial