aoqi@0: /* aoqi@0: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.javac.tree; aoqi@0: aoqi@0: import com.sun.source.doctree.AttributeTree.ValueKind; aoqi@0: import com.sun.source.doctree.DocTree.Kind; aoqi@0: aoqi@0: import com.sun.tools.javac.parser.Tokens.Comment; aoqi@0: import com.sun.tools.javac.tree.DCTree.*; aoqi@0: import com.sun.tools.javac.util.Context; aoqi@0: import com.sun.tools.javac.util.DiagnosticSource; aoqi@0: import com.sun.tools.javac.util.JCDiagnostic; aoqi@0: import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; aoqi@0: import com.sun.tools.javac.util.List; aoqi@0: import com.sun.tools.javac.util.Name; aoqi@0: import com.sun.tools.javac.util.Position; aoqi@0: aoqi@0: /** aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: */ aoqi@0: public class DocTreeMaker { aoqi@0: aoqi@0: /** The context key for the tree factory. */ aoqi@0: protected static final Context.Key treeMakerKey = aoqi@0: new Context.Key(); aoqi@0: aoqi@0: /** Get the TreeMaker instance. */ aoqi@0: public static DocTreeMaker instance(Context context) { aoqi@0: DocTreeMaker instance = context.get(treeMakerKey); aoqi@0: if (instance == null) aoqi@0: instance = new DocTreeMaker(context); aoqi@0: return instance; aoqi@0: } aoqi@0: aoqi@0: /** The position at which subsequent trees will be created. aoqi@0: */ aoqi@0: public int pos = Position.NOPOS; aoqi@0: aoqi@0: /** Access to diag factory for ErroneousTrees. */ aoqi@0: private final JCDiagnostic.Factory diags; aoqi@0: aoqi@0: /** Create a tree maker with NOPOS as initial position. aoqi@0: */ aoqi@0: protected DocTreeMaker(Context context) { aoqi@0: context.put(treeMakerKey, this); aoqi@0: diags = JCDiagnostic.Factory.instance(context); aoqi@0: this.pos = Position.NOPOS; aoqi@0: } aoqi@0: aoqi@0: /** Reassign current position. aoqi@0: */ aoqi@0: public DocTreeMaker at(int pos) { aoqi@0: this.pos = pos; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: /** Reassign current position. aoqi@0: */ aoqi@0: public DocTreeMaker at(DiagnosticPosition pos) { aoqi@0: this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public DCAttribute Attribute(Name name, ValueKind vkind, List value) { aoqi@0: DCAttribute tree = new DCAttribute(name, vkind, value); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCAuthor Author(List name) { aoqi@0: DCAuthor tree = new DCAuthor(name); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCLiteral Code(DCText text) { aoqi@0: DCLiteral tree = new DCLiteral(Kind.CODE, text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCComment Comment(String text) { aoqi@0: DCComment tree = new DCComment(text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCDeprecated Deprecated(List text) { aoqi@0: DCDeprecated tree = new DCDeprecated(text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCDocComment DocComment(Comment comment, List firstSentence, List body, List tags) { aoqi@0: DCDocComment tree = new DCDocComment(comment, firstSentence, body, tags); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCDocRoot DocRoot() { aoqi@0: DCDocRoot tree = new DCDocRoot(); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCEndElement EndElement(Name name) { aoqi@0: DCEndElement tree = new DCEndElement(name); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCEntity Entity(Name name) { aoqi@0: DCEntity tree = new DCEntity(name); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) { aoqi@0: DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCThrows Exception(DCReference name, List description) { aoqi@0: DCThrows tree = new DCThrows(Kind.EXCEPTION, name, description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCIdentifier Identifier(Name name) { aoqi@0: DCIdentifier tree = new DCIdentifier(name); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCInheritDoc InheritDoc() { aoqi@0: DCInheritDoc tree = new DCInheritDoc(); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCLink Link(DCReference ref, List label) { aoqi@0: DCLink tree = new DCLink(Kind.LINK, ref, label); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCLink LinkPlain(DCReference ref, List label) { aoqi@0: DCLink tree = new DCLink(Kind.LINK_PLAIN, ref, label); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCLiteral Literal(DCText text) { aoqi@0: DCLiteral tree = new DCLiteral(Kind.LITERAL, text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCParam Param(boolean isTypeParameter, DCIdentifier name, List description) { aoqi@0: DCParam tree = new DCParam(isTypeParameter, name, description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCReference Reference(String signature, aoqi@0: JCTree qualExpr, Name member, List paramTypes) { aoqi@0: DCReference tree = new DCReference(signature, qualExpr, member, paramTypes); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCReturn Return(List description) { aoqi@0: DCReturn tree = new DCReturn(description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCSee See(List reference) { aoqi@0: DCSee tree = new DCSee(reference); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCSerial Serial(List description) { aoqi@0: DCSerial tree = new DCSerial(description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCSerialData SerialData(List description) { aoqi@0: DCSerialData tree = new DCSerialData(description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCSerialField SerialField(DCIdentifier name, DCReference type, List description) { aoqi@0: DCSerialField tree = new DCSerialField(name, type, description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCSince Since(List text) { aoqi@0: DCSince tree = new DCSince(text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCStartElement StartElement(Name name, List attrs, boolean selfClosing) { aoqi@0: DCStartElement tree = new DCStartElement(name, attrs, selfClosing); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCText Text(String text) { aoqi@0: DCText tree = new DCText(text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCThrows Throws(DCReference name, List description) { aoqi@0: DCThrows tree = new DCThrows(Kind.THROWS, name, description); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCUnknownBlockTag UnknownBlockTag(Name name, List content) { aoqi@0: DCUnknownBlockTag tree = new DCUnknownBlockTag(name, content); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCUnknownInlineTag UnknownInlineTag(Name name, List content) { aoqi@0: DCUnknownInlineTag tree = new DCUnknownInlineTag(name, content); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCValue Value(DCReference ref) { aoqi@0: DCValue tree = new DCValue(ref); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: aoqi@0: public DCVersion Version(List text) { aoqi@0: DCVersion tree = new DCVersion(text); aoqi@0: tree.pos = pos; aoqi@0: return tree; aoqi@0: } aoqi@0: }