langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java
changeset 25874 83c19f00452c
parent 22163 3651128c74eb
child 33360 d8ef08003d35
equal deleted inserted replaced
25873:024ed9c9ed13 25874:83c19f00452c
       
     1 /*
       
     2  * Copyright (c) 2011, 2012, 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.tools.javac.tree;
       
    27 
       
    28 import com.sun.source.doctree.AttributeTree.ValueKind;
       
    29 import com.sun.source.doctree.DocTree.Kind;
       
    30 
       
    31 import com.sun.tools.javac.parser.Tokens.Comment;
       
    32 import com.sun.tools.javac.tree.DCTree.*;
       
    33 import com.sun.tools.javac.util.Context;
       
    34 import com.sun.tools.javac.util.DiagnosticSource;
       
    35 import com.sun.tools.javac.util.JCDiagnostic;
       
    36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
       
    37 import com.sun.tools.javac.util.List;
       
    38 import com.sun.tools.javac.util.Name;
       
    39 import com.sun.tools.javac.util.Position;
       
    40 
       
    41 /**
       
    42  *
       
    43  *  <p><b>This is NOT part of any supported API.
       
    44  *  If you write code that depends on this, you do so at your own risk.
       
    45  *  This code and its internal interfaces are subject to change or
       
    46  *  deletion without notice.</b>
       
    47  */
       
    48 public class DocTreeMaker {
       
    49 
       
    50     /** The context key for the tree factory. */
       
    51     protected static final Context.Key<DocTreeMaker> treeMakerKey = new Context.Key<>();
       
    52 
       
    53     /** Get the TreeMaker instance. */
       
    54     public static DocTreeMaker instance(Context context) {
       
    55         DocTreeMaker instance = context.get(treeMakerKey);
       
    56         if (instance == null)
       
    57             instance = new DocTreeMaker(context);
       
    58         return instance;
       
    59     }
       
    60 
       
    61     /** The position at which subsequent trees will be created.
       
    62      */
       
    63     public int pos = Position.NOPOS;
       
    64 
       
    65     /** Access to diag factory for ErroneousTrees. */
       
    66     private final JCDiagnostic.Factory diags;
       
    67 
       
    68     /** Create a tree maker with NOPOS as initial position.
       
    69      */
       
    70     protected DocTreeMaker(Context context) {
       
    71         context.put(treeMakerKey, this);
       
    72         diags = JCDiagnostic.Factory.instance(context);
       
    73         this.pos = Position.NOPOS;
       
    74     }
       
    75 
       
    76     /** Reassign current position.
       
    77      */
       
    78     public DocTreeMaker at(int pos) {
       
    79         this.pos = pos;
       
    80         return this;
       
    81     }
       
    82 
       
    83     /** Reassign current position.
       
    84      */
       
    85     public DocTreeMaker at(DiagnosticPosition pos) {
       
    86         this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
       
    87         return this;
       
    88     }
       
    89 
       
    90     public DCAttribute Attribute(Name name, ValueKind vkind, List<DCTree> value) {
       
    91         DCAttribute tree = new DCAttribute(name, vkind, value);
       
    92         tree.pos = pos;
       
    93         return tree;
       
    94     }
       
    95 
       
    96     public DCAuthor Author(List<DCTree> name) {
       
    97         DCAuthor tree = new DCAuthor(name);
       
    98         tree.pos = pos;
       
    99         return tree;
       
   100     }
       
   101 
       
   102     public DCLiteral Code(DCText text) {
       
   103         DCLiteral tree = new DCLiteral(Kind.CODE, text);
       
   104         tree.pos = pos;
       
   105         return tree;
       
   106     }
       
   107 
       
   108     public DCComment Comment(String text) {
       
   109         DCComment tree = new DCComment(text);
       
   110         tree.pos = pos;
       
   111         return tree;
       
   112     }
       
   113 
       
   114     public DCDeprecated Deprecated(List<DCTree> text) {
       
   115         DCDeprecated tree = new DCDeprecated(text);
       
   116         tree.pos = pos;
       
   117         return tree;
       
   118     }
       
   119 
       
   120     public DCDocComment DocComment(Comment comment, List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
       
   121         DCDocComment tree = new DCDocComment(comment, firstSentence, body, tags);
       
   122         tree.pos = pos;
       
   123         return tree;
       
   124     }
       
   125 
       
   126     public DCDocRoot DocRoot() {
       
   127         DCDocRoot tree = new DCDocRoot();
       
   128         tree.pos = pos;
       
   129         return tree;
       
   130     }
       
   131 
       
   132     public DCEndElement EndElement(Name name) {
       
   133         DCEndElement tree = new DCEndElement(name);
       
   134         tree.pos = pos;
       
   135         return tree;
       
   136     }
       
   137 
       
   138     public DCEntity Entity(Name name) {
       
   139         DCEntity tree = new DCEntity(name);
       
   140         tree.pos = pos;
       
   141         return tree;
       
   142     }
       
   143 
       
   144     public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) {
       
   145         DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
       
   146         tree.pos = pos;
       
   147         return tree;
       
   148     }
       
   149 
       
   150     public DCThrows Exception(DCReference name, List<DCTree> description) {
       
   151         DCThrows tree = new DCThrows(Kind.EXCEPTION, name, description);
       
   152         tree.pos = pos;
       
   153         return tree;
       
   154     }
       
   155 
       
   156     public DCIdentifier Identifier(Name name) {
       
   157         DCIdentifier tree = new DCIdentifier(name);
       
   158         tree.pos = pos;
       
   159         return tree;
       
   160     }
       
   161 
       
   162     public DCInheritDoc InheritDoc() {
       
   163         DCInheritDoc tree = new DCInheritDoc();
       
   164         tree.pos = pos;
       
   165         return tree;
       
   166     }
       
   167 
       
   168     public DCLink Link(DCReference ref, List<DCTree> label) {
       
   169         DCLink tree = new DCLink(Kind.LINK, ref, label);
       
   170         tree.pos = pos;
       
   171         return tree;
       
   172     }
       
   173 
       
   174     public DCLink LinkPlain(DCReference ref, List<DCTree> label) {
       
   175         DCLink tree = new DCLink(Kind.LINK_PLAIN, ref, label);
       
   176         tree.pos = pos;
       
   177         return tree;
       
   178     }
       
   179 
       
   180     public DCLiteral Literal(DCText text) {
       
   181         DCLiteral tree = new DCLiteral(Kind.LITERAL, text);
       
   182         tree.pos = pos;
       
   183         return tree;
       
   184     }
       
   185 
       
   186     public DCParam Param(boolean isTypeParameter, DCIdentifier name, List<DCTree> description) {
       
   187         DCParam tree = new DCParam(isTypeParameter, name, description);
       
   188         tree.pos = pos;
       
   189         return tree;
       
   190     }
       
   191 
       
   192     public DCReference Reference(String signature,
       
   193             JCTree qualExpr, Name member, List<JCTree> paramTypes) {
       
   194         DCReference tree = new DCReference(signature, qualExpr, member, paramTypes);
       
   195         tree.pos = pos;
       
   196         return tree;
       
   197     }
       
   198 
       
   199     public DCReturn Return(List<DCTree> description) {
       
   200         DCReturn tree = new DCReturn(description);
       
   201         tree.pos = pos;
       
   202         return tree;
       
   203     }
       
   204 
       
   205     public DCSee See(List<DCTree> reference) {
       
   206         DCSee tree = new DCSee(reference);
       
   207         tree.pos = pos;
       
   208         return tree;
       
   209     }
       
   210 
       
   211     public DCSerial Serial(List<DCTree> description) {
       
   212         DCSerial tree = new DCSerial(description);
       
   213         tree.pos = pos;
       
   214         return tree;
       
   215     }
       
   216 
       
   217     public DCSerialData SerialData(List<DCTree> description) {
       
   218         DCSerialData tree = new DCSerialData(description);
       
   219         tree.pos = pos;
       
   220         return tree;
       
   221     }
       
   222 
       
   223     public DCSerialField SerialField(DCIdentifier name, DCReference type, List<DCTree> description) {
       
   224         DCSerialField tree = new DCSerialField(name, type, description);
       
   225         tree.pos = pos;
       
   226         return tree;
       
   227     }
       
   228 
       
   229     public DCSince Since(List<DCTree> text) {
       
   230         DCSince tree = new DCSince(text);
       
   231         tree.pos = pos;
       
   232         return tree;
       
   233     }
       
   234 
       
   235     public DCStartElement StartElement(Name name, List<DCTree> attrs, boolean selfClosing) {
       
   236         DCStartElement tree = new DCStartElement(name, attrs, selfClosing);
       
   237         tree.pos = pos;
       
   238         return tree;
       
   239     }
       
   240 
       
   241     public DCText Text(String text) {
       
   242         DCText tree = new DCText(text);
       
   243         tree.pos = pos;
       
   244         return tree;
       
   245     }
       
   246 
       
   247     public DCThrows Throws(DCReference name, List<DCTree> description) {
       
   248         DCThrows tree = new DCThrows(Kind.THROWS, name, description);
       
   249         tree.pos = pos;
       
   250         return tree;
       
   251     }
       
   252 
       
   253     public DCUnknownBlockTag UnknownBlockTag(Name name, List<DCTree> content) {
       
   254         DCUnknownBlockTag tree = new DCUnknownBlockTag(name, content);
       
   255         tree.pos = pos;
       
   256         return tree;
       
   257     }
       
   258 
       
   259     public DCUnknownInlineTag UnknownInlineTag(Name name, List<DCTree> content) {
       
   260         DCUnknownInlineTag tree = new DCUnknownInlineTag(name, content);
       
   261         tree.pos = pos;
       
   262         return tree;
       
   263     }
       
   264 
       
   265     public DCValue Value(DCReference ref) {
       
   266         DCValue tree = new DCValue(ref);
       
   267         tree.pos = pos;
       
   268         return tree;
       
   269     }
       
   270 
       
   271     public DCVersion Version(List<DCTree> text) {
       
   272         DCVersion tree = new DCVersion(text);
       
   273         tree.pos = pos;
       
   274         return tree;
       
   275     }
       
   276 }