Skip to content

Commit

Permalink
8247957: remove doclint support for HTML 4
Browse files Browse the repository at this point in the history
8257204: Remove usage of -Xhtmlversion option from javac
8256313: JavaCompilation.gmk needs to be updated not to use --doclint-format html5 option
8258460: Remove --doclint-format option from javac
8256312: Valid anchor 'id' value not allowed

Reviewed-by: jjg, ihse
  • Loading branch information
Yoshiki Sato authored and jonathan-gibbons committed Jan 6, 2021
1 parent 80544e4 commit 28e1f4d
Show file tree
Hide file tree
Showing 59 changed files with 494 additions and 891 deletions.
2 changes: 1 addition & 1 deletion make/common/JavaCompilation.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ define SetupJavaCompilationBody
# Tell javac to do exactly as told and no more
PARANOIA_FLAGS := -implicit:none -Xprefer:source -XDignore.symbol.file=true -encoding ascii

$1_FLAGS += -g -Xlint:all --doclint-format html5 $$($1_TARGET_RELEASE) $$(PARANOIA_FLAGS) $$(JAVA_WARNINGS_ARE_ERRORS)
$1_FLAGS += -g -Xlint:all $$($1_TARGET_RELEASE) $$(PARANOIA_FLAGS) $$(JAVA_WARNINGS_ARE_ERRORS)
$1_FLAGS += $$($1_JAVAC_FLAGS)

ifneq ($$($1_DISABLED_WARNINGS), )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
public abstract class DocLint implements Plugin {
public static final String XMSGS_OPTION = "-Xmsgs";
public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
public static final String XHTML_VERSION_PREFIX = "-XhtmlVersion:";
public static final String XCHECK_PACKAGE = "-XcheckPackage:";

private static ServiceLoader.Provider<DocLint> docLintProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,6 @@ public List<String> getDocLintOpts() {
doclintOpts.add(DocLint.XCHECK_PACKAGE + checkPackages);
}

String format = options.get(Option.DOCLINT_FORMAT);
if (format != null) {
doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + format);
}

return List.from(doclintOpts.toArray(new String[doclintOpts.size()]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ public void process(OptionHelper helper, String option, String arg) {
}
},

DOCLINT_FORMAT("--doclint-format", "opt.doclint.format", EXTENDED, BASIC, ONEOF, "html5"),

// -nowarn is retained for command-line backward compatibility
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ javac.opt.Xdoclint.package.desc=\
expands to all sub-packages of the given package. Each <package> can be prefixed\n\
with '-' to disable checks for the specified package or packages.

javac.opt.doclint.format=\
Specify the format for documentation comments

javac.opt.Xstdout=\
Redirect standard output
javac.opt.X=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,6 @@ public void initDocLint(List<String> opts, Set<String> customTagNames) {
doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags);
}

doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + "html5");

