diff --git a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocCommentTree.java b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocCommentTree.java index 810be9ea6ba..e6058f3d910 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocCommentTree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocCommentTree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2017, 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 @@ -26,6 +26,7 @@ package com.sun.source.doctree; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -69,4 +70,39 @@ public interface DocCommentTree extends DocTree { * @return the block tags of a documentation comment */ List extends DocTree> getBlockTags(); + + /** + * Returns a list of trees containing the content (if any) preceding + * the content of the documentation comment. + * When the {@code DocCommentTree} has been read from a documentation + * comment in a Java source file, the list will be empty. + * When the {@code DocCommentTree} has been read from an HTML file, this + * represents the content from the beginning of the file up to and + * including the {@code
} tag. + * + * @implSpec This implementation returns an empty list. + * + * @return the list of trees + * @since 10 + */ + default List extends DocTree> getPreamble() { + return Collections.emptyList(); + } + + /** + * Returns a list of trees containing the content (if any) following the + * content of the documentation comment. + * When the {@code DocCommentTree} has been read from a documentation + * comment in a Java source file, the list will be empty. + * When {@code DocCommentTree} has been read from an HTML file, this + * represents the content from the {@code } tag to the end of file. + * + * @implSpec This implementation returns an empty list. + * + * @return the list of trees + * @since 10 + */ + default List extends DocTree> getPostamble() { + return Collections.emptyList(); + } } diff --git a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTree.java b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTree.java index ec757e6e348..c9a06ba9b0c 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTree.java @@ -77,6 +77,12 @@ public interface DocTree { */ DOC_ROOT("docRoot"), + /** + * Used for instances of {@link DocTypeTree} + * representing an HTML DocType declaration. + */ + DOC_TYPE, + /** * Used for instances of {@link EndElementTree} * representing the end of an HTML element. diff --git a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTreeVisitor.java b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTreeVisitor.java index 0a71fe07238..29ccba7474d 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTreeVisitor.java +++ b/src/jdk.compiler/share/classes/com/sun/source/doctree/DocTreeVisitor.java @@ -104,6 +104,21 @@ public interface DocTreeVisitor
+ * <!doctype text>
+ *
+ * @since 10
+ */
+public interface DocTypeTree extends DocTree {
+ /**
+ * Returns the text of the doctype declaration.
+ * @return text
+ */
+ String getText();
+}
diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeFactory.java b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeFactory.java
index f8488f82f3f..189d0f153c7 100644
--- a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeFactory.java
+++ b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeFactory.java
@@ -39,6 +39,7 @@ import com.sun.source.doctree.DeprecatedTree;
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocRootTree;
import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.DocTypeTree;
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.EntityTree;
import com.sun.source.doctree.ErroneousTree;
@@ -121,12 +122,34 @@ public interface DocTreeFactory {
*/
DocCommentTree newDocCommentTree(List extends DocTree> fullBody, List extends DocTree> tags);
+
+ /**
+ * Create a new {@code DocCommentTree} object, to represent the enitire doc comment.
+ * @param fullBody the entire body of the doc comment
+ * @param tags the block tags in the doc comment
+ * @param preamble the meta content of an html file including the body tag
+ * @param postamble the meta content of an html including the closing body tag
+ * @return a {@code DocCommentTree} object
+ * @since 10
+ */
+ DocCommentTree newDocCommentTree(List extends DocTree> fullBody,
+ List extends DocTree> tags,
+ List extends DocTree> preamble,
+ List extends DocTree> postamble);
/**
* Create a new {@code DocRootTree} object, to represent an {@code {@docroot} } tag.
* @return a {@code DocRootTree} object
*/
DocRootTree newDocRootTree();
+ /**
+ * Create a new {@code DocTypeTree}, to represent a {@code DOCTYPE} HTML declaration.
+ * @param text the content of the declaration
+ * @return a {@code CommentTree} object
+ * @since 10
+ */
+ DocTypeTree newDocTypeTree(String text);
+
/**
* Create a new {@code EndElement} object, to represent the end of an HTML element.
* @param name the name of the HTML element
diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
index 4a48a8c5d40..4f4648f0eb7 100644
--- a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
+++ b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
@@ -198,6 +198,18 @@ public class DocTreeScanner, List
, List
, List
> inheritedText = new ArrayList<>();
DocTree parent = interestingParent.peek();
switch (parent.getKind()) {
@@ -391,7 +397,6 @@ public abstract class JavadocHelper implements AutoCloseable {
break;
}
if (!inheritedText.isEmpty()) {
- long offset = trees.getSourcePositions().getStartPosition(null, inheritedDocTree, inheritedDocTree);
long start = Long.MAX_VALUE;
long end = Long.MIN_VALUE;
@@ -475,7 +480,6 @@ public abstract class JavadocHelper implements AutoCloseable {
return docComment;
StringBuilder replacedInheritDoc = new StringBuilder(docComment);
- int offset = (int) trees.getSourcePositions().getStartPosition(null, docCommentTree, docCommentTree);
for (Entry
overview0.html
.
+A simple well formed html document
overview0.html
.
-
-
+
\ No newline at end of file
diff --git a/test/langtools/tools/javac/doctree/dcapi/overview0.html.out b/test/langtools/tools/javac/doctree/dcapi/overview0.html.out
new file mode 100644
index 00000000000..9ae529dbcd1
--- /dev/null
+++ b/test/langtools/tools/javac/doctree/dcapi/overview0.html.out
@@ -0,0 +1,33 @@
+EXPECT_START
+DocComment[DOC_COMMENT, pos:0
+ preamble: 5
+ Comment[COMMENT, pos:0, ]
+ StartElement[START_ELEMENT, pos:30
+ name:HTML
+ attributes: empty
+ ]
+ StartElement[START_ELEMENT, pos:37
+ name:HEAD
+ attributes: empty
+ ]
+ EndElement[END_ELEMENT, pos:44, HEAD]
+ StartElement[START_ELEMENT, pos:52
+ name:BODY
+ attributes: empty
+ ]
+ firstSentence: 1
+ Text[TEXT, pos:59, A_simple_well_fo...rmed_html_document]
+ body: 4
+ StartElement[START_ELEMENT, pos:94
+ name:pre
+ attributes: empty
+ ]
+ Text[TEXT, pos:99, overview0.html]
+ EndElement[END_ELEMENT, pos:113, pre]
+ Text[TEXT, pos:119, .]
+ block tags: empty
+ postamble: 2
+ EndElement[END_ELEMENT, pos:121, BODY]
+ EndElement[END_ELEMENT, pos:129, HTML]
+]
+EXPECT_END
diff --git a/test/langtools/tools/javac/doctree/dcapi/overview1.html b/test/langtools/tools/javac/doctree/dcapi/overview1.html
index 984632b0654..3012e5b3767 100644
--- a/test/langtools/tools/javac/doctree/dcapi/overview1.html
+++ b/test/langtools/tools/javac/doctree/dcapi/overview1.html
@@ -1,47 +1,8 @@
-
-
+
-Html document overview1.html
.
+Html document
overview1.html
.
Missing HTML.
-