Skip to content
Permalink
Browse files
8252712: move doclint to jdk.javadoc module
Reviewed-by: hannesw
  • Loading branch information
jonathan-gibbons committed Sep 23, 2020
1 parent c21690b commit f765a7f513d8e6013026fc05677a3a2d16d2a217
Showing 104 changed files with 638 additions and 529 deletions.

Large diffs are not rendered by default.

@@ -258,7 +258,7 @@ public void initDocLint(List<String> docLintOpts) {
if (docLintOpts.isEmpty())
return;

new DocLint().init(this, docLintOpts.toArray(new String[docLintOpts.size()]));
DocLint.newDocLint().init(this, docLintOpts.toArray(new String[docLintOpts.size()]));
JavaCompiler.instance(context).keepComments = true;
}
}
@@ -132,7 +132,7 @@ protected void help(Log log) {
XDOCLINT_CUSTOM("-Xdoclint:", "opt.Xdoclint.subopts", "opt.Xdoclint.custom", EXTENDED, BASIC) {
@Override
public boolean matches(String option) {
return DocLint.isValidOption(
return DocLint.newDocLint().isValidOption(
option.replace(XDOCLINT_CUSTOM.primaryName, DocLint.XMSGS_CUSTOM_PREFIX));
}

@@ -147,7 +147,7 @@ public void process(OptionHelper helper, String option, String arg) {
XDOCLINT_PACKAGE("-Xdoclint/package:", "opt.Xdoclint.package.args", "opt.Xdoclint.package.desc", EXTENDED, BASIC) {
@Override
public boolean matches(String option) {
return DocLint.isValidOption(
return DocLint.newDocLint().isValidOption(
option.replace(XDOCLINT_PACKAGE.primaryName, DocLint.XCHECK_PACKAGE));
}

@@ -32,6 +32,7 @@
import java.util.EnumSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import javax.lang.model.element.Name;
import javax.tools.Diagnostic;
@@ -46,7 +47,6 @@
import com.sun.source.doctree.StartElementTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.util.DocTreeFactory;
import com.sun.tools.doclint.HtmlTag;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.parser.ReferenceParser;
@@ -95,8 +95,8 @@
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Pair;
import com.sun.tools.javac.util.Position;
import com.sun.tools.javac.util.StringUtils;

import static com.sun.tools.doclint.HtmlTag.*;

/**
*
@@ -112,7 +112,7 @@ public class DocTreeMaker implements DocTreeFactory {

// A subset of block tags, which acts as sentence breakers, appearing
// anywhere but the zero'th position in the first sentence.
final EnumSet<HtmlTag> sentenceBreakTags;
final Set<String> sentenceBreakTags;

/** Get the TreeMaker instance. */
public static DocTreeMaker instance(Context context) {
@@ -142,7 +142,7 @@ protected DocTreeMaker(Context context) {
this.pos = Position.NOPOS;
trees = JavacTrees.instance(context);
referenceParser = new ReferenceParser(ParserFactory.instance(context));
sentenceBreakTags = EnumSet.of(H1, H2, H3, H4, H5, H6, PRE, P);
sentenceBreakTags = Set.of("H1", "H2", "H3", "H4", "H5", "H6", "PRE", "P");
}

/** Reassign current position.
@@ -690,7 +690,7 @@ private int getSentenceBreak(String s, DocTree dt) {
}

private boolean isSentenceBreak(Name tagName) {
return sentenceBreakTags.contains(get(tagName));
return sentenceBreakTags.contains(StringUtils.toUpperCase(tagName.toString()));
}

private boolean isSentenceBreak(DocTree dt, boolean isFirstDocTree) {
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -58,7 +59,6 @@
import com.sun.source.util.DocTreeScanner;
import com.sun.source.util.DocTrees;
import com.sun.source.util.JavacTask;
import com.sun.tools.doclint.HtmlTag;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.StringUtils;
@@ -124,6 +124,27 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
}
}

enum HtmlTag {
HTML,
H1, H2, H3, H4, H5, H6,
BLOCKQUOTE, P, PRE,
IMG,
OL, UL, LI,
DL, DT, DD,
TABLE, TR, TD, TH;

private static final Map<String, HtmlTag> index = new HashMap<>();
static {
for (HtmlTag t: values()) {
index.put(StringUtils.toLowerCase(t.name()), t);
}
}

public static HtmlTag get(Name tagName) {
return index.get(StringUtils.toLowerCase(tagName.toString()));
}
}

private class FormatJavadocScanner extends DocTreeScanner<Object, Object> {
private final StringBuilder result;
private final JavacTask task;
@@ -117,6 +117,7 @@

uses javax.annotation.processing.Processor;
uses com.sun.source.util.Plugin;
uses com.sun.tools.doclint.DocLint;
uses com.sun.tools.javac.platform.PlatformProvider;

provides java.util.spi.ToolProvider with
@@ -29,7 +29,6 @@
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.StartElementTree;
import com.sun.source.util.DocTreeFactory;
import com.sun.tools.doclint.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
@@ -42,6 +41,7 @@
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import jdk.javadoc.internal.doclint.HtmlTag;

import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement;
@@ -73,6 +73,8 @@
import com.sun.source.doctree.SystemPropertyTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.util.SimpleDocTreeVisitor;

import jdk.javadoc.internal.doclint.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.FixedStringContent;
@@ -1262,9 +1264,9 @@ boolean ignoreNonInlineTag(DocTree dtree) {
}

if (name != null) {
com.sun.tools.doclint.HtmlTag htmlTag = com.sun.tools.doclint.HtmlTag.get(name);
HtmlTag htmlTag = HtmlTag.get(name);
if (htmlTag != null &&
htmlTag.blockType != com.sun.tools.doclint.HtmlTag.BlockType.INLINE) {
htmlTag.blockType != jdk.javadoc.internal.doclint.HtmlTag.BlockType.INLINE) {
return true;
}
}
@@ -1364,9 +1366,9 @@ private boolean inAnAtag() {
StartElementTree st = (StartElementTree)tag;
Name name = st.getName();
if (name != null) {
com.sun.tools.doclint.HtmlTag htag =
com.sun.tools.doclint.HtmlTag.get(name);
return htag != null && htag.equals(com.sun.tools.doclint.HtmlTag.A);
jdk.javadoc.internal.doclint.HtmlTag htag =
jdk.javadoc.internal.doclint.HtmlTag.get(name);
return htag != null && htag.equals(jdk.javadoc.internal.doclint.HtmlTag.A);
}
}
return false;
@@ -411,7 +411,7 @@ public boolean process(String opt, List<String> args) {
messages.error("doclet.Option_doclint_no_qualifiers");
return false;
}
if (!DocLint.isValidOption(dopt)) {
if (!DocLint.newDocLint().isValidOption(dopt)) {
messages.error("doclet.Option_doclint_invalid_arg");
return false;
}
@@ -424,7 +424,7 @@ public boolean process(String opt, List<String> args) {
@Override
public boolean process(String opt, List<String> args) {
String dopt = opt.replace("-Xdoclint/package:", DocLint.XCHECK_PACKAGE);
if (!DocLint.isValidOption(dopt)) {
if (!DocLint.newDocLint().isValidOption(dopt)) {
messages.error("doclet.Option_doclint_package_invalid_arg");
return false;
}
@@ -50,7 +50,6 @@
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePath;
import com.sun.tools.doclint.DocLint;
import com.sun.tools.javac.api.BasicJavacTask;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
@@ -70,6 +69,7 @@
import com.sun.tools.javac.util.Names;

import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import jdk.javadoc.internal.doclint.DocLint;
import jdk.javadoc.internal.tool.ToolEnvironment;
import jdk.javadoc.internal.tool.DocEnvImpl;

@@ -23,7 +23,7 @@
* questions.
*/

package com.sun.tools.doclint;
package jdk.javadoc.internal.doclint;

import java.io.IOException;
import java.io.StringWriter;
@@ -85,14 +85,13 @@
import com.sun.source.util.DocTreePath;
import com.sun.source.util.DocTreePathScanner;
import com.sun.source.util.TreePath;
import com.sun.tools.doclint.HtmlTag.AttrKind;
import com.sun.tools.javac.tree.DocPretty;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.StringUtils;

import static com.sun.tools.doclint.Messages.Group.*;
import jdk.javadoc.internal.doclint.HtmlTag.AttrKind;
import static jdk.javadoc.internal.doclint.Messages.Group.*;


/**

1 comment on commit f765a7f

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on f765a7f Sep 23, 2020

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.