doclint = new DocLint();
doclint.init(docEnv.getDocTrees(), docEnv.getElementUtils(), docEnv.getTypeUtils(),
doclintOpts.toArray(new String[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import com.sun.tools.javac.util.DefinedBy.Api;

import jdk.javadoc.internal.doclint.HtmlTag.AttrKind;
import jdk.javadoc.internal.doclint.HtmlTag.ElemKind;
import static jdk.javadoc.internal.doclint.Messages.Group.*;


Expand Down Expand Up @@ -324,8 +325,8 @@ public Void visitStartElement(StartElementTree tree, Void ignore) {
final HtmlTag t = HtmlTag.get(treeName);
if (t == null) {
env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
} else if (t.allowedVersion != HtmlVersion.ALL && t.allowedVersion != env.htmlVersion) {
env.messages.error(HTML, tree, "dc.tag.not.supported", treeName);
} else if (t.elemKind == ElemKind.HTML4) {
env.messages.error(HTML, tree, "dc.tag.not.supported.html5", treeName);
} else {
boolean done = false;
for (TagStackItem tsi: tagStack) {
Expand Down Expand Up @@ -413,8 +414,7 @@ public Void visitStartElement(StartElementTree tree, Void ignore) {
// so-called "self-closing" tags are only permitted in HTML 5, for void elements
// https://html.spec.whatwg.org/multipage/syntax.html#start-tags
private boolean isSelfClosingAllowed(HtmlTag tag) {
return env.htmlVersion == HtmlVersion.HTML5
&& tag.endKind == HtmlTag.EndKind.NONE;
return tag.endKind == HtmlTag.EndKind.NONE;
}

private void checkStructure(StartElementTree tree, HtmlTag t) {
Expand Down Expand Up @@ -535,7 +535,7 @@ public Void visitEndElement(EndElementTree tree, Void ignore) {

case SECTION:
case ARTICLE:
if (env.htmlVersion == HtmlVersion.HTML5 && !top.flags.contains(Flag.HAS_HEADING)) {
if (!top.flags.contains(Flag.HAS_HEADING)) {
env.messages.error(HTML, tree, "dc.tag.requires.heading", treeName);
}
break;
Expand Down Expand Up @@ -579,7 +579,8 @@ void warnIfEmpty(TagStackItem tsi, DocTree endTree) {
if (tsi.tag.flags.contains(HtmlTag.Flag.EXPECT_CONTENT)
&& !tsi.flags.contains(Flag.HAS_TEXT)
&& !tsi.flags.contains(Flag.HAS_ELEMENT)
&& !tsi.flags.contains(Flag.HAS_INLINE_TAG)) {
&& !tsi.flags.contains(Flag.HAS_INLINE_TAG)
&& !(tsi.tag.elemKind == ElemKind.HTML4)) {
DocTree tree = (endTree != null) ? endTree : tsi.tree;
Name treeName = ((StartElementTree) tsi.tree).getName();
env.messages.warning(HTML, tree, "dc.tag.empty", treeName);
Expand All @@ -594,13 +595,10 @@ void warnIfEmpty(TagStackItem tsi, DocTree endTree) {
@Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
public Void visitAttribute(AttributeTree tree, Void ignore) {
HtmlTag currTag = tagStack.peek().tag;
if (currTag != null) {
if (currTag != null && currTag.elemKind != ElemKind.HTML4) {
Name name = tree.getName();
HtmlTag.Attr attr = currTag.getAttr(name);
if (attr != null) {
if (env.htmlVersion == HtmlVersion.HTML4 && attr.name().contains("-")) {
env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name);
}
boolean first = tagStack.peek().attrs.add(attr);
if (!first)
env.messages.error(HTML, tree, "dc.attr.repeated", name);
Expand All @@ -609,30 +607,29 @@ public Void visitAttribute(AttributeTree tree, Void ignore) {
// without checking the validity or applicability of the name
if (!name.toString().startsWith("on")) {
AttrKind k = currTag.getAttrKind(name);
switch (env.htmlVersion) {
switch (k) {
case OK:
break;
case OBSOLETE:
env.messages.warning(HTML, tree, "dc.attr.obsolete", name);
break;
case HTML4:
validateHtml4Attrs(tree, name, k);
env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name);
break;

case HTML5:
validateHtml5Attrs(tree, name, k);
case INVALID:
env.messages.error(HTML, tree, "dc.attr.unknown", name);
break;
}
}

if (attr != null) {
switch (attr) {
case NAME:
if (currTag != HtmlTag.A) {
break;
}
// fallthrough
case ID:
String value = getAttrValue(tree);
if (value == null) {
env.messages.error(HTML, tree, "dc.anchor.value.missing");
} else {
if (!validName.matcher(value).matches()) {
if (!validId.matcher(value).matches()) {
env.messages.error(HTML, tree, "dc.invalid.anchor", value);
}
if (!checkAnchor(value)) {
Expand Down Expand Up @@ -674,12 +671,20 @@ public Void visitAttribute(AttributeTree tree, Void ignore) {
if (currTag == HtmlTag.TABLE) {
String v = getAttrValue(tree);
try {
if (env.htmlVersion == HtmlVersion.HTML5
&& (v == null || (!v.isEmpty() && Integer.parseInt(v) != 1))) {
env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr);
if (v == null || (!v.isEmpty() && Integer.parseInt(v) != 1)) {
env.messages.error(HTML, tree, "dc.attr.table.border.not.valid", attr);
}
} catch (NumberFormatException ex) {
env.messages.error(HTML, tree, "dc.attr.table.border.not.number", attr);
}
} else if (currTag == HtmlTag.IMG) {
String v = getAttrValue(tree);
try {
if (v == null || (!v.isEmpty() && Integer.parseInt(v) != 0)) {
env.messages.error(HTML, tree, "dc.attr.img.border.not.valid", attr);
}
} catch (NumberFormatException ex) {
env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr);
env.messages.error(HTML, tree, "dc.attr.img.border.not.number", attr);
}
}
break;
Expand All @@ -701,44 +706,6 @@ public Void visitAttribute(AttributeTree tree, Void ignore) {
return null;
}

private void validateHtml4Attrs(AttributeTree tree, Name name, AttrKind k) {
switch (k) {
case ALL:
case HTML4:
break;

case INVALID:
env.messages.error(HTML, tree, "dc.attr.unknown", name);
break;

case OBSOLETE:
env.messages.warning(HTML, tree, "dc.attr.obsolete", name);
break;

case USE_CSS:
env.messages.warning(HTML, tree, "dc.attr.obsolete.use.css", name);
break;

case HTML5:
env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name);
break;
}
}

private void validateHtml5Attrs(AttributeTree tree, Name name, AttrKind k) {
switch (k) {
case ALL:
case HTML5:
break;

case INVALID:
case OBSOLETE:
case USE_CSS:
case HTML4:
env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name);
break;
}
}

private boolean checkAnchor(String name) {
Element e = getEnclosingPackageOrClass(env.currElement);
Expand All @@ -765,8 +732,8 @@ private Element getEnclosingPackageOrClass(Element e) {
return e;
}

// http://www.w3.org/TR/html401/types.html#type-name
private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*");
// https://html.spec.whatwg.org/#the-id-attribute
private static final Pattern validId = Pattern.compile("[^\\s]+");

private static final Pattern validNumber = Pattern.compile("-?[0-9]+");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class DocLint extends com.sun.tools.doclint.DocLint {
public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
private static final String STATS = "-stats";
public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:";
public static final String XHTML_VERSION_PREFIX = "-XhtmlVersion:";
public static final String XCHECK_PACKAGE = "-XcheckPackage:";
public static final String SEPARATOR = ",";

Expand Down Expand Up @@ -223,14 +222,6 @@ void processArgs(String... args) throws BadArgs {
env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
} else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
} else if (arg.startsWith(XHTML_VERSION_PREFIX)) {
String argsVersion = arg.substring(arg.indexOf(":") + 1);
HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion);
if (htmlVersion != null) {
env.setHtmlVersion(htmlVersion);
} else {
throw new BadArgs("dc.bad.value.for.option", arg, argsVersion);
}
} else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")
|| arg.equals("-?") || arg.equals("-usage")) {
needHelp = true;
Expand Down Expand Up @@ -345,14 +336,6 @@ private void processArgs(Env env, String... args) {
env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
} else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
} else if (arg.startsWith(XHTML_VERSION_PREFIX)) {
String argsVersion = arg.substring(arg.indexOf(":") + 1);
HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion);
if (htmlVersion != null) {
env.setHtmlVersion(htmlVersion);
} else {
throw new IllegalArgumentException(argsVersion);
}
} else if (arg.startsWith(XCHECK_PACKAGE)) {
env.setCheckPackages(arg.substring(arg.indexOf(":") + 1));
} else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -98,8 +98,6 @@ else if (mods.contains(Modifier.PRIVATE))
Set<Pattern> includePackages;
Set<Pattern> excludePackages;

HtmlVersion htmlVersion = HtmlVersion.HTML4;

// Utility classes
DocTrees trees;
Elements elements;
Expand Down Expand Up @@ -190,10 +188,6 @@ static boolean validatePackages(String packages) {
return true;
}

void setHtmlVersion(HtmlVersion version) {
htmlVersion = version;
}

/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
currPath = path;
Expand Down
Loading

1 comment on commit 28e1f4d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.