1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.source.util;
  27 
  28 import java.util.List;
  29 
  30 import javax.lang.model.element.Name;
  31 import javax.tools.Diagnostic;
  32 import javax.tools.JavaFileObject;
  33 
  34 import com.sun.source.doctree.AttributeTree;
  35 import com.sun.source.doctree.AttributeTree.ValueKind;
  36 import com.sun.source.doctree.AuthorTree;
  37 import com.sun.source.doctree.CommentTree;
  38 import com.sun.source.doctree.DeprecatedTree;
  39 import com.sun.source.doctree.DocCommentTree;
  40 import com.sun.source.doctree.DocRootTree;
  41 import com.sun.source.doctree.DocTree;
  42 import com.sun.source.doctree.DocTypeTree;
  43 import com.sun.source.doctree.EndElementTree;
  44 import com.sun.source.doctree.EntityTree;
  45 import com.sun.source.doctree.ErroneousTree;
  46 import com.sun.source.doctree.HiddenTree;
  47 import com.sun.source.doctree.IdentifierTree;
  48 import com.sun.source.doctree.IndexTree;
  49 import com.sun.source.doctree.InheritDocTree;
  50 import com.sun.source.doctree.LinkTree;
  51 import com.sun.source.doctree.LiteralTree;
  52 import com.sun.source.doctree.ParamTree;
  53 import com.sun.source.doctree.ProvidesTree;
  54 import com.sun.source.doctree.ReferenceTree;
  55 import com.sun.source.doctree.ReturnTree;
  56 import com.sun.source.doctree.SeeTree;
  57 import com.sun.source.doctree.SerialDataTree;
  58 import com.sun.source.doctree.SerialFieldTree;
  59 import com.sun.source.doctree.SerialTree;
  60 import com.sun.source.doctree.SinceTree;
  61 import com.sun.source.doctree.StartElementTree;
  62 import com.sun.source.doctree.SummaryTree;
  63 import com.sun.source.doctree.SystemPropertyTree;
  64 import com.sun.source.doctree.TextTree;
  65 import com.sun.source.doctree.ThrowsTree;
  66 import com.sun.source.doctree.UnknownBlockTagTree;
  67 import com.sun.source.doctree.UnknownInlineTagTree;
  68 import com.sun.source.doctree.UsesTree;
  69 import com.sun.source.doctree.ValueTree;
  70 import com.sun.source.doctree.VersionTree;
  71 
  72 /**
  73  *  Factory for creating {@code DocTree} nodes.
  74  *
  75  *  @implNote The methods in an implementation of this interface may only accept {@code DocTree}
  76  *  nodes that have been created by the same implementation.
  77  *
  78  *  @since 9
  79  */
  80 public interface DocTreeFactory {
  81     /**
  82      * Create a new {@code AttributeTree} object, to represent an HTML attribute in an HTML tag.
  83      * @param name  the name of the attribute
  84      * @param vkind the kind of attribute value
  85      * @param value the value, if any, of the attribute
  86      * @return an {@code AttributeTree} object
  87      */
  88     AttributeTree newAttributeTree(Name name, ValueKind vkind, List<? extends DocTree> value);
  89 
  90     /**
  91      * Create a new {@code AuthorTree} object, to represent an {@code {@author } } tag.
  92      * @param name the name of the author
  93      * @return an {@code AuthorTree} object
  94      */
  95     AuthorTree newAuthorTree(List<? extends DocTree> name);
  96 
  97     /**
  98      * Create a new {@code CodeTree} object, to represent a {@code {@code } } tag.
  99      * @param text the content of the tag
 100      * @return a {@code CodeTree} object
 101      */
 102     LiteralTree newCodeTree(TextTree text);
 103 
 104     /**
 105      * Create a new {@code CommentTree}, to represent an HTML comment.
 106      * @param text the content of the comment
 107      * @return a {@code CommentTree} object
 108      */
 109     CommentTree newCommentTree(String text);
 110 
 111     /**
 112      * Create a new {@code DeprecatedTree} object, to represent an {@code {@deprecated } } tag.
 113      * @param text the content of the tag
 114      * @return a {@code DeprecatedTree} object
 115      */
 116     DeprecatedTree newDeprecatedTree(List<? extends DocTree> text);
 117 
 118     /**
 119      * Create a new {@code DocCommentTree} object, to represent a complete doc comment.
 120      * @param fullBody the entire body of the doc comment
 121      * @param tags the block tags in the doc comment
 122      * @return a {@code DocCommentTree} object
 123      */
 124     DocCommentTree newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags);
 125 
 126 
 127     /**
 128      * Create a new {@code DocCommentTree} object, to represent the enitire doc comment.
 129      * @param fullBody the entire body of the doc comment
 130      * @param tags the block tags in the doc comment
 131      * @param preamble the meta content of an html file including the body tag
 132      * @param postamble the meta content of an html including the closing body tag
 133      * @return a {@code DocCommentTree} object
 134      * @since 10
 135      */
 136     DocCommentTree newDocCommentTree(List<? extends DocTree> fullBody,
 137                                      List<? extends DocTree> tags,
 138                                      List<? extends DocTree> preamble,
 139                                      List<? extends DocTree> postamble);
 140     /**
 141      * Create a new {@code DocRootTree} object, to represent an {@code {@docroot} } tag.
 142      * @return a {@code DocRootTree} object
 143      */
 144     DocRootTree newDocRootTree();
 145 
 146     /**
 147      * Create a new {@code DocTypeTree}, to represent a {@code DOCTYPE} HTML declaration.
 148      * @param text the content of the declaration
 149      * @return a {@code CommentTree} object
 150      * @since 10
 151      */
 152     DocTypeTree newDocTypeTree(String text);
 153 
 154     /**
 155      * Create a new {@code EndElement} object, to represent the end of an HTML element.
 156      * @param name the name of the HTML element
 157      * @return an {@code EndElementTree} object
 158      */
 159     EndElementTree newEndElementTree(Name name);
 160 
 161     /**
 162      * Create a new {@code EntityTree} object, to represent an HTML entity.
 163      * @param name the name of the entity, representing the characters between '&lt;' and ';'
 164      * in the representation of the entity in an HTML document
 165      * @return an {@code EntityTree} object
 166      */
 167     EntityTree newEntityTree(Name name);
 168 
 169     /**
 170      * Create a new {@code ErroneousTree} object, to represent some unparseable input.
 171      * @param text the unparseable text
 172      * @param diag a diagnostic associated with the unparseable text, or null
 173      * @return an {@code ErroneousTree} object
 174      */
 175     ErroneousTree newErroneousTree(String text, Diagnostic<JavaFileObject> diag);
 176 
 177     /**
 178      * Create a new {@code ExceptionTree} object, to represent an {@code @exception } tag.
 179      * @param name the name of the exception
 180      * @param description a description of why the exception might be thrown
 181      * @return an {@code ExceptionTree} object
 182      */
 183     ThrowsTree newExceptionTree(ReferenceTree name, List<? extends DocTree> description);
 184 
 185     /**
 186      * Create a new {@code HiddenTree} object, to represent an {@code {@hidden } } tag.
 187      * @param text the content of the tag
 188      * @return a {@code HiddenTree} object
 189      */
 190     HiddenTree newHiddenTree(List<? extends DocTree> text);
 191 
 192     /**
 193      * Create a new {@code IdentifierTree} object, to represent an identifier, such as in a
 194      * {@code @param } tag.
 195      * @param name the name of the identifier
 196      * @return an {@code IdentifierTree} object
 197      */
 198     IdentifierTree newIdentifierTree(Name name);
 199 
 200     /**
 201      * Create a new {@code IndexTree} object, to represent an {@code {@index } } tag.
 202      * @param term the search term
 203      * @param description an optional description of the search term
 204      * @return an {@code IndexTree} object
 205      */
 206     IndexTree newIndexTree(DocTree term, List<? extends DocTree> description);
 207 
 208     /**
 209      * Create a new {@code InheritDocTree} object, to represent an {@code {@inheritDoc} } tag.
 210      * @return an {@code InheritDocTree} object
 211      */
 212     InheritDocTree newInheritDocTree();
 213 
 214     /**
 215      * Create a new {@code LinkTree} object, to represent a {@code {@link } } tag.
 216      * @param ref the API element being referenced
 217      * @param label an optional label for the link
 218      * @return a {@code LinkTree} object
 219      */
 220     LinkTree newLinkTree(ReferenceTree ref, List<? extends DocTree> label);
 221 
 222     /**
 223      * Create a new {@code LinkPlainTree} object, to represent a {@code {@linkplain } } tag.
 224      * @param ref the API element being referenced
 225      * @param label an optional label for the link
 226      * @return a {@code LinkPlainTree} object
 227      */
 228     LinkTree newLinkPlainTree(ReferenceTree ref, List<? extends DocTree> label);
 229 
 230     /**
 231      * Create a new {@code LiteralTree} object, to represent a {@code {@literal } } tag.
 232      * @param text the content of the tag
 233      * @return a {@code LiteralTree} object
 234      */
 235     LiteralTree newLiteralTree(TextTree text);
 236 
 237     /**
 238      * Create a new {@code ParamTree} object, to represent a {@code @param } tag.
 239      * @param isTypeParameter true if this is a type parameter, and false otherwise
 240      * @param name the parameter being described
 241      * @param description the description of the parameter
 242      * @return a {@code ParamTree} object
 243      */
 244     ParamTree newParamTree(boolean isTypeParameter, IdentifierTree name, List<? extends DocTree> description);
 245 
 246     /**
 247      * Create a new {@code ProvidesTree} object, to represent a {@code @provides } tag.
 248      * @param name the name of the service type
 249      * @param description a description of the service being provided
 250      * @return a {@code ProvidesTree} object
 251      */
 252     ProvidesTree newProvidesTree(ReferenceTree name, List<? extends DocTree> description);
 253 
 254     /**
 255      * Create a new {@code ReferenceTree} object, to represent a reference to an API element.
 256      *
 257      * @param signature the doc comment signature of the reference
 258      * @return a {@code ReferenceTree} object
 259      */
 260     ReferenceTree newReferenceTree(String signature);
 261 
 262     /**
 263      * Create a new {@code ReturnTree} object, to represent a {@code @return } tag.
 264      * @param description the description of the return value of a method
 265      * @return a {@code ReturnTree} object
 266      */
 267     ReturnTree newReturnTree(List<? extends DocTree> description);
 268 
 269     /**
 270      * Create a new {@code SeeTree} object, to represent a {@code @see } tag.
 271      * @param reference the reference
 272      * @return a {@code SeeTree} object
 273      */
 274     SeeTree newSeeTree(List<? extends DocTree> reference);
 275 
 276     /**
 277      * Create a new {@code SerialTree} object, to represent a {@code @serial } tag.
 278      * @param description the description for the tag
 279      * @return a {@code SerialTree} object
 280      */
 281     SerialTree newSerialTree(List<? extends DocTree> description);
 282 
 283     /**
 284      * Create a new {@code SerialDataTree} object, to represent a {@code @serialData } tag.
 285      * @param description the description for the tag
 286      * @return a {@code SerialDataTree} object
 287      */
 288     SerialDataTree newSerialDataTree(List<? extends DocTree> description);
 289 
 290     /**
 291      * Create a new {@code SerialFieldTree} object, to represent a {@code @serialField } tag.
 292      * @param name the name of the field
 293      * @param type the type of the field
 294      * @param description the description of the field
 295      * @return a {@code SerialFieldTree} object
 296      */
 297     SerialFieldTree newSerialFieldTree(IdentifierTree name, ReferenceTree type, List<? extends DocTree> description);
 298 
 299     /**
 300      * Create a new {@code SinceTree} object, to represent a {@code @since } tag.
 301      * @param text the content of the tag
 302      * @return a {@code SinceTree} object
 303      */
 304     SinceTree newSinceTree(List<? extends DocTree> text);
 305 
 306     /**
 307      * Create a new {@code StartElementTree} object, to represent the start of an HTML element.
 308      * @param name the name of the HTML element
 309      * @param attrs the attributes
 310      * @param selfClosing true if the start element is marked as self-closing; otherwise false
 311      * @return a {@code StartElementTree} object
 312      */
 313     StartElementTree newStartElementTree(Name name, List<? extends DocTree> attrs, boolean selfClosing);
 314 
 315     /**
 316      * Create a new {@code SummaryTree} object, to represent a {@code @summary } tag.
 317      *
 318      * @implSpec This implementation throws {@code UnsupportedOperationException}.
 319      *
 320      * @param summary the content of the tag
 321      * @return a {@code SummaryTree} object
 322      * @since 10
 323      */
 324     default SummaryTree newSummaryTree(List<? extends DocTree> summary) {
 325         throw new UnsupportedOperationException("not implemented");
 326     }
 327 
 328     /**
 329      * Create a new {@code SystemPropertyTree} object, to represent a {@code {@systemProperty } } tag.
 330      *
 331      * @param propertyName the system property name
 332      * @return a {@code SystemPropertyTree} object
 333      * @since 12
 334      */
 335     SystemPropertyTree newSystemPropertyTree(Name propertyName);
 336 
 337     /**
 338      * Create a new {@code TextTree} object, to represent some plain text.
 339      * @param text the text
 340      * @return a {@code TextTree} object
 341      */
 342     TextTree newTextTree(String text);
 343 
 344     /**
 345      * Create a new {@code ThrowsTree} object, to represent a {@code @throws } tag.
 346      * @param name the name of the exception
 347      * @param description a description of why the exception might be thrown
 348      * @return a {@code ThrowsTree} object
 349      */
 350     ThrowsTree newThrowsTree(ReferenceTree name, List<? extends DocTree> description);
 351 
 352     /**
 353      * Create a new {@code UnknownBlockTagTree} object, to represent an unrecognized block tag.
 354      * @param name the name of the block tag
 355      * @param content the content
 356      * @return an {@code UnknownBlockTagTree} object
 357      */
 358     UnknownBlockTagTree newUnknownBlockTagTree(Name name, List<? extends DocTree> content);
 359 
 360     /**
 361      * Create a new {@code UnknownInlineTagTree} object, to represent an unrecognized inline tag.
 362      * @param name the name of the inline tag
 363      * @param content the content
 364      * @return an {@code UnknownInlineTagTree} object
 365      */
 366     UnknownInlineTagTree newUnknownInlineTagTree(Name name, List<? extends DocTree> content);
 367 
 368     /**
 369      * Create a new {@code UsesTree} object, to represent a {@code @uses } tag.
 370      * @param name the name of the service type
 371      * @param description a description of how the service will be used
 372      * @return a {@code UsesTree} object
 373      */
 374     UsesTree newUsesTree(ReferenceTree name, List<? extends DocTree> description);
 375 
 376     /**
 377      * Create a new {@code ValueTree} object, to represent a {@code {@value } } tag.
 378      * @param ref a reference to the value
 379      * @return a {@code ValueTree} object
 380      */
 381     ValueTree newValueTree(ReferenceTree ref);
 382 
 383     /**
 384      * Create a new {@code VersionTree} object, to represent a {@code {@version } } tag.
 385      * @param text the content of the tag
 386      * @return a {@code VersionTree} object
 387      */
 388     VersionTree newVersionTree(List<? extends DocTree> text);
 389 
 390     /**
 391      * Set the position to be recorded in subsequent tree nodes created by this factory.
 392      * The position should be a character offset relative to the beginning of the source file
 393      * or {@link javax.tools.Diagnostic#NOPOS NOPOS}.
 394      * @param pos the position
 395      * @return this object, to facilitate method chaining
 396      */
 397     DocTreeFactory at(int pos);
 398 
 399     /**
 400      * Get the first sentence contained in a list of content.
 401      * The determination of the first sentence is implementation specific, and may
 402      * involve the use of a locale-specific {@link java.text.BreakIterator BreakIterator}
 403      * and other heuristics.
 404      * The resulting list may share a common set of initial items with the input list.
 405      * @param list the list
 406      * @return a list containing the first sentence of the list.
 407      */
 408     List<DocTree> getFirstSentence(List<? extends DocTree> list);
 409 
 410 }