Skip to content

Commit

Permalink
Issue checkstyle#3332: Added HTML void element 'embed'
Browse files Browse the repository at this point in the history
  • Loading branch information
voidfist committed Aug 13, 2017
1 parent 78de3dc commit 8b8199b
Show file tree
Hide file tree
Showing 11 changed files with 1,098 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,8 @@
<haltOnFailure>true</haltOnFailure>
<branchRate>100</branchRate>
<lineRate>100</lineRate>
<totalBranchRate>81</totalBranchRate>
<totalLineRate>84</totalLineRate>
<totalBranchRate>83</totalBranchRate>
<totalLineRate>87</totalLineRate>
<regexes>
<regex>
<pattern>com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer</pattern>
Expand All @@ -1547,13 +1547,13 @@
</regex>
<regex>
<pattern>com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser</pattern>
<branchRate>23</branchRate>
<lineRate>27</lineRate>
<branchRate>32</branchRate>
<lineRate>41</lineRate>
</regex>
<regex>
<pattern>com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocLexer</pattern>
<branchRate>41</branchRate>
<lineRate>55</lineRate>
<branchRate>63</branchRate>
<lineRate>82</lineRate>
</regex>
</regexes>
</check>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,15 @@ public final class JavadocTokenTypes {
public static final int PARAM_TAG = JavadocParser.RULE_paramTag + RULE_TYPES_OFFSET;
/** Param tag name. */
public static final int PARAM_HTML_TAG_NAME = JavadocParser.PARAM_HTML_TAG_NAME;
/**
* HTML void element {@code <embed>}.
* @see #SINGLETON_ELEMENT
* @see <a href="https://www.w3.org/TR/html51/semantics-embedded-content.html#elementdef-embed">
* W3 docs</a>
*/
public static final int EMBED_TAG = JavadocParser.RULE_embedTag + RULE_TYPES_OFFSET;
/** "embed" tag name. */
public static final int EMBED_HTML_TAG_NAME = JavadocParser.EMBED_HTML_TAG_NAME;
///////////////////////////////////////////////////////////////////////////////////////////////

/** Html comment: {@code <!-- -->}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ ISINDEX_HTML_TAG_NAME: I S I N D E X {!htmlTagNameCatched}? {htmlTagNameCatched=
LINK_HTML_TAG_NAME: L I N K {!htmlTagNameCatched}? {htmlTagNameCatched=true;};
META_HTML_TAG_NAME: M E T A {!htmlTagNameCatched}? {htmlTagNameCatched=true;};
PARAM_HTML_TAG_NAME: P A R A M {!htmlTagNameCatched}? {htmlTagNameCatched=true;};
EMBED_HTML_TAG_NAME: E M B E D {!htmlTagNameCatched}? {htmlTagNameCatched=true;};

// other tag names and attribute names
HTML_TAG_NAME: NAME_START_CHAR NAME_CHAR* {htmlTagNameCatched=true;};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ singletonElement: emptyTag
| metaTag
| paramTag
| wrongSinletonTag
| embedTag
;

emptyTag: START
Expand Down Expand Up @@ -822,6 +823,8 @@ metaTag: START META_HTML_TAG_NAME (attribute | NEWLINE | LEADING_ASTERISK | WS)*
(SLASH_END | END);
paramTag: START PARAM_HTML_TAG_NAME (attribute | NEWLINE | LEADING_ASTERISK | WS)*
(SLASH_END | END);
embedTag: START EMBED_HTML_TAG_NAME (attribute | NEWLINE | LEADING_ASTERISK | WS)*
(SLASH_END | END);

wrongSinletonTag: START SLASH singletonTagName
END {notifyErrorListeners($singletonTagName.start,
Expand All @@ -840,6 +843,7 @@ singletonTagName: (AREA_HTML_TAG_NAME
| LINK_HTML_TAG_NAME
| META_HTML_TAG_NAME
| PARAM_HTML_TAG_NAME
| EMBED_HTML_TAG_NAME
)
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import org.eclipse.jgit.util.StringUtils;

public abstract class AbstractTreeTestSupport extends AbstractPathTestSupport {

protected static final String LF_REGEX = "\\\\n";
Expand Down Expand Up @@ -115,7 +117,9 @@ protected static void verifyJavadocTree(String expectedTextPrintFilename,
final String actualContents = DetailNodeTreeStringPrinter.printFileAst(
new File(actualJavadocFilename)).replaceAll(CLRF_REGEX, LF_REGEX);

assertEquals("Generated tree from the javadoc file should match the pre-defined tree",
assertEquals("Generated tree from the javadoc file should match the pre-defined tree. "
+ "Match failed at index: "
+ StringUtils.compareWithCase(expectedContents, actualContents),
expectedContents, actualContents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,16 @@ public void testJavadocWithCrAsNewline() throws Exception {
verifyJavadocTree(getPath("expectedJavadocWithCrAsNewlineAst.txt"),
getPath("InputJavadocWithCrAsNewline.javadoc"));
}

@Test
public void testVoidElements() throws Exception {
verifyJavadocTree(getHtmlPath("expectedVoidElementsAst.txt"),
getHtmlPath("InputVoidElements.javadoc"));
}

@Test
public void testHtmlVoidElementEmbed() throws Exception {
verifyJavadocTree(getHtmlPath("expectedHtmlVoidElementEmbedAst.txt"),
getHtmlPath("InputHtmlVoidElementEmbed.javadoc"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ public void testGetTokenNameForId() {
@Test
public void testGetTokenNameForLargeId() {
try {
JavadocUtils.getTokenName(20074);
JavadocUtils.getTokenName(30073);
fail("exception expected");
}
catch (IllegalArgumentException ex) {
assertEquals("Invalid exception message",
"Unknown javadoc token id. Given id: 20074", ex.getMessage());
"Unknown javadoc token id. Given id: 30073", ex.getMessage());
}
}

Expand Down Expand Up @@ -346,6 +346,6 @@ public void testGetPreviousSibling() {
@Test
public void testGetTokenNames() {
assertEquals("Unexpected token name",
"HTML_COMMENT", JavadocUtils.getTokenName(20073));
"HTML_COMMENT", JavadocUtils.getTokenName(20074));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
* <p> <embed> </p>
* <li> <embed> </li>
* <tr> <embed> </tr>
* <td> <embed> </td>
* <th> <embed> </th>
* <body> <embed> </body>
* <colgroup> <embed> </colgroup>
* <dd> <embed> </dd>
* <dt> <embed> </dt>
* <head> <embed> </head>
* <html> <embed> </html>
* <option> <embed> </option>
* <tbody> <embed> </tbody>
* <thead> <embed> </thead>
* <tfoot> <embed> </tfoot>

* <p> <embed/> </p>
* <li> <embed/> </li>
* <tr> <embed/> </tr>
* <td> <embed/> </td>
* <th> <embed/> </th>
* <body> <embed/> </body>
* <colgroup> <embed/> </colgroup>
* <dd> <embed/> </dd>
* <dt> <embed/> </dt>
* <head> <embed/> </head>
* <html> <embed/> </html>
* <option> <embed/> </option>
* <tbody> <embed/> </tbody>
* <thead> <embed/> </thead>
* <tfoot> <embed/> </tfoot>

* <embed>
* <embed/>
* <embed attr="something">
* <embed attr="something"/>
* <embed attr="something" attr2="someotherthing">
* <embed attr="something" attr2="someotherthing"/>
* <embed attr="something"
* attr2="someotherting">
* <embed attr="something"
* attr2="someotherting"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<area>
<base>
<basefont>
<br>
<col>
<frame>
<hr>
<img>
<input>
<isindex>
<link>
<meta>
<param>
<embed>

<area/>
<base/>
<basefont/>
<br/>
<col/>
<frame/>
<hr/>
<img/>
<input/>
<isindex/>
<link/>
<meta/>
<param/>
<embed/>
Loading

0 comments on commit 8b8199b

Please sign in to comment.