8273244: Improve diagnostic output related to ErroneousTree
Reviewed-by: prappo
This commit is contained in:
parent
6f727d831d
commit
0ca094bc5f
src
jdk.compiler/share/classes
com/sun/tools/javac
api
parser
tree
util
jdk/internal/shellsupport/doc
jdk.javadoc/share/classes/jdk/javadoc/internal
test/langtools/tools
doclint
javac
doctree
AttrTest.javaAuthorTest.javaBadTest.javaCodeTest.javaCoverageTest.javaDeprecatedTest.javaDocCommentTester.javaDocRootTest.javaElementTest.javaEntityTest.javaExceptionTest.javaFirstSentenceTest.javaHiddenTest.javaInPreTest.javaIndexTest.javaInheritDocTest.javaLinkPlainTest.javaLinkTest.javaLiteralTest.javaParamTest.javaProvidesTest.javaReturnTest.javaSeeTest.javaSerialDataTest.javaSerialFieldTest.javaSerialTest.javaSinceTest.javaSummaryTest.javaSystemPropertyTest.javaTagTest.javaThrowableTest.javaUsesTest.javaValueTest.javaVersionTest.java
positions
tree
@ -256,79 +256,16 @@ public class JavacTrees extends DocTrees {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
|
||||
return ((DCTree) tree).getSourcePosition((DCDocComment) comment);
|
||||
DCDocComment dcComment = (DCDocComment) comment;
|
||||
DCTree dcTree = (DCTree) tree;
|
||||
return dcComment.getSourcePosition(dcTree.getStartPosition());
|
||||
}
|
||||
@Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
|
||||
DCDocComment dcComment = (DCDocComment) comment;
|
||||
if (tree instanceof DCEndPosTree<?> dcEndPosTree) {
|
||||
int endPos = dcEndPosTree.getEndPos(dcComment);
|
||||
|
||||
if (endPos != Position.NOPOS) {
|
||||
return endPos;
|
||||
}
|
||||
}
|
||||
int correction = 0;
|
||||
switch (tree.getKind()) {
|
||||
case TEXT:
|
||||
DCText text = (DCText) tree;
|
||||
|
||||
return dcComment.comment.getSourcePos(text.pos + text.text.length());
|
||||
case ERRONEOUS:
|
||||
DCErroneous err = (DCErroneous) tree;
|
||||
|
||||
return dcComment.comment.getSourcePos(err.pos + err.body.length());
|
||||
case IDENTIFIER:
|
||||
DCIdentifier ident = (DCIdentifier) tree;
|
||||
|
||||
return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0));
|
||||
case PARAM:
|
||||
DCParam param = (DCParam) tree;
|
||||
|
||||
if (param.isTypeParameter && param.getDescription().isEmpty()) {
|
||||
correction = 1;
|
||||
}
|
||||
case AUTHOR: case DEPRECATED: case RETURN: case SEE:
|
||||
case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE:
|
||||
case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: {
|
||||
DocTree last = getLastChild(tree);
|
||||
|
||||
if (last != null) {
|
||||
return getEndPosition(file, comment, last) + correction;
|
||||
}
|
||||
|
||||
int pos;
|
||||
String name;
|
||||
if (tree.getKind() == DocTree.Kind.RETURN) {
|
||||
DCTree.DCReturn dcReturn = (DCTree.DCReturn) tree;
|
||||
pos = dcReturn.pos;
|
||||
name = dcReturn.getTagName();
|
||||
} else {
|
||||
DCBlockTag block = (DCBlockTag) tree;
|
||||
pos = block.pos;
|
||||
name = block.getTagName();
|
||||
}
|
||||
|
||||
return dcComment.comment.getSourcePos(pos + name.length() + 1);
|
||||
}
|
||||
case ENTITY: {
|
||||
DCEntity endEl = (DCEntity) tree;
|
||||
return dcComment.comment.getSourcePos(endEl.pos + (endEl.name != names.error ? endEl.name.length() : 0) + 2);
|
||||
}
|
||||
case COMMENT: {
|
||||
DCComment endEl = (DCComment) tree;
|
||||
return dcComment.comment.getSourcePos(endEl.pos + endEl.body.length());
|
||||
}
|
||||
default:
|
||||
DocTree last = getLastChild(tree);
|
||||
|
||||
if (last != null) {
|
||||
return getEndPosition(file, comment, last);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Position.NOPOS;
|
||||
DCTree dcTree = (DCTree) tree;
|
||||
return dcComment.getSourcePosition(dcTree.getEndPosition());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import com.sun.tools.javac.tree.DCTree.DCReference;
|
||||
import com.sun.tools.javac.tree.DCTree.DCText;
|
||||
import com.sun.tools.javac.tree.DocTreeMaker;
|
||||
import com.sun.tools.javac.util.DiagnosticSource;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
@ -62,14 +63,21 @@ import static com.sun.tools.javac.util.LayoutCharacters.EOI;
|
||||
public class DocCommentParser {
|
||||
static class ParseException extends Exception {
|
||||
private static final long serialVersionUID = 0;
|
||||
final int pos;
|
||||
|
||||
ParseException(String key) {
|
||||
this(Position.NOPOS, key);
|
||||
}
|
||||
ParseException(int pos, String key) {
|
||||
super(key);
|
||||
this.pos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
private enum Phase {PREAMBLE, BODY, POSTAMBLE}
|
||||
private enum Phase { PREAMBLE, BODY, POSTAMBLE }
|
||||
|
||||
private final ParserFactory fac;
|
||||
private final JCDiagnostic.Factory diags;
|
||||
private final DiagnosticSource diagSource;
|
||||
private final Comment comment;
|
||||
private final DocTreeMaker m;
|
||||
@ -96,6 +104,7 @@ public class DocCommentParser {
|
||||
public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource,
|
||||
Comment comment, boolean isFileContent) {
|
||||
this.fac = fac;
|
||||
this.diags = fac.log.diags;
|
||||
this.diagSource = diagSource;
|
||||
this.comment = comment;
|
||||
names = fac.names;
|
||||
@ -126,18 +135,13 @@ public class DocCommentParser {
|
||||
List<DCTree> tags = blockTags();
|
||||
List<DCTree> postamble = isFileContent ? blockContent(Phase.POSTAMBLE) : List.nil();
|
||||
|
||||
int pos = Position.NOPOS;
|
||||
if (!preamble.isEmpty())
|
||||
pos = preamble.head.pos;
|
||||
else if (!body.isEmpty())
|
||||
pos = body.head.pos;
|
||||
else if (!tags.isEmpty())
|
||||
pos = tags.head.pos;
|
||||
else if (!postamble.isEmpty())
|
||||
pos = postamble.head.pos;
|
||||
int pos = !preamble.isEmpty() ? preamble.head.pos
|
||||
: !body.isEmpty() ? body.head.pos
|
||||
: !tags.isEmpty() ? tags.head.pos
|
||||
: !postamble.isEmpty() ? postamble.head.pos
|
||||
: 0;
|
||||
|
||||
DCDocComment dc = m.at(pos).newDocCommentTree(comment, body, tags, preamble, postamble);
|
||||
return dc;
|
||||
return m.at(pos).newDocCommentTree(comment, body, tags, preamble, postamble);
|
||||
}
|
||||
|
||||
void nextChar() {
|
||||
@ -281,7 +285,7 @@ public class DocCommentParser {
|
||||
return erroneous("dc.no.tag.name", p);
|
||||
} catch (ParseException e) {
|
||||
blockContent();
|
||||
return erroneous(e.getMessage(), p);
|
||||
return erroneous(e.getMessage(), p, e.pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,7 +338,7 @@ public class DocCommentParser {
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return erroneous(e.getMessage(), p);
|
||||
return erroneous(e.getMessage(), p, e.pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,18 +475,15 @@ public class DocCommentParser {
|
||||
ref.moduleName, ref.qualExpr,
|
||||
ref.member, ref.paramTypes)
|
||||
.setEndPos(bp);
|
||||
} catch (ReferenceParser.ParseException parseException) {
|
||||
throw new ParseException(parseException.getMessage());
|
||||
} catch (ReferenceParser.ParseException pe) {
|
||||
throw new ParseException(pos + pe.pos, pe.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Java identifier
|
||||
* Matching pairs of { } are skipped; the text is terminated by the first
|
||||
* unmatched }. It is an error if the beginning of the next tag is detected.
|
||||
* Reads a Java identifier.
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
protected DCIdentifier identifier() throws ParseException {
|
||||
skipWhitespace();
|
||||
int pos = bp;
|
||||
@ -496,10 +497,9 @@ public class DocCommentParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a quoted string.
|
||||
* Reads a quoted string.
|
||||
* It is an error if the beginning of the next tag is detected.
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
protected DCText quotedString() {
|
||||
int pos = bp;
|
||||
nextChar();
|
||||
@ -530,7 +530,7 @@ public class DocCommentParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a term (that is, one word).
|
||||
* Reads a term (that is, one word).
|
||||
* It is an error if the beginning of the next tag is detected.
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
@ -567,7 +567,7 @@ public class DocCommentParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read general text content of an inline tag, including HTML entities and elements.
|
||||
* Reads general text content of an inline tag, including HTML entities and elements.
|
||||
* Matching pairs of { } are skipped; the text is terminated by the first
|
||||
* unmatched }. It is an error if the beginning of the next tag is detected.
|
||||
*/
|
||||
@ -656,7 +656,7 @@ public class DocCommentParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an HTML entity.
|
||||
* Reads an HTML entity.
|
||||
* {@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; }
|
||||
*/
|
||||
protected DCTree entity() {
|
||||
@ -966,7 +966,33 @@ public class DocCommentParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code ErroneousTree} node, for a range of text starting at a given position,
|
||||
* ending at the last non-whitespace character before the current position,
|
||||
* and with the preferred position set to the last character within that range.
|
||||
*
|
||||
* @param code the resource key for the error message
|
||||
* @param pos the starting position
|
||||
*
|
||||
* @return the {@code ErroneousTree} node
|
||||
*/
|
||||
protected DCErroneous erroneous(String code, int pos) {
|
||||
return erroneous(code, pos, Position.NOPOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code ErroneousTree} node, for a range of text starting at a given position,
|
||||
* ending at the last non-whitespace character before the current position,
|
||||
* and with a given preferred position.
|
||||
*
|
||||
* @param code the resource key for the error message
|
||||
* @param pos the starting position
|
||||
* @param pref the preferred position for the node, or {@code NOPOS} to use the default value
|
||||
* as the last character of the range
|
||||
*
|
||||
* @return the {@code ErroneousTree} node
|
||||
*/
|
||||
protected DCErroneous erroneous(String code, int pos, int pref) {
|
||||
int i = bp - 1;
|
||||
loop:
|
||||
while (i > pos) {
|
||||
@ -981,8 +1007,14 @@ public class DocCommentParser {
|
||||
}
|
||||
i--;
|
||||
}
|
||||
if (pref == Position.NOPOS) {
|
||||
pref = i;
|
||||
}
|
||||
int end = i + 1;
|
||||
textStart = -1;
|
||||
return m.at(pos).newErroneousTree(newString(pos, i + 1), diagSource, code);
|
||||
JCDiagnostic.DiagnosticPosition dp = DCTree.createDiagnosticPosition(comment, pos, pref, end);
|
||||
JCDiagnostic diag = diags.error(null, diagSource, dp, code);
|
||||
return m.at(pos).newErroneousTree(newString(pos, end), diag).setPrefPos(pref);
|
||||
}
|
||||
|
||||
protected boolean isIdentifierStart(char ch) {
|
||||
@ -1169,7 +1201,7 @@ public class DocCommentParser {
|
||||
}
|
||||
inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content
|
||||
nextChar();
|
||||
throw new ParseException("dc.unexpected.content");
|
||||
throw new ParseException(pos, "dc.unexpected.content");
|
||||
}
|
||||
},
|
||||
|
||||
@ -1226,7 +1258,7 @@ public class DocCommentParser {
|
||||
}
|
||||
inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content
|
||||
nextChar();
|
||||
throw new ParseException("dc.unexpected.content");
|
||||
throw new ParseException(pos, "dc.unexpected.content");
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -30,11 +30,17 @@ import com.sun.source.tree.Tree;
|
||||
import com.sun.source.util.TreeScanner;
|
||||
import com.sun.tools.javac.parser.Tokens.TokenKind;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.util.DiagnosticSource;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* A utility class to parse a string in a doc comment containing a
|
||||
* reference to an API element, such as a type, field or method.
|
||||
@ -71,8 +77,11 @@ public class ReferenceParser {
|
||||
*/
|
||||
public static class ParseException extends Exception {
|
||||
private static final long serialVersionUID = 0;
|
||||
ParseException(String message) {
|
||||
final int pos;
|
||||
|
||||
ParseException(int pos, String message) {
|
||||
super(message);
|
||||
this.pos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,106 +109,157 @@ public class ReferenceParser {
|
||||
Name member;
|
||||
List<JCTree> paramTypes;
|
||||
|
||||
Log.DeferredDiagnosticHandler deferredDiagnosticHandler
|
||||
= new Log.DeferredDiagnosticHandler(fac.log);
|
||||
Log.DeferredDiagnosticHandler dh = new Log.DeferredDiagnosticHandler(fac.log);
|
||||
|
||||
try {
|
||||
int slash = sig.indexOf("/");
|
||||
int hash = sig.indexOf("#", slash + 1);
|
||||
int afterSlash = slash + 1;
|
||||
int hash = sig.indexOf("#", afterSlash);
|
||||
int afterHash = hash + 1;
|
||||
int lparen = sig.indexOf("(", Math.max(slash, hash) + 1);
|
||||
if (slash > -1) {
|
||||
moduleName = parseModule(sig.substring(0, slash));
|
||||
} else {
|
||||
moduleName = null;
|
||||
}
|
||||
if (slash > 0 && sig.length() == slash + 1) {
|
||||
int afterLparen = lparen + 1;
|
||||
|
||||
moduleName = switch (slash) {
|
||||
case -1 -> null;
|
||||
case 0 -> throw new ParseException(0, "dc.ref.syntax.error");
|
||||
default -> parseModule(sig, 0, slash, dh);
|
||||
};
|
||||
|
||||
if (slash > 0 && sig.length() == afterSlash) {
|
||||
qualExpr = null;
|
||||
member = null;
|
||||
} else if (hash == -1) {
|
||||
if (lparen == -1) {
|
||||
qualExpr = parseType(sig.substring(slash + 1));
|
||||
qualExpr = parseType(sig, afterSlash, sig.length(), dh);
|
||||
member = null;
|
||||
} else {
|
||||
qualExpr = null;
|
||||
member = parseMember(sig.substring(slash + 1, lparen));
|
||||
member = parseMember(sig, afterSlash, lparen, dh);
|
||||
}
|
||||
} else {
|
||||
qualExpr = (hash == slash + 1) ? null : parseType(sig.substring(slash + 1, hash));
|
||||
if (lparen == -1)
|
||||
member = parseMember(sig.substring(hash + 1));
|
||||
else
|
||||
member = parseMember(sig.substring(hash + 1, lparen));
|
||||
qualExpr = (hash == afterSlash) ? null : parseType(sig, afterSlash, hash, dh);
|
||||
if (lparen == -1) {
|
||||
member = parseMember(sig, afterHash, sig.length(), dh);
|
||||
} else {
|
||||
member = parseMember(sig, afterHash, lparen, dh);
|
||||
}
|
||||
}
|
||||
|
||||
if (lparen < 0) {
|
||||
if (lparen == -1) {
|
||||
paramTypes = null;
|
||||
} else {
|
||||
int rparen = sig.indexOf(")", lparen);
|
||||
if (rparen != sig.length() - 1)
|
||||
throw new ParseException("dc.ref.bad.parens");
|
||||
paramTypes = parseParams(sig.substring(lparen + 1, rparen));
|
||||
if (rparen != sig.length() - 1) {
|
||||
throw new ParseException(rparen, "dc.ref.bad.parens");
|
||||
}
|
||||
paramTypes = parseParams(sig, afterLparen, rparen, dh);
|
||||
}
|
||||
|
||||
if (!deferredDiagnosticHandler.getDiagnostics().isEmpty())
|
||||
throw new ParseException("dc.ref.syntax.error");
|
||||
assert dh.getDiagnostics().isEmpty();
|
||||
|
||||
} finally {
|
||||
fac.log.popDiagnosticHandler(deferredDiagnosticHandler);
|
||||
fac.log.popDiagnosticHandler(dh);
|
||||
}
|
||||
|
||||
return new Reference(moduleName, qualExpr, member, paramTypes);
|
||||
}
|
||||
|
||||
private JCTree.JCExpression parseModule(String s) throws ParseException {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
JCTree.JCExpression expr = p.qualident(false);
|
||||
if (p.token().kind != TokenKind.EOF)
|
||||
throw new ParseException("dc.ref.unexpected.input");
|
||||
return expr;
|
||||
private JCTree.JCExpression parseModule(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException {
|
||||
String s = sig.substring(beginIndex, endIndex);
|
||||
JavaFileObject prev = fac.log.useSource(null);
|
||||
try {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
JCTree.JCExpression expr = p.qualident(false);
|
||||
if (p.token().kind != TokenKind.EOF) {
|
||||
throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input");
|
||||
}
|
||||
checkDiags(dh, beginIndex);
|
||||
return expr;
|
||||
} finally {
|
||||
fac.log.useSource(prev);
|
||||
}
|
||||
}
|
||||
|
||||
private JCTree parseType(String s) throws ParseException {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
JCTree tree = p.parseType();
|
||||
if (p.token().kind != TokenKind.EOF)
|
||||
throw new ParseException("dc.ref.unexpected.input");
|
||||
return tree;
|
||||
private JCTree parseType(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException {
|
||||
String s = sig.substring(beginIndex, endIndex);
|
||||
JavaFileObject prev = fac.log.useSource(null);
|
||||
try {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
JCTree tree = p.parseType();
|
||||
if (p.token().kind != TokenKind.EOF) {
|
||||
throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input");
|
||||
}
|
||||
checkDiags(dh, beginIndex);
|
||||
return tree;
|
||||
} finally {
|
||||
fac.log.useSource(prev);
|
||||
}
|
||||
}
|
||||
|
||||
private Name parseMember(String s) throws ParseException {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
Name name = p.ident();
|
||||
if (p.token().kind != TokenKind.EOF)
|
||||
throw new ParseException("dc.ref.unexpected.input");
|
||||
return name;
|
||||
private Name parseMember(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException {
|
||||
String s = sig.substring(beginIndex, endIndex);
|
||||
JavaFileObject prev = fac.log.useSource(null);
|
||||
try {
|
||||
JavacParser p = fac.newParser(s, false, false, false);
|
||||
Name name = p.ident();
|
||||
if (p.token().kind != TokenKind.EOF) {
|
||||
throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input");
|
||||
}
|
||||
checkDiags(dh, beginIndex);
|
||||
return name;
|
||||
} finally {
|
||||
fac.log.useSource(prev);
|
||||
}
|
||||
}
|
||||
|
||||
private List<JCTree> parseParams(String s) throws ParseException {
|
||||
if (s.trim().isEmpty())
|
||||
private List<JCTree> parseParams(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException {
|
||||
String s = sig.substring(beginIndex, endIndex);
|
||||
if (s.isBlank()) {
|
||||
return List.nil();
|
||||
|
||||
JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
|
||||
ListBuffer<JCTree> paramTypes = new ListBuffer<>();
|
||||
paramTypes.add(p.parseType());
|
||||
|
||||
if (p.token().kind == TokenKind.IDENTIFIER)
|
||||
p.nextToken();
|
||||
|
||||
while (p.token().kind == TokenKind.COMMA) {
|
||||
p.nextToken();
|
||||
paramTypes.add(p.parseType());
|
||||
|
||||
if (p.token().kind == TokenKind.IDENTIFIER)
|
||||
p.nextToken();
|
||||
}
|
||||
|
||||
if (p.token().kind != TokenKind.EOF)
|
||||
throw new ParseException("dc.ref.unexpected.input");
|
||||
JavaFileObject prev = fac.log.useSource(null);
|
||||
try {
|
||||
JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
|
||||
ListBuffer<JCTree> paramTypes = new ListBuffer<>();
|
||||
paramTypes.add(p.parseType());
|
||||
|
||||
if (new TypeAnnotationFinder().scan(paramTypes, null) != null)
|
||||
throw new ParseException("dc.ref.annotations.not.allowed");
|
||||
if (p.token().kind == TokenKind.IDENTIFIER) {
|
||||
p.nextToken();
|
||||
}
|
||||
|
||||
return paramTypes.toList();
|
||||
while (p.token().kind == TokenKind.COMMA) {
|
||||
p.nextToken();
|
||||
paramTypes.add(p.parseType());
|
||||
|
||||
if (p.token().kind == TokenKind.IDENTIFIER) {
|
||||
p.nextToken();
|
||||
}
|
||||
}
|
||||
|
||||
if (p.token().kind != TokenKind.EOF) {
|
||||
throw new ParseException(p.token().pos, "dc.ref.unexpected.input");
|
||||
}
|
||||
|
||||
Tree typeAnno = new TypeAnnotationFinder().scan(paramTypes, null);
|
||||
if (typeAnno != null) {
|
||||
int annoPos = ((JCTree) typeAnno).getStartPosition();
|
||||
throw new ParseException(beginIndex + annoPos, "dc.ref.annotations.not.allowed");
|
||||
}
|
||||
|
||||
checkDiags(dh, beginIndex);
|
||||
|
||||
return paramTypes.toList();
|
||||
} finally {
|
||||
fac.log.useSource(prev);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDiags(Log.DeferredDiagnosticHandler h, int offset) throws ParseException {
|
||||
JCDiagnostic d = h.getDiagnostics().peek();
|
||||
if (d != null) {
|
||||
throw new ParseException(offset + ((int) d.getPosition()), "dc.ref.syntax.error");
|
||||
}
|
||||
}
|
||||
|
||||
static class TypeAnnotationFinder extends TreeScanner<Tree, Void> {
|
||||
@ -213,4 +273,4 @@ public class ReferenceParser {
|
||||
return t1 != null ? t1 : t2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,26 +25,57 @@
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||
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.DiagnosticSource;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
import com.sun.source.util.DocTreeScanner;
|
||||
|
||||
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||
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.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
import static com.sun.tools.javac.util.Position.NOPOS;
|
||||
|
||||
/**
|
||||
*
|
||||
* Root class for abstract syntax documentation tree nodes. It provides definitions
|
||||
* for specific tree nodes as subclasses nested inside.
|
||||
*
|
||||
* Apart from the top-level {@link DCDocComment} node, generally nodes fall into
|
||||
* three groups:
|
||||
* <ul>
|
||||
* <li>Leaf nodes, such as {@link DCIdentifier}, {@link DCText}
|
||||
* <li>Inline tag nodes, such as {@link DCLink}, {@link DCLiteral}
|
||||
* <li>Block tag nodes, such as {@link DCParam}, {@link DCThrows}
|
||||
* </ul>
|
||||
*
|
||||
* Trees are typically wide and shallow, without a significant amount of nesting.
|
||||
*
|
||||
* Nodes have various associated positions:
|
||||
* <ul>
|
||||
* <li>the {@link #pos position} of the first character that is unique to this node,
|
||||
* and not part of any child node
|
||||
* <li>the {@link #getStartPosition start} of the range of characters for this node
|
||||
* <li>the "{@link #getPreferredPosition() preferred}" position in the range of characters
|
||||
* for this node
|
||||
* <li>the {@link #getEndPosition() end} of the range of characters for this node
|
||||
* </ul>
|
||||
*
|
||||
* All values are relative to the beginning of the
|
||||
* {@link Elements#getDocComment comment text} in which they appear.
|
||||
* To convert a value to the position in the enclosing source text,
|
||||
* use {@link DCDocComment#getSourcePosition(int)}.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
@ -53,41 +84,150 @@ import javax.tools.JavaFileObject;
|
||||
public abstract class DCTree implements DocTree {
|
||||
|
||||
/**
|
||||
* The position in the comment string.
|
||||
* Use {@link #getSourcePosition getSourcePosition} to convert
|
||||
* The position of the first character that is unique to this node.
|
||||
* It is normally set by the methods in {@link DocTreeMaker}.
|
||||
*
|
||||
* The value is relative to the beginning of the comment text.
|
||||
* Use {@link DCDocComment#getSourcePosition(int)} to convert
|
||||
* it to a position in the source file.
|
||||
*
|
||||
* TODO: why not simply translate all these values into
|
||||
* source file positions? Is it useful to have string-offset
|
||||
* positions as well?
|
||||
* @see #getStartPosition()
|
||||
* @see #getPreferredPosition()
|
||||
* @see #getEndPosition()
|
||||
*/
|
||||
public int pos;
|
||||
|
||||
/**
|
||||
* {@return the source position for this tree node}
|
||||
* {@return a {@code DiagnosticPosition} for this node}
|
||||
* The method may be used when reporting diagnostics for this node.
|
||||
*
|
||||
* @param dc the enclosing doc comment
|
||||
* @param dc the enclosing comment, used to convert comment-based positions
|
||||
* to file-based positions
|
||||
*/
|
||||
public long getSourcePosition(DCDocComment dc) {
|
||||
return dc.comment.getSourcePos(pos);
|
||||
public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) {
|
||||
return createDiagnosticPosition(dc.comment, getStartPosition(), getPreferredPosition(), getEndPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source position for position relative to this tree node}
|
||||
* This is primarily useful for nodes that wrap a single string child.
|
||||
* {@return the start position of this tree node}
|
||||
*
|
||||
* @param dc the enclosing doc comment
|
||||
* @param offset the offset
|
||||
* For most nodes, this is the position of the first character that is unique to this node.
|
||||
*
|
||||
* The value is relative to the beginning of the comment text.
|
||||
* Use {@link DCDocComment#getSourcePosition(int)} to convert
|
||||
* it to a position in the source file.
|
||||
*/
|
||||
public long getSourcePosition(DCDocComment dc, int offset) {
|
||||
return dc.comment.getSourcePos(pos + offset);
|
||||
public int getStartPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) {
|
||||
return new SimpleDiagnosticPosition(dc.comment.getSourcePos(pos));
|
||||
/**
|
||||
* {@return the "preferred" position of this tree node}
|
||||
*
|
||||
* It is typically the position of the first character that is unique to this node.
|
||||
* It is the position that is used for the caret in "line and caret" diagnostic messages.
|
||||
*
|
||||
* The value is relative to the beginning of the comment text.
|
||||
* Use {@link DCDocComment#getSourcePosition(int)} to convert
|
||||
* it to a position in the source file.
|
||||
*/
|
||||
public int getPreferredPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/** Convert a tree to a pretty-printed string. */
|
||||
/**
|
||||
* {@return the end position of the tree node}
|
||||
*
|
||||
* The value is typically derived in one of three ways:
|
||||
* <ul>
|
||||
* <li>computed from the start and length of "leaf" nodes, such as {@link TextTree},
|
||||
* <li>computed recursively from the end of the last child node, such as for most {@link DCBlockTag block tags}, or
|
||||
* <li>provided explicitly, such as for subtypes of {@link DCEndPosTree}
|
||||
* </ul>
|
||||
*
|
||||
* The value is relative to the beginning of the comment text.
|
||||
* Use {@link DCDocComment#getSourcePosition(int)} to convert
|
||||
* it to a position in the source file.
|
||||
*/
|
||||
public int getEndPosition() {
|
||||
if (this instanceof DCEndPosTree<?> dcEndPosTree) {
|
||||
int endPos = dcEndPosTree.getEndPos();
|
||||
|
||||
if (endPos != NOPOS) {
|
||||
return endPos;
|
||||
}
|
||||
}
|
||||
|
||||
switch (getKind()) {
|
||||
case TEXT -> {
|
||||
DCText text = (DCText) this;
|
||||
return text.pos + text.text.length();
|
||||
}
|
||||
|
||||
case ERRONEOUS -> {
|
||||
DCErroneous err = (DCErroneous) this;
|
||||
return err.pos + err.body.length();
|
||||
}
|
||||
|
||||
case IDENTIFIER -> {
|
||||
DCIdentifier ident = (DCIdentifier) this;
|
||||
return ident.pos + ident.name.length();
|
||||
}
|
||||
|
||||
case AUTHOR, DEPRECATED, HIDDEN, PARAM, PROVIDES, RETURN, SEE, SERIAL, SERIAL_DATA, SERIAL_FIELD, SINCE,
|
||||
THROWS, UNKNOWN_BLOCK_TAG, USES, VERSION -> {
|
||||
DCTree last = getLastChild();
|
||||
|
||||
if (last != null) {
|
||||
int correction = (this instanceof DCParam p && p.isTypeParameter && p.getDescription().isEmpty()) ? 1 : 0;
|
||||
return last.getEndPosition() + correction;
|
||||
}
|
||||
|
||||
String name = ((BlockTagTree) this).getTagName();
|
||||
return this.pos + name.length() + 1;
|
||||
}
|
||||
|
||||
case ENTITY -> {
|
||||
DCEntity endEl = (DCEntity) this;
|
||||
return endEl.pos + endEl.name.length() + 2;
|
||||
}
|
||||
|
||||
case COMMENT -> {
|
||||
DCComment endEl = (DCComment) this;
|
||||
return endEl.pos + endEl.body.length();
|
||||
}
|
||||
|
||||
case ATTRIBUTE -> {
|
||||
DCAttribute attr = (DCAttribute) this;
|
||||
if (attr.vkind == AttributeTree.ValueKind.EMPTY) {
|
||||
return attr.pos + attr.name.length();
|
||||
}
|
||||
DCTree last = getLastChild();
|
||||
if (last != null) {
|
||||
return last.getEndPosition() + (attr.vkind == AttributeTree.ValueKind.UNQUOTED ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
case DOC_COMMENT -> {
|
||||
DCDocComment dc = (DCDocComment) this;
|
||||
DCTree last = getLastChild();
|
||||
return last == null ? dc.pos : last.getEndPosition();
|
||||
}
|
||||
|
||||
default -> {
|
||||
DCTree last = getLastChild();
|
||||
if (last != null) {
|
||||
return last.getEndPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NOPOS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a tree to a pretty-printed string.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringWriter s = new StringWriter();
|
||||
@ -102,12 +242,64 @@ public abstract class DCTree implements DocTree {
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the last (right-most) child of this node}
|
||||
*/
|
||||
private DCTree getLastChild() {
|
||||
final DCTree[] last = new DCTree[] {null};
|
||||
|
||||
accept(new DocTreeScanner<Void, Void>() {
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Void scan(DocTree node, Void p) {
|
||||
if (node instanceof DCTree dcTree) last[0] = dcTree;
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
|
||||
return last[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a diagnostic position based on the positions in a comment}
|
||||
*
|
||||
* The positions are lazily converted to file-based positions, as needed.
|
||||
*
|
||||
* @param comment the enclosing comment
|
||||
* @param start the start position in the comment
|
||||
* @param pref the preferred position in the comment
|
||||
* @param end the end position in the comment
|
||||
*/
|
||||
public static JCDiagnostic.DiagnosticPosition createDiagnosticPosition(Comment comment, int start, int pref, int end) {
|
||||
return new JCDiagnostic.DiagnosticPosition() {
|
||||
|
||||
@Override
|
||||
public JCTree getTree() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartPosition() {
|
||||
return comment.getSourcePos(start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreferredPosition() {
|
||||
return comment.getSourcePos(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEndPosition(EndPosTable endPosTable) {
|
||||
return comment.getSourcePos(end);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static abstract class DCEndPosTree<T extends DCEndPosTree<T>> extends DCTree {
|
||||
|
||||
private int endPos = Position.NOPOS;
|
||||
private int endPos = NOPOS;
|
||||
|
||||
public int getEndPos(DCDocComment dc) {
|
||||
return dc.comment.getSourcePos(endPos);
|
||||
public int getEndPos() {
|
||||
return endPos;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -183,6 +375,10 @@ public abstract class DCTree implements DocTree {
|
||||
public List<? extends DocTree> getPostamble() {
|
||||
return postamble;
|
||||
}
|
||||
|
||||
public int getSourcePosition(int index) {
|
||||
return comment.getSourcePos(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class DCBlockTag extends DCTree implements BlockTagTree {
|
||||
@ -388,14 +584,11 @@ public abstract class DCTree implements DocTree {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCErroneous extends DCTree implements ErroneousTree, JCDiagnostic.DiagnosticPosition {
|
||||
public static class DCErroneous extends DCTree implements ErroneousTree {
|
||||
public final String body;
|
||||
public final JCDiagnostic diag;
|
||||
|
||||
DCErroneous(String body, JCDiagnostic.Factory diags, DiagnosticSource diagSource, String code, Object... args) {
|
||||
this.body = body;
|
||||
this.diag = diags.error(null, diagSource, this, code, args);
|
||||
}
|
||||
private int prefPos = NOPOS;
|
||||
|
||||
DCErroneous(String body, JCDiagnostic diag) {
|
||||
this.body = body;
|
||||
@ -422,11 +615,6 @@ public abstract class DCTree implements DocTree {
|
||||
return diag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JCTree getTree() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartPosition() {
|
||||
return pos;
|
||||
@ -434,14 +622,19 @@ public abstract class DCTree implements DocTree {
|
||||
|
||||
@Override
|
||||
public int getPreferredPosition() {
|
||||
return pos + body.length() - 1;
|
||||
return prefPos == NOPOS ? pos + body.length() - 1 : prefPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEndPosition(EndPosTable endPosTable) {
|
||||
public int getEndPosition() {
|
||||
return pos + body.length();
|
||||
}
|
||||
|
||||
public DCErroneous setPrefPos(int prefPos) {
|
||||
this.prefPos = prefPos;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DCHidden extends DCBlockTag implements HiddenTree {
|
||||
|
@ -126,9 +126,6 @@ public class DocTreeMaker implements DocTreeFactory {
|
||||
*/
|
||||
public int pos = Position.NOPOS;
|
||||
|
||||
/** Access to diag factory for ErroneousTrees. */
|
||||
private final JCDiagnostic.Factory diags;
|
||||
|
||||
private final JavacTrees trees;
|
||||
|
||||
/** Utility class to parse reference signatures. */
|
||||
@ -138,7 +135,6 @@ public class DocTreeMaker implements DocTreeFactory {
|
||||
*/
|
||||
protected DocTreeMaker(Context context) {
|
||||
context.put(treeMakerKey, this);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
this.pos = Position.NOPOS;
|
||||
trees = JavacTrees.instance(context);
|
||||
referenceParser = new ReferenceParser(ParserFactory.instance(context));
|
||||
@ -153,13 +149,6 @@ public class DocTreeMaker implements DocTreeFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Reassign current position.
|
||||
*/
|
||||
public DocTreeMaker at(DiagnosticPosition pos) {
|
||||
this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public DCAttribute newAttributeTree(Name name, ValueKind vkind, List<? extends DocTree> value) {
|
||||
DCAttribute tree = new DCAttribute(name, vkind, cast(value));
|
||||
@ -289,12 +278,6 @@ public class DocTreeMaker implements DocTreeFactory {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCErroneous newErroneousTree(String text, DiagnosticSource diagSource, String code, Object... args) {
|
||||
DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public DCThrows newExceptionTree(ReferenceTree name, List<? extends DocTree> description) {
|
||||
// TODO: verify the reference is just to a type (not a field or method)
|
||||
@ -720,7 +703,7 @@ public class DocTreeMaker implements DocTreeFactory {
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the position of the the first non-white space
|
||||
* Returns the position of the first non-whitespace character.
|
||||
*/
|
||||
private int skipWhiteSpace(String s, int start) {
|
||||
for (int i = start; i < s.length(); i++) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -50,7 +50,7 @@ import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
|
||||
public abstract class AbstractLog {
|
||||
/** Factory for diagnostics
|
||||
*/
|
||||
protected JCDiagnostic.Factory diags;
|
||||
public final JCDiagnostic.Factory diags;
|
||||
|
||||
/** The file that's currently being translated.
|
||||
*/
|
||||
|
@ -495,7 +495,7 @@ public abstract class JavadocHelper implements AutoCloseable {
|
||||
//if there is a newline immediately behind this tree, insert behind
|
||||
//the newline:
|
||||
long endPos = sp.getEndPosition(null, dcTree, tree);
|
||||
if (endPos >= 0) {
|
||||
if (endPos >= offset) {
|
||||
if (endPos - offset + 1 < docComment.length() &&
|
||||
docComment.charAt((int) (endPos - offset + 1)) == '\n') {
|
||||
endPos++;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -287,7 +287,6 @@ public class DocLint extends com.sun.tools.doclint.DocLint {
|
||||
void visitDecl(Tree tree, Name name) {
|
||||
TreePath p = getCurrentPath();
|
||||
DocCommentTree dc = env.trees.getDocCommentTree(p);
|
||||
|
||||
checker.scan(dc, p);
|
||||
}
|
||||
};
|
||||
|
@ -45,13 +45,15 @@ import javax.tools.FileObject;
|
||||
import javax.tools.ForwardingFileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
|
||||
import com.sun.source.doctree.CommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.DocTypeTree;
|
||||
import com.sun.source.doctree.ReferenceTree;
|
||||
import com.sun.source.doctree.TextTree;
|
||||
import com.sun.tools.javac.tree.DCTree.DCDocComment;
|
||||
import com.sun.tools.javac.tree.DCTree;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
|
||||
import com.sun.tools.javac.tree.EndPosTable;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
@ -278,12 +280,13 @@ public class JavadocLog extends Log implements Reporter {
|
||||
DiagnosticSource ds = getDiagnosticSource(path);
|
||||
|
||||
DCTree.DCDocComment docComment = (DCTree.DCDocComment) path.getDocComment();
|
||||
DCTree tree = (DCTree) path.getLeaf();
|
||||
DCTree docTree = (DCTree) path.getLeaf();
|
||||
// note: it is important to evaluate the offsets in the context of the position
|
||||
// within the comment text, and not in the context of the overall source text
|
||||
int sStart = (int) tree.getSourcePosition(docComment, start);
|
||||
int sPos = (int) tree.getSourcePosition(docComment, pos);
|
||||
int sEnd = (int) tree.getSourcePosition(docComment, end);
|
||||
int dtStart = docTree.getStartPosition();
|
||||
int sStart = docComment.getSourcePosition(dtStart + start);
|
||||
int sPos = docComment.getSourcePosition(dtStart + pos);
|
||||
int sEnd = docComment.getSourcePosition(dtStart + end);
|
||||
DiagnosticPosition dp = createDiagnosticPosition(null, sStart, sPos, sEnd);
|
||||
|
||||
report(dt, flags, ds, dp, message);
|
||||
@ -292,7 +295,7 @@ public class JavadocLog extends Log implements Reporter {
|
||||
private int getSourcePos(DocTreePath path, int offset) {
|
||||
DCTree.DCDocComment docComment = (DCTree.DCDocComment) path.getDocComment();
|
||||
DCTree tree = (DCTree) path.getLeaf();
|
||||
return (int) tree.getSourcePosition(docComment, offset);
|
||||
return docComment.getSourcePosition(tree.getStartPosition() + offset);
|
||||
}
|
||||
|
||||
@Override // Reporter
|
||||
@ -566,11 +569,9 @@ public class JavadocLog extends Log implements Reporter {
|
||||
* @return the diagnostic position
|
||||
*/
|
||||
private DiagnosticPosition getDiagnosticPosition(DocTreePath path) {
|
||||
DocSourcePositions posns = getSourcePositions();
|
||||
CompilationUnitTree compUnit = path.getTreePath().getCompilationUnit();
|
||||
int start = (int) posns.getStartPosition(compUnit, path.getDocComment(), path.getLeaf());
|
||||
int end = (int) posns.getEndPosition(compUnit, path.getDocComment(), path.getLeaf());
|
||||
return createDiagnosticPosition(null, start, start, end);
|
||||
DCDocComment dc = (DCDocComment) path.getDocComment();
|
||||
DCTree dcTree = (DCTree) path.getLeaf();
|
||||
return dcTree.pos(dc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -657,7 +658,7 @@ public class JavadocLog extends Log implements Reporter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the diagnostic source for an documentation tree node.
|
||||
* Returns the diagnostic source for a documentation tree node.
|
||||
*
|
||||
* @param path the path for the documentation tree node
|
||||
* @return the diagnostic source
|
||||
|
@ -1,7 +1,7 @@
|
||||
CrashInAnnotateTest.java:10:5: compiler.err.proc.messager: annotations not allowed
|
||||
CrashInAnnotateTest.java:11:5: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:16:5: compiler.err.proc.messager: annotations not allowed
|
||||
CrashInAnnotateTest.java:21:5: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:24:5: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:25:5: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:10:20: compiler.err.proc.messager: annotations not allowed
|
||||
CrashInAnnotateTest.java:11:37: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:16:39: compiler.err.proc.messager: annotations not allowed
|
||||
CrashInAnnotateTest.java:21:23: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:24:54: compiler.err.proc.messager: syntax error in reference
|
||||
CrashInAnnotateTest.java:25:37: compiler.err.proc.messager: syntax error in reference
|
||||
6 errors
|
@ -1,12 +1,12 @@
|
||||
EndWithIdentifierTest.java:17: error: syntax error in reference
|
||||
/**{@link*/
|
||||
^
|
||||
^
|
||||
EndWithIdentifierTest.java:22: error: reference not found
|
||||
* @see List*/
|
||||
^
|
||||
EndWithIdentifierTest.java:25: error: semicolon missing
|
||||
/**&*/
|
||||
^
|
||||
^
|
||||
EndWithIdentifierTest.java:28: error: malformed HTML
|
||||
/**<a*/
|
||||
^
|
||||
|
@ -1,5 +1,5 @@
|
||||
UnfinishedInlineTagTest.java:15: error: unterminated inline tag
|
||||
*/
|
||||
^
|
||||
UnfinishedInlineTagTest.java:14: error: unterminated inline tag
|
||||
/**{@link List
|
||||
^
|
||||
1 error
|
||||
|
||||
|
@ -5,17 +5,17 @@ the messages that are reported.
|
||||
|
||||
tidy.sh is a script that will run the "tidy" program on
|
||||
the files in a directory, writing the results to a new
|
||||
directroy.
|
||||
directory.
|
||||
|
||||
tidystats.Main is a Java program that can analyze the
|
||||
files produced by the tidy.sh script to generate a
|
||||
tidystats.Main is a Java program that can analyze the
|
||||
files produced by the tidy.sh script to generate a
|
||||
summary report about the warnings that were found.
|
||||
|
||||
|
||||
The tests is this directory are focussed on verifying
|
||||
that doclint detects issues in javadoc comments that will
|
||||
give rise to issues detected by "tidy" in the output
|
||||
generated by javadoc.
|
||||
generated by javadoc.
|
||||
|
||||
For more information on the "tidy" program, see the HTML Tidy
|
||||
Library Project page at http://tidy.sourceforge.net/.
|
||||
page at https://www.html-tidy.org.
|
||||
|
@ -1,11 +1,10 @@
|
||||
UnescapedOrUnknownEntity.java:16: error: semicolon missing
|
||||
* L&F
|
||||
^
|
||||
^
|
||||
UnescapedOrUnknownEntity.java:17: error: semicolon missing
|
||||
* Drag&Drop
|
||||
^
|
||||
^
|
||||
UnescapedOrUnknownEntity.java:18: error: bad HTML entity
|
||||
* if (a & b);
|
||||
^
|
||||
3 errors
|
||||
|
||||
3 errors
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8076026
|
||||
* @bug 7021614 8076026 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8241780
|
||||
* @bug 7021614 8241780 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
185
test/langtools/tools/javac/doctree/CoverageTest.java
Normal file
185
test/langtools/tools/javac/doctree/CoverageTest.java
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8273244
|
||||
* @summary check coverage of tools/javac/doctree tests
|
||||
* @modules jdk.compiler
|
||||
* @run main CoverageTest
|
||||
*/
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.tree.ClassTree;
|
||||
import com.sun.source.tree.MethodTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.source.util.DocTreeScanner;
|
||||
import com.sun.source.util.DocTrees;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.TaskEvent;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.source.util.TreePathScanner;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Scans for tests in the same source directory that use the DocCommentTester framework,
|
||||
* and for those tests, scans for doc comments, counting the number of occurrences
|
||||
* of different kinds of DocTree nodes. The number are mostly just informational,
|
||||
* except for the (implicit) zeroes, indicating that no instances of a kind of tree
|
||||
* have been detected ... which is a hole in the coverage.
|
||||
*
|
||||
* If desired, we could enhance the DocTreeScanner to track different variants of
|
||||
* specific kinds of tree nodes.
|
||||
*/
|
||||
public class CoverageTest {
|
||||
public static void main(String... args) throws Exception {
|
||||
new CoverageTest().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception {
|
||||
Path src = Path.of(System.getProperty("test.src"));
|
||||
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
|
||||
|
||||
List<JavaFileObject> files = new ArrayList<>();
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(src, this::isDocCommentTesterTest)) {
|
||||
for (Path p : ds) {
|
||||
files.add(fm.getJavaFileObjects(p).iterator().next());
|
||||
}
|
||||
}
|
||||
|
||||
JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, files);
|
||||
|
||||
DocTrees trees = DocTrees.instance(task);
|
||||
Map<DocTree.Kind, Integer> counts = new TreeMap<>();
|
||||
DocTreeScanner dtScanner = new DocTreeScanner() {
|
||||
@Override
|
||||
public Object scan(DocTree node, Object o) {
|
||||
if (node != null) {
|
||||
DocTree.Kind k = node.getKind();
|
||||
counts.put(k, counts.computeIfAbsent(k, k_ -> 0) + 1);
|
||||
}
|
||||
return super.scan(node, o);
|
||||
}
|
||||
};
|
||||
|
||||
TreePathScanner declScanner = new DeclScanner() {
|
||||
@Override
|
||||
void visitDecl(Tree tree, Name name) {
|
||||
TreePath path = getCurrentPath();
|
||||
DocCommentTree dc = trees.getDocCommentTree(path);
|
||||
dtScanner.scan(dc, null);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
task.addTaskListener(new TaskListener() {
|
||||
@Override
|
||||
public void finished(TaskEvent e) {
|
||||
if (e.getKind() == TaskEvent.Kind.PARSE) {
|
||||
declScanner.scan(e.getCompilationUnit(), null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
task.parse();
|
||||
|
||||
counts.forEach((k, v) -> System.err.printf("%20s: %5d%n", k, v));
|
||||
|
||||
// Note: DOC_TYPE cannot appear in any doc comment in a *.java file,
|
||||
// and OTHER is a special value that never appears in any standard DocTree node.
|
||||
List<DocTree.Kind> notFound = Stream.of(DocTree.Kind.values())
|
||||
.filter(k -> switch (k) { case DOC_TYPE, OTHER -> false; default -> true; })
|
||||
.filter(k -> !counts.containsKey(k))
|
||||
.toList();
|
||||
|
||||
if (!notFound.isEmpty()) {
|
||||
System.err.println();
|
||||
System.err.println("ERROR: The following kinds were not found: " + notFound.stream()
|
||||
.map(DocTree.Kind::name)
|
||||
.collect(Collectors.joining(", ")));
|
||||
System.err.println();
|
||||
throw new Exception("Not Found: " + notFound);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isDocCommentTesterTest(Path p) throws IOException {
|
||||
if (!p.getFileName().toString().endsWith(".java")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String marker = " * @run main DocCommentTester " + p.getFileName();
|
||||
for (String line : Files.readAllLines(p)) {
|
||||
if (line.equals(marker)) {
|
||||
return true;
|
||||
} else if (line.contains("{")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static abstract class DeclScanner extends TreePathScanner<Void, Void> {
|
||||
abstract void visitDecl(Tree tree, Name name);
|
||||
|
||||
@Override
|
||||
public Void visitClass(ClassTree tree, Void ignore) {
|
||||
super.visitClass(tree, ignore);
|
||||
visitDecl(tree, tree.getSimpleName());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitMethod(MethodTree tree, Void ignore) {
|
||||
super.visitMethod(tree, ignore);
|
||||
visitDecl(tree, tree.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitVariable(VariableTree tree, Void ignore) {
|
||||
super.visitVariable(tree, ignore);
|
||||
visitDecl(tree, tree.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -37,6 +37,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
|
||||
@ -57,14 +58,16 @@ import com.sun.tools.javac.tree.DCTree.DCDocComment;
|
||||
import com.sun.tools.javac.tree.DCTree.DCErroneous;
|
||||
import com.sun.tools.javac.tree.DocPretty;
|
||||
|
||||
/**
|
||||
* A class to test doc comment trees.
|
||||
* It is normally executed by calling {@code main}, providing a source file to be analyzed.
|
||||
* The file is scanned for top-level declarations, and the comment for any such declarations
|
||||
* is analyzed with a series of "checkers".
|
||||
*
|
||||
* @see DocCommentTester.ASTChecker#main(String... args)
|
||||
*/
|
||||
public class DocCommentTester {
|
||||
|
||||
public static final String BI_MARKER = "BREAK_ITERATOR";
|
||||
public final boolean useBreakIterator;
|
||||
|
||||
public DocCommentTester(boolean useBreakIterator) {
|
||||
this.useBreakIterator = useBreakIterator;
|
||||
}
|
||||
public static void main(String... args) throws Exception {
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList(args));
|
||||
if (!list.isEmpty() && "-useBreakIterator".equals(list.get(0))) {
|
||||
@ -75,6 +78,13 @@ public class DocCommentTester {
|
||||
}
|
||||
}
|
||||
|
||||
public static final String BI_MARKER = "BREAK_ITERATOR";
|
||||
public final boolean useBreakIterator;
|
||||
|
||||
public DocCommentTester(boolean useBreakIterator) {
|
||||
this.useBreakIterator = useBreakIterator;
|
||||
}
|
||||
|
||||
public void run(List<String> args) throws Exception {
|
||||
String testSrc = System.getProperty("test.src");
|
||||
|
||||
@ -98,7 +108,9 @@ public class DocCommentTester {
|
||||
final Checker[] checkers = {
|
||||
new ASTChecker(this, trees),
|
||||
new PosChecker(this, trees),
|
||||
new PrettyChecker(this, trees)
|
||||
new PrettyChecker(this, trees),
|
||||
new RangeChecker(this, trees),
|
||||
new StartEndPosChecker(this, trees)
|
||||
};
|
||||
|
||||
DeclScanner d = new DeclScanner() {
|
||||
@ -194,7 +206,7 @@ public class DocCommentTester {
|
||||
int errors;
|
||||
|
||||
/**
|
||||
* Verify the structure of the DocTree AST by comparing it against golden text.
|
||||
* Verifies the structure of the DocTree AST by comparing it against golden text.
|
||||
*/
|
||||
static class ASTChecker extends Checker {
|
||||
static final String NEWLINE = System.getProperty("line.separator");
|
||||
@ -280,7 +292,7 @@ public class DocCommentTester {
|
||||
final DocTrees trees = DocTrees.instance(t);
|
||||
|
||||
DeclScanner d = new DeclScanner() {
|
||||
Printer p = new Printer();
|
||||
final Printer p = new Printer();
|
||||
String source;
|
||||
|
||||
@Override
|
||||
@ -796,7 +808,7 @@ public class DocCommentTester {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the reported tree positions by comparing the characters found
|
||||
* Verifies the reported tree positions by comparing the characters found
|
||||
* at and after the reported position with the beginning of the pretty-
|
||||
* printed text.
|
||||
*/
|
||||
@ -811,16 +823,16 @@ public class DocCommentTester {
|
||||
final CharSequence cs = fo.getCharContent(true);
|
||||
|
||||
final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
|
||||
DCTree t = (DCTree) trees.getDocCommentTree(path);
|
||||
|
||||
DocTreeScanner<Void, Void> scanner = new DocTreeScanner<>() {
|
||||
@Override
|
||||
public Void scan(DocTree node, Void ignore) {
|
||||
if (node != null) {
|
||||
try {
|
||||
DCTree dcTree = (DCTree) node;
|
||||
String expect = getExpectText(node);
|
||||
long pos = ((DCTree) node).getSourcePosition(dc);
|
||||
String found = getFoundText(cs, (int) pos, expect.length());
|
||||
long startPos = dc.getSourcePosition(dcTree.getStartPosition());
|
||||
String found = getFoundText(cs, (int) startPos, expect.length());
|
||||
if (!found.equals(expect)) {
|
||||
System.err.println("expect: " + expect);
|
||||
System.err.println("found: " + found);
|
||||
@ -828,7 +840,7 @@ public class DocCommentTester {
|
||||
}
|
||||
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
error(node.getClass() + ": " + e.toString());
|
||||
error(node.getClass() + ": " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -836,7 +848,7 @@ public class DocCommentTester {
|
||||
}
|
||||
};
|
||||
|
||||
scanner.scan(t, null);
|
||||
scanner.scan(dc, null);
|
||||
}
|
||||
|
||||
String getExpectText(DocTree t) {
|
||||
@ -857,7 +869,7 @@ public class DocCommentTester {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the pretty printed text against a normalized form of the
|
||||
* Verifies the pretty printed text against a normalized form of the
|
||||
* original doc comment.
|
||||
*/
|
||||
static class PrettyChecker extends Checker {
|
||||
@ -905,9 +917,9 @@ public class DocCommentTester {
|
||||
}
|
||||
|
||||
String normalizeFragment(String s) {
|
||||
return s.replaceAll("\\{@docRoot\\s+\\}", "{@docRoot}")
|
||||
.replaceAll("\\{@inheritDoc\\s+\\}", "{@inheritDoc}")
|
||||
.replaceAll("(\\{@value\\s+[^}]+)\\s+(\\})", "$1$2")
|
||||
return s.replaceAll("\\{@docRoot\\s+}", "{@docRoot}")
|
||||
.replaceAll("\\{@inheritDoc\\s+}", "{@inheritDoc}")
|
||||
.replaceAll("(\\{@value\\s+[^}]+)\\s+(})", "$1$2")
|
||||
.replaceAll("\n[ \t]+@", "\n@");
|
||||
}
|
||||
|
||||
@ -919,21 +931,166 @@ public class DocCommentTester {
|
||||
sb.append(' ');
|
||||
}
|
||||
switch (ch) {
|
||||
case '{':
|
||||
case '{' ->
|
||||
depth++;
|
||||
break;
|
||||
case '}':
|
||||
|
||||
case '}' -> {
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
sb.append(ch);
|
||||
return i + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
sb.append(ch);
|
||||
}
|
||||
return s.length();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies the general "left to right" constraints for the positions of
|
||||
* nodes in the DocTree AST.
|
||||
*/
|
||||
static class RangeChecker extends Checker {
|
||||
int cursor = 0;
|
||||
|
||||
RangeChecker(DocCommentTester test, DocTrees docTrees) {
|
||||
test.super(docTrees);
|
||||
}
|
||||
|
||||
@Override
|
||||
void check(TreePath path, Name name) throws Exception {
|
||||
final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
|
||||
|
||||
DocTreeScanner<Void, Void> scanner = new DocTreeScanner<>() {
|
||||
@Override
|
||||
public Void scan(DocTree node, Void ignore) {
|
||||
if (node instanceof DCTree dcTree) {
|
||||
int start = dcTree.getStartPosition();
|
||||
int pref = dcTree.getPreferredPosition();
|
||||
int end = dcTree.getEndPosition();
|
||||
|
||||
// check within the node, start <= pref <= end
|
||||
check("start:pref", dcTree, start, pref);
|
||||
check("pref:end", dcTree, pref, end);
|
||||
|
||||
// check cursor <= start
|
||||
check("cursor:start", dcTree, cursor, start);
|
||||
cursor = start;
|
||||
|
||||
// recursively scan any children, updating the cursor
|
||||
super.scan(node, ignore);
|
||||
|
||||
// check cursor <= end
|
||||
check("cursor:end", dcTree, cursor, end);
|
||||
cursor = end;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
cursor = 0;
|
||||
scanner.scan(dc, null);
|
||||
|
||||
}
|
||||
|
||||
void check(String name, DCTree tree, int first, int second) {
|
||||
if (!(first <= second)) {
|
||||
error(name, tree, first, second);
|
||||
}
|
||||
}
|
||||
|
||||
private void error(String name, DCTree tree, int first, int second) {
|
||||
String t = tree.toString().replaceAll("\\s+", " ");
|
||||
if (t.length() > 32) {
|
||||
t = t.substring(0, 15) + "..." + t.substring(t.length() - 15);
|
||||
}
|
||||
error("Checking " + name + " for " + tree.getKind() + " `" + t + "`; first:" + first + ", second:" + second);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the start and end positions of all nodes in a DocCommentTree point to the
|
||||
* expected characters in the source code.
|
||||
*
|
||||
* The expected characters are derived from the beginning and end of the DocPretty output
|
||||
* for each node. Note that while the whitespace within the DocPretty output may not exactly
|
||||
* match the original source code, the first and last characters should match.
|
||||
*/
|
||||
static class StartEndPosChecker extends Checker {
|
||||
|
||||
StartEndPosChecker(DocCommentTester test, DocTrees docTrees) {
|
||||
test.super(docTrees);
|
||||
}
|
||||
|
||||
@Override
|
||||
void check(TreePath path, Name name) throws Exception {
|
||||
final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
|
||||
JavaFileObject jfo = path.getCompilationUnit().getSourceFile();
|
||||
CharSequence content = jfo.getCharContent(true);
|
||||
|
||||
DocTreeScanner<Void, Void> scanner = new DocTreeScanner<>() {
|
||||
@Override
|
||||
public Void scan(DocTree node, Void ignore) {
|
||||
if (node instanceof DCTree dcTree) {
|
||||
int start = dc.getSourcePosition(dc.getStartPosition());
|
||||
int end = dc.getSourcePosition(dcTree.getEndPosition());
|
||||
|
||||
try {
|
||||
StringWriter out = new StringWriter();
|
||||
DocPretty dp = new DocPretty(out);
|
||||
dp.print(trees.getDocCommentTree(path));
|
||||
String pretty = out.toString();
|
||||
|
||||
if (pretty.isEmpty()) {
|
||||
if (start != end) {
|
||||
error("Error: expected content is empty, but actual content is not: "
|
||||
+ dcTree.getKind() + " [" + start + "," + end + ")"
|
||||
+ ": \"" + content.subSequence(start, end) + "\"" );
|
||||
}
|
||||
} else {
|
||||
check(dcTree, "start", content, start, pretty, 0);
|
||||
check(dcTree, "end", content, end - 1, pretty, pretty.length() - 1);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
error("Error generating DocPretty for tree at position " + start + "; " + e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
scanner.scan(dc, null);
|
||||
}
|
||||
|
||||
void check(DCTree tree, String label, CharSequence content, int contentIndex, String pretty, int prettyIndex) {
|
||||
if (contentIndex == Diagnostic.NOPOS) {
|
||||
error("NOPOS for content " + label + ": " + tree.getKind() + " >>" + abbrev(pretty, MAX) + "<<");
|
||||
}
|
||||
|
||||
char contentChar = content.charAt(contentIndex);
|
||||
char prettyChar = pretty.charAt(prettyIndex);
|
||||
if (contentChar != prettyChar) {
|
||||
error ("Mismatch for content " + label + ": "
|
||||
+ "expect: '" + prettyChar + "', found: '" + contentChar + "' at position " + contentIndex + ": "
|
||||
+ tree.getKind() + " >>" + abbrev(pretty, MAX) + "<<");
|
||||
}
|
||||
}
|
||||
|
||||
static final int MAX = 64;
|
||||
|
||||
static String abbrev(String s, int max) {
|
||||
s = s.replaceAll("\\s+", " ");
|
||||
if (s.length() > max) {
|
||||
s = s.substring(0, max / 2 - 2) + " ... " + s.substring(max / 2 + 2);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8078320 8247788
|
||||
* @bug 7021614 8078320 8247788 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8078320 8132096
|
||||
* @bug 7021614 8078320 8132096 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
@ -38,7 +38,7 @@ class FirstSentenceTest {
|
||||
/** */
|
||||
void empty() { }
|
||||
/*
|
||||
DocComment[DOC_COMMENT, pos:-1
|
||||
DocComment[DOC_COMMENT, pos:0
|
||||
firstSentence: empty
|
||||
body: empty
|
||||
block tags: empty
|
||||
@ -46,7 +46,7 @@ DocComment[DOC_COMMENT, pos:-1
|
||||
*/
|
||||
/*
|
||||
BREAK_ITERATOR
|
||||
DocComment[DOC_COMMENT, pos:-1
|
||||
DocComment[DOC_COMMENT, pos:0
|
||||
firstSentence: empty
|
||||
body: empty
|
||||
block tags: empty
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8073100
|
||||
* @bug 8073100 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8078320
|
||||
* @bug 8078320 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8144287
|
||||
* @bug 8144287 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8241780
|
||||
* @bug 7021614 8241780 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8160196
|
||||
* @bug 8160196 8273244
|
||||
* @summary Module summary page should display information based on "api" or "detail" mode.
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8031212
|
||||
* @bug 7021614 8031212 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8173425
|
||||
* @bug 8173425 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 5076751
|
||||
* @bug 5076751 8273244
|
||||
* @summary System properties documentation needed in javadocs
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614 8078320
|
||||
* @bug 7021614 8078320 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8160196
|
||||
* @bug 8160196 8273244
|
||||
* @summary Module summary page should display information based on "api" or "detail" mode.
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7021614
|
||||
* @bug 7021614 8273244
|
||||
* @summary extend com.sun.source API to support parsing javadoc comments
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2021, 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
|
||||
@ -77,7 +77,7 @@ public class TestPosition extends AbstractProcessor {
|
||||
new DocTreeScanner<Void, Void>() {
|
||||
@Override public Void scan(DocTree node, Void p) {
|
||||
if (node != null) {
|
||||
DocSourcePositions sp = (DocSourcePositions) trees.getSourcePositions(); //XXX: the cast???
|
||||
DocSourcePositions sp = trees.getSourcePositions();
|
||||
int start = (int) sp.getStartPosition(testElement.getCompilationUnit(), docCommentTree, node);
|
||||
int end = (int) sp.getEndPosition(testElement.getCompilationUnit(), docCommentTree, node);
|
||||
String snippet = code.substring(start, end).replace(" \n", "!trailing-whitespace!\n");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2021, 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
|
||||
@ -200,10 +200,11 @@ public abstract class AbstractTreeScannerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error for a specific tree node.
|
||||
* @param file the source file for the tree
|
||||
* @param t the tree node
|
||||
* @param label an indication of the error
|
||||
* Report an error for a specific tree node.
|
||||
*
|
||||
* @param file the source file for the tree
|
||||
* @param tree the tree node
|
||||
* @param msg an indication of the error
|
||||
*/
|
||||
void error(JavaFileObject file, Tree tree, String msg) {
|
||||
JCTree t = (JCTree) tree;
|
||||
@ -211,15 +212,17 @@ public abstract class AbstractTreeScannerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error for a specific tree node.
|
||||
* @param file the source file for the tree
|
||||
* @param t the tree node
|
||||
* @param label an indication of the error
|
||||
* Report an error for a specific tree node.
|
||||
*
|
||||
* @param file the source file for the tree
|
||||
* @param comment the top level doc tree node
|
||||
* @param tree the tree node
|
||||
* @param msg an indication of the error
|
||||
*/
|
||||
void error(JavaFileObject file, DocCommentTree comment, DocTree tree, String msg) {
|
||||
DCDocComment dc = (DCDocComment) comment;
|
||||
DCTree t = (DCTree) tree;
|
||||
error(file.getName() + ":" + getLine(file, t.getSourcePosition(dc)) + ": " + msg + " " + trim(t, 64));
|
||||
error(file.getName() + ":" + getLine(file, dc.getSourcePosition(t.pos)) + ": " + msg + " " + trim(t, 64));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user