Skip to content

Commit 7f27d0b

Browse files
8236142: DocTrees should provide getCharacters(EntityTree)
Reviewed-by: prappo
1 parent e7a1b9b commit 7f27d0b

File tree

7 files changed

+2242
-2234
lines changed

7 files changed

+2242
-2234
lines changed

src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
import com.sun.source.doctree.DocCommentTree;
4141
import com.sun.source.doctree.DocTree;
42+
import com.sun.source.doctree.EntityTree;
43+
import com.sun.source.tree.CompilationUnitTree;
4244

4345
/**
4446
* Provides access to syntax trees for doc comments.
@@ -202,19 +204,17 @@ public static DocTrees instance(ProcessingEnvironment env) {
202204
* @param root the compilation unit that contains tree
203205
*/
204206
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
205-
com.sun.source.doctree.DocTree t,
206-
com.sun.source.doctree.DocCommentTree c,
207-
com.sun.source.tree.CompilationUnitTree root);
207+
DocTree t, DocCommentTree c, CompilationUnitTree root);
208208

209209
/**
210210
* Sets the break iterator to compute the first sentence of
211211
* documentation comments.
212-
* @param breakiterator a break iterator or {@code null} to specify the default
212+
* @param breakIterator a break iterator or {@code null} to specify the default
213213
* sentence breaker
214214
*
215215
* @since 9
216216
*/
217-
public abstract void setBreakIterator(BreakIterator breakiterator);
217+
public abstract void setBreakIterator(BreakIterator breakIterator);
218218

219219
/**
220220
* Returns a utility object for creating {@code DocTree} objects.
@@ -223,4 +223,16 @@ public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
223223
* @since 9
224224
*/
225225
public abstract DocTreeFactory getDocTreeFactory();
226+
227+
/**
228+
* Returns a string containing the characters for the entity in a given entity tree,
229+
* or {@code null} if the tree does not represent a valid series of characters.
230+
*
231+
* <p>The interpretation of entities is based on section
232+
* <a href="https://www.w3.org/TR/html52/syntax.html#character-references">8.1.4. Character references</a>
233+
* in the HTML 5.2 specification.</p>
234+
*
235+
* @return a string containing the characters
236+
*/
237+
public abstract String getCharacters(EntityTree tree);
226238
}

src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -295,18 +295,12 @@ public Void visitText(TextTree tree, Void ignore) {
295295
public Void visitEntity(EntityTree tree, Void ignore) {
296296
checkAllowsText(tree);
297297
markEnclosingTag(Flag.HAS_TEXT);
298-
String name = tree.getName().toString();
299-
if (name.startsWith("#")) {
300-
int v = StringUtils.toLowerCase(name).startsWith("#x")
301-
? Integer.parseInt(name.substring(2), 16)
302-
: Integer.parseInt(name.substring(1), 10);
303-
if (!Entity.isValid(v)) {
304-
env.messages.error(HTML, tree, "dc.entity.invalid", name);
305-
}
306-
} else if (!Entity.isValid(name)) {
307-
env.messages.error(HTML, tree, "dc.entity.invalid", name);
298+
String s = env.trees.getCharacters(tree);
299+
if (s == null) {
300+
env.messages.error(HTML, tree, "dc.entity.invalid", tree.getName());
308301
}
309302
return null;
303+
310304
}
311305

312306
void checkAllowsText(DocTree tree) {

0 commit comments

Comments
 (0)