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