feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
883
jdkSrc/jdk8/com/sun/tools/javac/tree/DCTree.java
Normal file
883
jdkSrc/jdk8/com/sun/tools/javac/tree/DCTree.java
Normal file
@@ -0,0 +1,883 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||
import com.sun.tools.javac.util.Assert;
|
||||
import com.sun.tools.javac.util.DiagnosticSource;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public abstract class DCTree implements DocTree {
|
||||
|
||||
/**
|
||||
* The position in the comment string.
|
||||
* Use {@link #getSourcePosition getSourcePosition} to convert
|
||||
* it to a position in the source file.
|
||||
*
|
||||
* TODO: why not simply translate all these values into
|
||||
* source file positions? Is it useful to have string-offset
|
||||
* positions as well?
|
||||
*/
|
||||
public int pos;
|
||||
|
||||
public long getSourcePosition(DCDocComment dc) {
|
||||
return dc.comment.getSourcePos(pos);
|
||||
}
|
||||
|
||||
public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) {
|
||||
return new SimpleDiagnosticPosition(dc.comment.getSourcePos(pos));
|
||||
}
|
||||
|
||||
/** Convert a tree to a pretty-printed string. */
|
||||
@Override
|
||||
public String toString() {
|
||||
StringWriter s = new StringWriter();
|
||||
try {
|
||||
new DocPretty(s).print(this);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// should never happen, because StringWriter is defined
|
||||
// never to throw any IOExceptions
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public static abstract class DCEndPosTree<T extends DCEndPosTree<T>> extends DCTree {
|
||||
|
||||
private int endPos = Position.NOPOS;
|
||||
|
||||
public int getEndPos(DCDocComment dc) {
|
||||
return dc.comment.getSourcePos(endPos);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T setEndPos(int endPos) {
|
||||
this.endPos = endPos;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DCDocComment extends DCTree implements DocCommentTree {
|
||||
public final Comment comment; // required for the implicit source pos table
|
||||
|
||||
public final List<DCTree> firstSentence;
|
||||
public final List<DCTree> body;
|
||||
public final List<DCTree> tags;
|
||||
|
||||
public DCDocComment(Comment comment,
|
||||
List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
|
||||
this.comment = comment;
|
||||
this.firstSentence = firstSentence;
|
||||
this.body = body;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public Kind getKind() {
|
||||
return Kind.DOC_COMMENT;
|
||||
}
|
||||
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitDocComment(this, d);
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getFirstSentence() {
|
||||
return firstSentence;
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static abstract class DCBlockTag extends DCTree implements BlockTagTree {
|
||||
public String getTagName() {
|
||||
return getKind().tagName;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class DCInlineTag extends DCEndPosTree<DCInlineTag> implements InlineTagTree {
|
||||
public String getTagName() {
|
||||
return getKind().tagName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCAttribute extends DCTree implements AttributeTree {
|
||||
public final Name name;
|
||||
public final ValueKind vkind;
|
||||
public final List<DCTree> value;
|
||||
|
||||
DCAttribute(Name name, ValueKind vkind, List<DCTree> value) {
|
||||
Assert.check((vkind == ValueKind.EMPTY) ? (value == null) : (value != null));
|
||||
this.name = name;
|
||||
this.vkind = vkind;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.ATTRIBUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitAttribute(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueKind getValueKind() {
|
||||
return vkind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DCTree> getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCAuthor extends DCBlockTag implements AuthorTree {
|
||||
public final List<DCTree> name;
|
||||
|
||||
DCAuthor(List<DCTree> name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.AUTHOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitAuthor(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCComment extends DCTree implements CommentTree {
|
||||
public final String body;
|
||||
|
||||
DCComment(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitComment(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCDeprecated extends DCBlockTag implements DeprecatedTree {
|
||||
public final List<DCTree> body;
|
||||
|
||||
DCDeprecated(List<DCTree> body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.DEPRECATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitDeprecated(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCDocRoot extends DCInlineTag implements DocRootTree {
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.DOC_ROOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitDocRoot(this, d);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCEndElement extends DCTree implements EndElementTree {
|
||||
public final Name name;
|
||||
|
||||
DCEndElement(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.END_ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitEndElement(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCEntity extends DCTree implements EntityTree {
|
||||
public final Name name;
|
||||
|
||||
DCEntity(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.ENTITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitEntity(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCErroneous extends DCTree implements ErroneousTree, JCDiagnostic.DiagnosticPosition {
|
||||
public final String body;
|
||||
public final JCDiagnostic diag;
|
||||
|
||||
DCErroneous(String body, JCDiagnostic.Factory diags, DiagnosticSource diagSource, String code, Object... args) {
|
||||
this.body = body;
|
||||
this.diag = diags.error(diagSource, this, code, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.ERRONEOUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitErroneous(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Diagnostic<JavaFileObject> getDiagnostic() {
|
||||
return diag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JCTree getTree() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreferredPosition() {
|
||||
return pos + body.length() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEndPosition(EndPosTable endPosTable) {
|
||||
return pos + body.length();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DCIdentifier extends DCTree implements IdentifierTree {
|
||||
public final Name name;
|
||||
|
||||
DCIdentifier(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitIdentifier(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCInheritDoc extends DCInlineTag implements InheritDocTree {
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.INHERIT_DOC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitInheritDoc(this, d);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCLink extends DCInlineTag implements LinkTree {
|
||||
public final Kind kind;
|
||||
public final DCReference ref;
|
||||
public final List<DCTree> label;
|
||||
|
||||
DCLink(Kind kind, DCReference ref, List<DCTree> label) {
|
||||
Assert.check(kind == Kind.LINK || kind == Kind.LINK_PLAIN);
|
||||
this.kind = kind;
|
||||
this.ref = ref;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitLink(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceTree getReference() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getLabel() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCLiteral extends DCInlineTag implements LiteralTree {
|
||||
public final Kind kind;
|
||||
public final DCText body;
|
||||
|
||||
DCLiteral(Kind kind, DCText body) {
|
||||
Assert.check(kind == Kind.CODE || kind == Kind.LITERAL);
|
||||
this.kind = kind;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitLiteral(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DCText getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCParam extends DCBlockTag implements ParamTree {
|
||||
public final boolean isTypeParameter;
|
||||
public final DCIdentifier name;
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCParam(boolean isTypeParameter, DCIdentifier name, List<DCTree> description) {
|
||||
this.isTypeParameter = isTypeParameter;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.PARAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitParam(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypeParameter() {
|
||||
return isTypeParameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCReference extends DCEndPosTree<DCReference> implements ReferenceTree {
|
||||
public final String signature;
|
||||
|
||||
// The following are not directly exposed through ReferenceTree
|
||||
// use DocTrees.getElement(TreePath,ReferenceTree)
|
||||
public final JCTree qualifierExpression;
|
||||
public final Name memberName;
|
||||
public final List<JCTree> paramTypes;
|
||||
|
||||
|
||||
DCReference(String signature, JCTree qualExpr, Name member, List<JCTree> paramTypes) {
|
||||
this.signature = signature;
|
||||
qualifierExpression = qualExpr;
|
||||
memberName = member;
|
||||
this.paramTypes = paramTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.REFERENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitReference(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCReturn extends DCBlockTag implements ReturnTree {
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCReturn(List<DCTree> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.RETURN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitReturn(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCSee extends DCBlockTag implements SeeTree {
|
||||
public final List<DCTree> reference;
|
||||
|
||||
DCSee(List<DCTree> reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitSee(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getReference() {
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCSerial extends DCBlockTag implements SerialTree {
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCSerial(List<DCTree> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SERIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitSerial(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCSerialData extends DCBlockTag implements SerialDataTree {
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCSerialData(List<DCTree> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SERIAL_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitSerialData(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCSerialField extends DCBlockTag implements SerialFieldTree {
|
||||
public final DCIdentifier name;
|
||||
public final DCReference type;
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCSerialField(DCIdentifier name, DCReference type, List<DCTree> description) {
|
||||
this.description = description;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SERIAL_FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitSerialField(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceTree getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCSince extends DCBlockTag implements SinceTree {
|
||||
public final List<DCTree> body;
|
||||
|
||||
DCSince(List<DCTree> body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SINCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitSince(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCStartElement extends DCEndPosTree<DCStartElement> implements StartElementTree {
|
||||
public final Name name;
|
||||
public final List<DCTree> attrs;
|
||||
public final boolean selfClosing;
|
||||
|
||||
DCStartElement(Name name, List<DCTree> attrs, boolean selfClosing) {
|
||||
this.name = name;
|
||||
this.attrs = attrs;
|
||||
this.selfClosing = selfClosing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.START_ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitStartElement(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getAttributes() {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelfClosing() {
|
||||
return selfClosing;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCText extends DCTree implements TextTree {
|
||||
public final String text;
|
||||
|
||||
DCText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.TEXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitText(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCThrows extends DCBlockTag implements ThrowsTree {
|
||||
public final Kind kind;
|
||||
public final DCReference name;
|
||||
public final List<DCTree> description;
|
||||
|
||||
DCThrows(Kind kind, DCReference name, List<DCTree> description) {
|
||||
Assert.check(kind == Kind.EXCEPTION || kind == Kind.THROWS);
|
||||
this.kind = kind;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitThrows(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceTree getExceptionName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCUnknownBlockTag extends DCBlockTag implements UnknownBlockTagTree {
|
||||
public final Name name;
|
||||
public final List<DCTree> content;
|
||||
|
||||
DCUnknownBlockTag(Name name, List<DCTree> content) {
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.UNKNOWN_BLOCK_TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitUnknownBlockTag(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTagName() {
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCUnknownInlineTag extends DCInlineTag implements UnknownInlineTagTree {
|
||||
public final Name name;
|
||||
public final List<DCTree> content;
|
||||
|
||||
DCUnknownInlineTag(Name name, List<DCTree> content) {
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.UNKNOWN_INLINE_TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitUnknownInlineTag(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTagName() {
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCValue extends DCInlineTag implements ValueTree {
|
||||
public final DCReference ref;
|
||||
|
||||
DCValue(DCReference ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitValue(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceTree getReference() {
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCVersion extends DCBlockTag implements VersionTree {
|
||||
public final List<DCTree> body;
|
||||
|
||||
DCVersion(List<DCTree> body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DocTreeVisitor<R, D> v, D d) {
|
||||
return v.visitVersion(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends DocTree> getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
jdkSrc/jdk8/com/sun/tools/javac/tree/DocCommentTable.java
Normal file
66
jdkSrc/jdk8/com/sun/tools/javac/tree/DocCommentTable.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.source.doctree.ErroneousTree;
|
||||
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||
import com.sun.tools.javac.tree.DCTree.DCDocComment;
|
||||
|
||||
/**
|
||||
* A table giving the doc comment, if any, for any tree node.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own
|
||||
* risk. This code and its internal interfaces are subject to change
|
||||
* or deletion without notice.</b>
|
||||
*/
|
||||
public interface DocCommentTable {
|
||||
/**
|
||||
* Check if a tree node has a corresponding doc comment.
|
||||
*/
|
||||
public boolean hasComment(JCTree tree);
|
||||
|
||||
/**
|
||||
* Get the Comment token containing the doc comment, if any, for a tree node.
|
||||
*/
|
||||
public Comment getComment(JCTree tree);
|
||||
|
||||
/**
|
||||
* Get the plain text of the doc comment, if any, for a tree node.
|
||||
*/
|
||||
public String getCommentText(JCTree tree);
|
||||
|
||||
/**
|
||||
* Get the parsed form of the doc comment as a DocTree. If any errors
|
||||
* are detected during parsing, they will be reported via
|
||||
* {@link ErroneousTree ErroneousTree} nodes within the resulting tree.
|
||||
*/
|
||||
public DCDocComment getCommentTree(JCTree tree);
|
||||
|
||||
/**
|
||||
* Set the Comment to be associated with a tree node.
|
||||
*/
|
||||
public void putComment(JCTree tree, Comment c);
|
||||
}
|
520
jdkSrc/jdk8/com/sun/tools/javac/tree/DocPretty.java
Normal file
520
jdkSrc/jdk8/com/sun/tools/javac/tree/DocPretty.java
Normal file
@@ -0,0 +1,520 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
import com.sun.source.doctree.AttributeTree.ValueKind;
|
||||
import com.sun.tools.javac.util.Convert;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Prints out a doc comment tree.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class DocPretty implements DocTreeVisitor<Void,Void> {
|
||||
|
||||
/**
|
||||
* The output stream on which trees are printed.
|
||||
*/
|
||||
final Writer out;
|
||||
|
||||
/**
|
||||
* The left margin.
|
||||
*/
|
||||
int lmargin = 0;
|
||||
|
||||
public DocPretty(Writer out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
/** Visitor method: print expression tree.
|
||||
*/
|
||||
public void print(DocTree tree) throws IOException {
|
||||
try {
|
||||
if (tree == null)
|
||||
print("/*missing*/");
|
||||
else {
|
||||
tree.accept(this, null);
|
||||
}
|
||||
} catch (UncheckedIOException ex) {
|
||||
throw new IOException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print string, replacing all non-ascii character with unicode escapes.
|
||||
*/
|
||||
protected void print(Object s) throws IOException {
|
||||
out.write(Convert.escapeUnicode(s.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print list.
|
||||
*/
|
||||
public void print(List<? extends DocTree> list) throws IOException {
|
||||
for (DocTree t: list) {
|
||||
print(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print list., with separators
|
||||
*/
|
||||
protected void print(List<? extends DocTree> list, String sep) throws IOException {
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
boolean first = true;
|
||||
for (DocTree t: list) {
|
||||
if (!first)
|
||||
print(sep);
|
||||
print(t);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Print new line.
|
||||
*/
|
||||
protected void println() throws IOException {
|
||||
out.write(lineSep);
|
||||
}
|
||||
|
||||
protected void printTagName(DocTree node) throws IOException {
|
||||
out.write("@");
|
||||
out.write(node.getKind().tagName);
|
||||
}
|
||||
|
||||
final String lineSep = System.getProperty("line.separator");
|
||||
|
||||
/**************************************************************************
|
||||
* Traversal methods
|
||||
*************************************************************************/
|
||||
|
||||
/** Exception to propagate IOException through visitXXX methods */
|
||||
private static class UncheckedIOException extends Error {
|
||||
static final long serialVersionUID = -4032692679158424751L;
|
||||
UncheckedIOException(IOException e) {
|
||||
super(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Void visitAttribute(AttributeTree node, Void p) {
|
||||
try {
|
||||
print(node.getName());
|
||||
String quote;
|
||||
switch (node.getValueKind()) {
|
||||
case EMPTY:
|
||||
quote = null;
|
||||
break;
|
||||
case UNQUOTED:
|
||||
quote = "";
|
||||
break;
|
||||
case SINGLE:
|
||||
quote = "'";
|
||||
break;
|
||||
case DOUBLE:
|
||||
quote = "\"";
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
if (quote != null) {
|
||||
print("=" + quote);
|
||||
print(node.getValue());
|
||||
print(quote);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitAuthor(AuthorTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getName());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitComment(CommentTree node, Void p) {
|
||||
try {
|
||||
print(node.getBody());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitDeprecated(DeprecatedTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
if (!node.getBody().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitDocComment(DocCommentTree node, Void p) {
|
||||
try {
|
||||
List<? extends DocTree> fs = node.getFirstSentence();
|
||||
List<? extends DocTree> b = node.getBody();
|
||||
List<? extends DocTree> t = node.getBlockTags();
|
||||
print(fs);
|
||||
if (!fs.isEmpty() && !b.isEmpty())
|
||||
print(" ");
|
||||
print(b);
|
||||
if ((!fs.isEmpty() || !b.isEmpty()) && !t.isEmpty())
|
||||
print("\n");
|
||||
print(t, "\n");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitDocRoot(DocRootTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
printTagName(node);
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitEndElement(EndElementTree node, Void p) {
|
||||
try {
|
||||
print("</");
|
||||
print(node.getName());
|
||||
print(">");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitEntity(EntityTree node, Void p) {
|
||||
try {
|
||||
print("&");
|
||||
print(node.getName());
|
||||
print(";");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitErroneous(ErroneousTree node, Void p) {
|
||||
try {
|
||||
print(node.getBody());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitIdentifier(IdentifierTree node, Void p) {
|
||||
try {
|
||||
print(node.getName());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitInheritDoc(InheritDocTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
printTagName(node);
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitLink(LinkTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getReference());
|
||||
if (!node.getLabel().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getLabel());
|
||||
}
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitLiteral(LiteralTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getBody());
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitParam(ParamTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
if (node.isTypeParameter()) print("<");
|
||||
print(node.getName());
|
||||
if (node.isTypeParameter()) print(">");
|
||||
if (!node.getDescription().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitReference(ReferenceTree node, Void p) {
|
||||
try {
|
||||
print(node.getSignature());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitReturn(ReturnTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitSee(SeeTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
boolean first = true;
|
||||
boolean needSep = true;
|
||||
for (DocTree t: node.getReference()) {
|
||||
if (needSep) print(" ");
|
||||
needSep = (first && (t instanceof ReferenceTree));
|
||||
first = false;
|
||||
print(t);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitSerial(SerialTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
if (!node.getDescription().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitSerialData(SerialDataTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
if (!node.getDescription().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitSerialField(SerialFieldTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getName());
|
||||
print(" ");
|
||||
print(node.getType());
|
||||
if (!node.getDescription().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitSince(SinceTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getBody());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitStartElement(StartElementTree node, Void p) {
|
||||
try {
|
||||
print("<");
|
||||
print(node.getName());
|
||||
List<? extends DocTree> attrs = node.getAttributes();
|
||||
if (!attrs.isEmpty()) {
|
||||
print(" ");
|
||||
print(attrs);
|
||||
DocTree last = node.getAttributes().get(attrs.size() - 1);
|
||||
if (node.isSelfClosing() && last instanceof AttributeTree
|
||||
&& ((AttributeTree) last).getValueKind() == ValueKind.UNQUOTED)
|
||||
print(" ");
|
||||
}
|
||||
if (node.isSelfClosing())
|
||||
print("/");
|
||||
print(">");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitText(TextTree node, Void p) {
|
||||
try {
|
||||
print(node.getBody());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitThrows(ThrowsTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getExceptionName());
|
||||
if (!node.getDescription().isEmpty()) {
|
||||
print(" ");
|
||||
print(node.getDescription());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
|
||||
try {
|
||||
print("@");
|
||||
print(node.getTagName());
|
||||
print(" ");
|
||||
print(node.getContent());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
print("@");
|
||||
print(node.getTagName());
|
||||
print(" ");
|
||||
print(node.getContent());
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitValue(ValueTree node, Void p) {
|
||||
try {
|
||||
print("{");
|
||||
printTagName(node);
|
||||
if (node.getReference() != null) {
|
||||
print(" ");
|
||||
print(node.getReference());
|
||||
}
|
||||
print("}");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitVersion(VersionTree node, Void p) {
|
||||
try {
|
||||
printTagName(node);
|
||||
print(" ");
|
||||
print(node.getBody());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitOther(DocTree node, Void p) {
|
||||
try {
|
||||
print("(UNKNOWN: " + node + ")");
|
||||
println();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
277
jdkSrc/jdk8/com/sun/tools/javac/tree/DocTreeMaker.java
Normal file
277
jdkSrc/jdk8/com/sun/tools/javac/tree/DocTreeMaker.java
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.source.doctree.AttributeTree.ValueKind;
|
||||
import com.sun.source.doctree.DocTree.Kind;
|
||||
|
||||
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||
import com.sun.tools.javac.tree.DCTree.*;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.DiagnosticSource;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class DocTreeMaker {
|
||||
|
||||
/** The context key for the tree factory. */
|
||||
protected static final Context.Key<DocTreeMaker> treeMakerKey =
|
||||
new Context.Key<DocTreeMaker>();
|
||||
|
||||
/** Get the TreeMaker instance. */
|
||||
public static DocTreeMaker instance(Context context) {
|
||||
DocTreeMaker instance = context.get(treeMakerKey);
|
||||
if (instance == null)
|
||||
instance = new DocTreeMaker(context);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The position at which subsequent trees will be created.
|
||||
*/
|
||||
public int pos = Position.NOPOS;
|
||||
|
||||
/** Access to diag factory for ErroneousTrees. */
|
||||
private final JCDiagnostic.Factory diags;
|
||||
|
||||
/** Create a tree maker with NOPOS as initial position.
|
||||
*/
|
||||
protected DocTreeMaker(Context context) {
|
||||
context.put(treeMakerKey, this);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
this.pos = Position.NOPOS;
|
||||
}
|
||||
|
||||
/** Reassign current position.
|
||||
*/
|
||||
public DocTreeMaker at(int pos) {
|
||||
this.pos = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Reassign current position.
|
||||
*/
|
||||
public DocTreeMaker at(DiagnosticPosition pos) {
|
||||
this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
|
||||
return this;
|
||||
}
|
||||
|
||||
public DCAttribute Attribute(Name name, ValueKind vkind, List<DCTree> value) {
|
||||
DCAttribute tree = new DCAttribute(name, vkind, value);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCAuthor Author(List<DCTree> name) {
|
||||
DCAuthor tree = new DCAuthor(name);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCLiteral Code(DCText text) {
|
||||
DCLiteral tree = new DCLiteral(Kind.CODE, text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCComment Comment(String text) {
|
||||
DCComment tree = new DCComment(text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCDeprecated Deprecated(List<DCTree> text) {
|
||||
DCDeprecated tree = new DCDeprecated(text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCDocComment DocComment(Comment comment, List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
|
||||
DCDocComment tree = new DCDocComment(comment, firstSentence, body, tags);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCDocRoot DocRoot() {
|
||||
DCDocRoot tree = new DCDocRoot();
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCEndElement EndElement(Name name) {
|
||||
DCEndElement tree = new DCEndElement(name);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCEntity Entity(Name name) {
|
||||
DCEntity tree = new DCEntity(name);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) {
|
||||
DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCThrows Exception(DCReference name, List<DCTree> description) {
|
||||
DCThrows tree = new DCThrows(Kind.EXCEPTION, name, description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCIdentifier Identifier(Name name) {
|
||||
DCIdentifier tree = new DCIdentifier(name);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCInheritDoc InheritDoc() {
|
||||
DCInheritDoc tree = new DCInheritDoc();
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCLink Link(DCReference ref, List<DCTree> label) {
|
||||
DCLink tree = new DCLink(Kind.LINK, ref, label);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCLink LinkPlain(DCReference ref, List<DCTree> label) {
|
||||
DCLink tree = new DCLink(Kind.LINK_PLAIN, ref, label);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCLiteral Literal(DCText text) {
|
||||
DCLiteral tree = new DCLiteral(Kind.LITERAL, text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCParam Param(boolean isTypeParameter, DCIdentifier name, List<DCTree> description) {
|
||||
DCParam tree = new DCParam(isTypeParameter, name, description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCReference Reference(String signature,
|
||||
JCTree qualExpr, Name member, List<JCTree> paramTypes) {
|
||||
DCReference tree = new DCReference(signature, qualExpr, member, paramTypes);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCReturn Return(List<DCTree> description) {
|
||||
DCReturn tree = new DCReturn(description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCSee See(List<DCTree> reference) {
|
||||
DCSee tree = new DCSee(reference);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCSerial Serial(List<DCTree> description) {
|
||||
DCSerial tree = new DCSerial(description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCSerialData SerialData(List<DCTree> description) {
|
||||
DCSerialData tree = new DCSerialData(description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCSerialField SerialField(DCIdentifier name, DCReference type, List<DCTree> description) {
|
||||
DCSerialField tree = new DCSerialField(name, type, description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCSince Since(List<DCTree> text) {
|
||||
DCSince tree = new DCSince(text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCStartElement StartElement(Name name, List<DCTree> attrs, boolean selfClosing) {
|
||||
DCStartElement tree = new DCStartElement(name, attrs, selfClosing);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCText Text(String text) {
|
||||
DCText tree = new DCText(text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCThrows Throws(DCReference name, List<DCTree> description) {
|
||||
DCThrows tree = new DCThrows(Kind.THROWS, name, description);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCUnknownBlockTag UnknownBlockTag(Name name, List<DCTree> content) {
|
||||
DCUnknownBlockTag tree = new DCUnknownBlockTag(name, content);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCUnknownInlineTag UnknownInlineTag(Name name, List<DCTree> content) {
|
||||
DCUnknownInlineTag tree = new DCUnknownInlineTag(name, content);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCValue Value(DCReference ref) {
|
||||
DCValue tree = new DCValue(ref);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public DCVersion Version(List<DCTree> text) {
|
||||
DCVersion tree = new DCVersion(text);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
}
|
62
jdkSrc/jdk8/com/sun/tools/javac/tree/EndPosTable.java
Normal file
62
jdkSrc/jdk8/com/sun/tools/javac/tree/EndPosTable.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
/**
|
||||
* Specifies the methods to access a mappings of syntax trees to end positions.
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own
|
||||
* risk. This code and its internal interfaces are subject to change
|
||||
* or deletion without notice.</b></p>
|
||||
*/
|
||||
public interface EndPosTable {
|
||||
|
||||
/**
|
||||
* This method will return the end position of a given tree, otherwise a
|
||||
* Positions.NOPOS will be returned.
|
||||
* @param tree JCTree
|
||||
* @return position of the source tree or Positions.NOPOS for non-existent mapping
|
||||
*/
|
||||
public int getEndPos(JCTree tree);
|
||||
|
||||
/**
|
||||
* Store ending position for a tree, the value of which is the greater of
|
||||
* last error position and the given ending position.
|
||||
* @param tree The tree.
|
||||
* @param endpos The ending position to associate with the tree.
|
||||
*/
|
||||
public abstract void storeEnd(JCTree tree, int endpos);
|
||||
|
||||
/**
|
||||
* Give an old tree and a new tree, the old tree will be replaced with
|
||||
* the new tree, the position of the new tree will be that of the old
|
||||
* tree.
|
||||
* @param oldtree a JCTree to be replaced
|
||||
* @param newtree a JCTree to be replaced with
|
||||
* @return position of the old tree or Positions.NOPOS for non-existent mapping
|
||||
*/
|
||||
public int replaceTree(JCTree oldtree, JCTree newtree);
|
||||
}
|
2591
jdkSrc/jdk8/com/sun/tools/javac/tree/JCTree.java
Normal file
2591
jdkSrc/jdk8/com/sun/tools/javac/tree/JCTree.java
Normal file
File diff suppressed because it is too large
Load Diff
1409
jdkSrc/jdk8/com/sun/tools/javac/tree/Pretty.java
Normal file
1409
jdkSrc/jdk8/com/sun/tools/javac/tree/Pretty.java
Normal file
File diff suppressed because it is too large
Load Diff
462
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeCopier.java
Normal file
462
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeCopier.java
Normal file
@@ -0,0 +1,462 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
|
||||
/**
|
||||
* Creates a copy of a tree, using a given TreeMaker.
|
||||
* Names, literal values, etc are shared with the original.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
|
||||
private TreeMaker M;
|
||||
|
||||
/** Creates a new instance of TreeCopier */
|
||||
public TreeCopier(TreeMaker M) {
|
||||
this.M = M;
|
||||
}
|
||||
|
||||
public <T extends JCTree> T copy(T tree) {
|
||||
return copy(tree, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends JCTree> T copy(T tree, P p) {
|
||||
if (tree == null)
|
||||
return null;
|
||||
return (T) (tree.accept(this, p));
|
||||
}
|
||||
|
||||
public <T extends JCTree> List<T> copy(List<T> trees) {
|
||||
return copy(trees, null);
|
||||
}
|
||||
|
||||
public <T extends JCTree> List<T> copy(List<T> trees, P p) {
|
||||
if (trees == null)
|
||||
return null;
|
||||
ListBuffer<T> lb = new ListBuffer<T>();
|
||||
for (T tree: trees)
|
||||
lb.append(copy(tree, p));
|
||||
return lb.toList();
|
||||
}
|
||||
|
||||
public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) {
|
||||
JCAnnotatedType t = (JCAnnotatedType) node;
|
||||
List<JCAnnotation> annotations = copy(t.annotations, p);
|
||||
JCExpression underlyingType = copy(t.underlyingType, p);
|
||||
return M.at(t.pos).AnnotatedType(annotations, underlyingType);
|
||||
}
|
||||
|
||||
public JCTree visitAnnotation(AnnotationTree node, P p) {
|
||||
JCAnnotation t = (JCAnnotation) node;
|
||||
JCTree annotationType = copy(t.annotationType, p);
|
||||
List<JCExpression> args = copy(t.args, p);
|
||||
if (t.getKind() == Tree.Kind.TYPE_ANNOTATION) {
|
||||
JCAnnotation newTA = M.at(t.pos).TypeAnnotation(annotationType, args);
|
||||
newTA.attribute = t.attribute;
|
||||
return newTA;
|
||||
} else {
|
||||
JCAnnotation newT = M.at(t.pos).Annotation(annotationType, args);
|
||||
newT.attribute = t.attribute;
|
||||
return newT;
|
||||
}
|
||||
}
|
||||
|
||||
public JCTree visitAssert(AssertTree node, P p) {
|
||||
JCAssert t = (JCAssert) node;
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
JCExpression detail = copy(t.detail, p);
|
||||
return M.at(t.pos).Assert(cond, detail);
|
||||
}
|
||||
|
||||
public JCTree visitAssignment(AssignmentTree node, P p) {
|
||||
JCAssign t = (JCAssign) node;
|
||||
JCExpression lhs = copy(t.lhs, p);
|
||||
JCExpression rhs = copy(t.rhs, p);
|
||||
return M.at(t.pos).Assign(lhs, rhs);
|
||||
}
|
||||
|
||||
public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
|
||||
JCAssignOp t = (JCAssignOp) node;
|
||||
JCTree lhs = copy(t.lhs, p);
|
||||
JCTree rhs = copy(t.rhs, p);
|
||||
return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
|
||||
}
|
||||
|
||||
public JCTree visitBinary(BinaryTree node, P p) {
|
||||
JCBinary t = (JCBinary) node;
|
||||
JCExpression lhs = copy(t.lhs, p);
|
||||
JCExpression rhs = copy(t.rhs, p);
|
||||
return M.at(t.pos).Binary(t.getTag(), lhs, rhs);
|
||||
}
|
||||
|
||||
public JCTree visitBlock(BlockTree node, P p) {
|
||||
JCBlock t = (JCBlock) node;
|
||||
List<JCStatement> stats = copy(t.stats, p);
|
||||
return M.at(t.pos).Block(t.flags, stats);
|
||||
}
|
||||
|
||||
public JCTree visitBreak(BreakTree node, P p) {
|
||||
JCBreak t = (JCBreak) node;
|
||||
return M.at(t.pos).Break(t.label);
|
||||
}
|
||||
|
||||
public JCTree visitCase(CaseTree node, P p) {
|
||||
JCCase t = (JCCase) node;
|
||||
JCExpression pat = copy(t.pat, p);
|
||||
List<JCStatement> stats = copy(t.stats, p);
|
||||
return M.at(t.pos).Case(pat, stats);
|
||||
}
|
||||
|
||||
public JCTree visitCatch(CatchTree node, P p) {
|
||||
JCCatch t = (JCCatch) node;
|
||||
JCVariableDecl param = copy(t.param, p);
|
||||
JCBlock body = copy(t.body, p);
|
||||
return M.at(t.pos).Catch(param, body);
|
||||
}
|
||||
|
||||
public JCTree visitClass(ClassTree node, P p) {
|
||||
JCClassDecl t = (JCClassDecl) node;
|
||||
JCModifiers mods = copy(t.mods, p);
|
||||
List<JCTypeParameter> typarams = copy(t.typarams, p);
|
||||
JCExpression extending = copy(t.extending, p);
|
||||
List<JCExpression> implementing = copy(t.implementing, p);
|
||||
List<JCTree> defs = copy(t.defs, p);
|
||||
return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
|
||||
}
|
||||
|
||||
public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
|
||||
JCConditional t = (JCConditional) node;
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
JCExpression truepart = copy(t.truepart, p);
|
||||
JCExpression falsepart = copy(t.falsepart, p);
|
||||
return M.at(t.pos).Conditional(cond, truepart, falsepart);
|
||||
}
|
||||
|
||||
public JCTree visitContinue(ContinueTree node, P p) {
|
||||
JCContinue t = (JCContinue) node;
|
||||
return M.at(t.pos).Continue(t.label);
|
||||
}
|
||||
|
||||
public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
|
||||
JCDoWhileLoop t = (JCDoWhileLoop) node;
|
||||
JCStatement body = copy(t.body, p);
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
return M.at(t.pos).DoLoop(body, cond);
|
||||
}
|
||||
|
||||
public JCTree visitErroneous(ErroneousTree node, P p) {
|
||||
JCErroneous t = (JCErroneous) node;
|
||||
List<? extends JCTree> errs = copy(t.errs, p);
|
||||
return M.at(t.pos).Erroneous(errs);
|
||||
}
|
||||
|
||||
public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
|
||||
JCExpressionStatement t = (JCExpressionStatement) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
return M.at(t.pos).Exec(expr);
|
||||
}
|
||||
|
||||
public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
|
||||
JCEnhancedForLoop t = (JCEnhancedForLoop) node;
|
||||
JCVariableDecl var = copy(t.var, p);
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
JCStatement body = copy(t.body, p);
|
||||
return M.at(t.pos).ForeachLoop(var, expr, body);
|
||||
}
|
||||
|
||||
public JCTree visitForLoop(ForLoopTree node, P p) {
|
||||
JCForLoop t = (JCForLoop) node;
|
||||
List<JCStatement> init = copy(t.init, p);
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
List<JCExpressionStatement> step = copy(t.step, p);
|
||||
JCStatement body = copy(t.body, p);
|
||||
return M.at(t.pos).ForLoop(init, cond, step, body);
|
||||
}
|
||||
|
||||
public JCTree visitIdentifier(IdentifierTree node, P p) {
|
||||
JCIdent t = (JCIdent) node;
|
||||
return M.at(t.pos).Ident(t.name);
|
||||
}
|
||||
|
||||
public JCTree visitIf(IfTree node, P p) {
|
||||
JCIf t = (JCIf) node;
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
JCStatement thenpart = copy(t.thenpart, p);
|
||||
JCStatement elsepart = copy(t.elsepart, p);
|
||||
return M.at(t.pos).If(cond, thenpart, elsepart);
|
||||
}
|
||||
|
||||
public JCTree visitImport(ImportTree node, P p) {
|
||||
JCImport t = (JCImport) node;
|
||||
JCTree qualid = copy(t.qualid, p);
|
||||
return M.at(t.pos).Import(qualid, t.staticImport);
|
||||
}
|
||||
|
||||
public JCTree visitArrayAccess(ArrayAccessTree node, P p) {
|
||||
JCArrayAccess t = (JCArrayAccess) node;
|
||||
JCExpression indexed = copy(t.indexed, p);
|
||||
JCExpression index = copy(t.index, p);
|
||||
return M.at(t.pos).Indexed(indexed, index);
|
||||
}
|
||||
|
||||
public JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
|
||||
JCLabeledStatement t = (JCLabeledStatement) node;
|
||||
JCStatement body = copy(t.body, p);
|
||||
return M.at(t.pos).Labelled(t.label, body);
|
||||
}
|
||||
|
||||
public JCTree visitLiteral(LiteralTree node, P p) {
|
||||
JCLiteral t = (JCLiteral) node;
|
||||
return M.at(t.pos).Literal(t.typetag, t.value);
|
||||
}
|
||||
|
||||
public JCTree visitMethod(MethodTree node, P p) {
|
||||
JCMethodDecl t = (JCMethodDecl) node;
|
||||
JCModifiers mods = copy(t.mods, p);
|
||||
JCExpression restype = copy(t.restype, p);
|
||||
List<JCTypeParameter> typarams = copy(t.typarams, p);
|
||||
List<JCVariableDecl> params = copy(t.params, p);
|
||||
JCVariableDecl recvparam = copy(t.recvparam, p);
|
||||
List<JCExpression> thrown = copy(t.thrown, p);
|
||||
JCBlock body = copy(t.body, p);
|
||||
JCExpression defaultValue = copy(t.defaultValue, p);
|
||||
return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue);
|
||||
}
|
||||
|
||||
public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
|
||||
JCMethodInvocation t = (JCMethodInvocation) node;
|
||||
List<JCExpression> typeargs = copy(t.typeargs, p);
|
||||
JCExpression meth = copy(t.meth, p);
|
||||
List<JCExpression> args = copy(t.args, p);
|
||||
return M.at(t.pos).Apply(typeargs, meth, args);
|
||||
}
|
||||
|
||||
public JCTree visitModifiers(ModifiersTree node, P p) {
|
||||
JCModifiers t = (JCModifiers) node;
|
||||
List<JCAnnotation> annotations = copy(t.annotations, p);
|
||||
return M.at(t.pos).Modifiers(t.flags, annotations);
|
||||
}
|
||||
|
||||
public JCTree visitNewArray(NewArrayTree node, P p) {
|
||||
JCNewArray t = (JCNewArray) node;
|
||||
JCExpression elemtype = copy(t.elemtype, p);
|
||||
List<JCExpression> dims = copy(t.dims, p);
|
||||
List<JCExpression> elems = copy(t.elems, p);
|
||||
return M.at(t.pos).NewArray(elemtype, dims, elems);
|
||||
}
|
||||
|
||||
public JCTree visitNewClass(NewClassTree node, P p) {
|
||||
JCNewClass t = (JCNewClass) node;
|
||||
JCExpression encl = copy(t.encl, p);
|
||||
List<JCExpression> typeargs = copy(t.typeargs, p);
|
||||
JCExpression clazz = copy(t.clazz, p);
|
||||
List<JCExpression> args = copy(t.args, p);
|
||||
JCClassDecl def = copy(t.def, p);
|
||||
return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
|
||||
}
|
||||
|
||||
public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
|
||||
JCLambda t = (JCLambda) node;
|
||||
List<JCVariableDecl> params = copy(t.params, p);
|
||||
JCTree body = copy(t.body, p);
|
||||
return M.at(t.pos).Lambda(params, body);
|
||||
}
|
||||
|
||||
public JCTree visitParenthesized(ParenthesizedTree node, P p) {
|
||||
JCParens t = (JCParens) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
return M.at(t.pos).Parens(expr);
|
||||
}
|
||||
|
||||
public JCTree visitReturn(ReturnTree node, P p) {
|
||||
JCReturn t = (JCReturn) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
return M.at(t.pos).Return(expr);
|
||||
}
|
||||
|
||||
public JCTree visitMemberSelect(MemberSelectTree node, P p) {
|
||||
JCFieldAccess t = (JCFieldAccess) node;
|
||||
JCExpression selected = copy(t.selected, p);
|
||||
return M.at(t.pos).Select(selected, t.name);
|
||||
}
|
||||
|
||||
public JCTree visitMemberReference(MemberReferenceTree node, P p) {
|
||||
JCMemberReference t = (JCMemberReference) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
List<JCExpression> typeargs = copy(t.typeargs, p);
|
||||
return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs);
|
||||
}
|
||||
|
||||
public JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
|
||||
JCSkip t = (JCSkip) node;
|
||||
return M.at(t.pos).Skip();
|
||||
}
|
||||
|
||||
public JCTree visitSwitch(SwitchTree node, P p) {
|
||||
JCSwitch t = (JCSwitch) node;
|
||||
JCExpression selector = copy(t.selector, p);
|
||||
List<JCCase> cases = copy(t.cases, p);
|
||||
return M.at(t.pos).Switch(selector, cases);
|
||||
}
|
||||
|
||||
public JCTree visitSynchronized(SynchronizedTree node, P p) {
|
||||
JCSynchronized t = (JCSynchronized) node;
|
||||
JCExpression lock = copy(t.lock, p);
|
||||
JCBlock body = copy(t.body, p);
|
||||
return M.at(t.pos).Synchronized(lock, body);
|
||||
}
|
||||
|
||||
public JCTree visitThrow(ThrowTree node, P p) {
|
||||
JCThrow t = (JCThrow) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
return M.at(t.pos).Throw(expr);
|
||||
}
|
||||
|
||||
public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
|
||||
JCCompilationUnit t = (JCCompilationUnit) node;
|
||||
List<JCAnnotation> packageAnnotations = copy(t.packageAnnotations, p);
|
||||
JCExpression pid = copy(t.pid, p);
|
||||
List<JCTree> defs = copy(t.defs, p);
|
||||
return M.at(t.pos).TopLevel(packageAnnotations, pid, defs);
|
||||
}
|
||||
|
||||
public JCTree visitTry(TryTree node, P p) {
|
||||
JCTry t = (JCTry) node;
|
||||
List<JCTree> resources = copy(t.resources, p);
|
||||
JCBlock body = copy(t.body, p);
|
||||
List<JCCatch> catchers = copy(t.catchers, p);
|
||||
JCBlock finalizer = copy(t.finalizer, p);
|
||||
return M.at(t.pos).Try(resources, body, catchers, finalizer);
|
||||
}
|
||||
|
||||
public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
|
||||
JCTypeApply t = (JCTypeApply) node;
|
||||
JCExpression clazz = copy(t.clazz, p);
|
||||
List<JCExpression> arguments = copy(t.arguments, p);
|
||||
return M.at(t.pos).TypeApply(clazz, arguments);
|
||||
}
|
||||
|
||||
public JCTree visitUnionType(UnionTypeTree node, P p) {
|
||||
JCTypeUnion t = (JCTypeUnion) node;
|
||||
List<JCExpression> components = copy(t.alternatives, p);
|
||||
return M.at(t.pos).TypeUnion(components);
|
||||
}
|
||||
|
||||
public JCTree visitIntersectionType(IntersectionTypeTree node, P p) {
|
||||
JCTypeIntersection t = (JCTypeIntersection) node;
|
||||
List<JCExpression> bounds = copy(t.bounds, p);
|
||||
return M.at(t.pos).TypeIntersection(bounds);
|
||||
}
|
||||
|
||||
public JCTree visitArrayType(ArrayTypeTree node, P p) {
|
||||
JCArrayTypeTree t = (JCArrayTypeTree) node;
|
||||
JCExpression elemtype = copy(t.elemtype, p);
|
||||
return M.at(t.pos).TypeArray(elemtype);
|
||||
}
|
||||
|
||||
public JCTree visitTypeCast(TypeCastTree node, P p) {
|
||||
JCTypeCast t = (JCTypeCast) node;
|
||||
JCTree clazz = copy(t.clazz, p);
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
return M.at(t.pos).TypeCast(clazz, expr);
|
||||
}
|
||||
|
||||
public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
|
||||
JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
|
||||
return M.at(t.pos).TypeIdent(t.typetag);
|
||||
}
|
||||
|
||||
public JCTree visitTypeParameter(TypeParameterTree node, P p) {
|
||||
JCTypeParameter t = (JCTypeParameter) node;
|
||||
List<JCAnnotation> annos = copy(t.annotations, p);
|
||||
List<JCExpression> bounds = copy(t.bounds, p);
|
||||
return M.at(t.pos).TypeParameter(t.name, bounds, annos);
|
||||
}
|
||||
|
||||
public JCTree visitInstanceOf(InstanceOfTree node, P p) {
|
||||
JCInstanceOf t = (JCInstanceOf) node;
|
||||
JCExpression expr = copy(t.expr, p);
|
||||
JCTree clazz = copy(t.clazz, p);
|
||||
return M.at(t.pos).TypeTest(expr, clazz);
|
||||
}
|
||||
|
||||
public JCTree visitUnary(UnaryTree node, P p) {
|
||||
JCUnary t = (JCUnary) node;
|
||||
JCExpression arg = copy(t.arg, p);
|
||||
return M.at(t.pos).Unary(t.getTag(), arg);
|
||||
}
|
||||
|
||||
public JCTree visitVariable(VariableTree node, P p) {
|
||||
JCVariableDecl t = (JCVariableDecl) node;
|
||||
JCModifiers mods = copy(t.mods, p);
|
||||
JCExpression vartype = copy(t.vartype, p);
|
||||
if (t.nameexpr == null) {
|
||||
JCExpression init = copy(t.init, p);
|
||||
return M.at(t.pos).VarDef(mods, t.name, vartype, init);
|
||||
} else {
|
||||
JCExpression nameexpr = copy(t.nameexpr, p);
|
||||
return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
|
||||
}
|
||||
}
|
||||
|
||||
public JCTree visitWhileLoop(WhileLoopTree node, P p) {
|
||||
JCWhileLoop t = (JCWhileLoop) node;
|
||||
JCStatement body = copy(t.body, p);
|
||||
JCExpression cond = copy(t.cond, p);
|
||||
return M.at(t.pos).WhileLoop(cond, body);
|
||||
}
|
||||
|
||||
public JCTree visitWildcard(WildcardTree node, P p) {
|
||||
JCWildcard t = (JCWildcard) node;
|
||||
TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
|
||||
JCTree inner = copy(t.inner, p);
|
||||
return M.at(t.pos).Wildcard(kind, inner);
|
||||
}
|
||||
|
||||
public JCTree visitOther(Tree node, P p) {
|
||||
JCTree tree = (JCTree) node;
|
||||
switch (tree.getTag()) {
|
||||
case LETEXPR: {
|
||||
LetExpr t = (LetExpr) node;
|
||||
List<JCVariableDecl> defs = copy(t.defs, p);
|
||||
JCTree expr = copy(t.expr, p);
|
||||
return M.at(t.pos).LetExpr(defs, expr);
|
||||
}
|
||||
default:
|
||||
throw new AssertionError("unknown tree tag: " + tree.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1187
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeInfo.java
Normal file
1187
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeInfo.java
Normal file
File diff suppressed because it is too large
Load Diff
989
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeMaker.java
Normal file
989
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeMaker.java
Normal file
@@ -0,0 +1,989 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type.*;
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
|
||||
import static com.sun.tools.javac.code.Flags.*;
|
||||
import static com.sun.tools.javac.code.Kinds.*;
|
||||
import static com.sun.tools.javac.code.TypeTag.*;
|
||||
|
||||
/** Factory class for trees.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class TreeMaker implements JCTree.Factory {
|
||||
|
||||
/** The context key for the tree factory. */
|
||||
protected static final Context.Key<TreeMaker> treeMakerKey =
|
||||
new Context.Key<TreeMaker>();
|
||||
|
||||
/** Get the TreeMaker instance. */
|
||||
public static TreeMaker instance(Context context) {
|
||||
TreeMaker instance = context.get(treeMakerKey);
|
||||
if (instance == null)
|
||||
instance = new TreeMaker(context);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The position at which subsequent trees will be created.
|
||||
*/
|
||||
public int pos = Position.NOPOS;
|
||||
|
||||
/** The toplevel tree to which created trees belong.
|
||||
*/
|
||||
public JCCompilationUnit toplevel;
|
||||
|
||||
/** The current name table. */
|
||||
Names names;
|
||||
|
||||
Types types;
|
||||
|
||||
/** The current symbol table. */
|
||||
Symtab syms;
|
||||
|
||||
/** Create a tree maker with null toplevel and NOPOS as initial position.
|
||||
*/
|
||||
protected TreeMaker(Context context) {
|
||||
context.put(treeMakerKey, this);
|
||||
this.pos = Position.NOPOS;
|
||||
this.toplevel = null;
|
||||
this.names = Names.instance(context);
|
||||
this.syms = Symtab.instance(context);
|
||||
this.types = Types.instance(context);
|
||||
}
|
||||
|
||||
/** Create a tree maker with a given toplevel and FIRSTPOS as initial position.
|
||||
*/
|
||||
protected TreeMaker(JCCompilationUnit toplevel, Names names, Types types, Symtab syms) {
|
||||
this.pos = Position.FIRSTPOS;
|
||||
this.toplevel = toplevel;
|
||||
this.names = names;
|
||||
this.types = types;
|
||||
this.syms = syms;
|
||||
}
|
||||
|
||||
/** Create a new tree maker for a given toplevel.
|
||||
*/
|
||||
public TreeMaker forToplevel(JCCompilationUnit toplevel) {
|
||||
return new TreeMaker(toplevel, names, types, syms);
|
||||
}
|
||||
|
||||
/** Reassign current position.
|
||||
*/
|
||||
public TreeMaker at(int pos) {
|
||||
this.pos = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Reassign current position.
|
||||
*/
|
||||
public TreeMaker at(DiagnosticPosition pos) {
|
||||
this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create given tree node at current position.
|
||||
* @param defs a list of ClassDef, Import, and Skip
|
||||
*/
|
||||
public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations,
|
||||
JCExpression pid,
|
||||
List<JCTree> defs) {
|
||||
Assert.checkNonNull(packageAnnotations);
|
||||
for (JCTree node : defs)
|
||||
Assert.check(node instanceof JCClassDecl
|
||||
|| node instanceof JCImport
|
||||
|| node instanceof JCSkip
|
||||
|| node instanceof JCErroneous
|
||||
|| (node instanceof JCExpressionStatement
|
||||
&& ((JCExpressionStatement)node).expr instanceof JCErroneous),
|
||||
node.getClass().getSimpleName());
|
||||
JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs,
|
||||
null, null, null, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCImport Import(JCTree qualid, boolean importStatic) {
|
||||
JCImport tree = new JCImport(qualid, importStatic);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCClassDecl ClassDef(JCModifiers mods,
|
||||
Name name,
|
||||
List<JCTypeParameter> typarams,
|
||||
JCExpression extending,
|
||||
List<JCExpression> implementing,
|
||||
List<JCTree> defs)
|
||||
{
|
||||
JCClassDecl tree = new JCClassDecl(mods,
|
||||
name,
|
||||
typarams,
|
||||
extending,
|
||||
implementing,
|
||||
defs,
|
||||
null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCMethodDecl MethodDef(JCModifiers mods,
|
||||
Name name,
|
||||
JCExpression restype,
|
||||
List<JCTypeParameter> typarams,
|
||||
List<JCVariableDecl> params,
|
||||
List<JCExpression> thrown,
|
||||
JCBlock body,
|
||||
JCExpression defaultValue) {
|
||||
return MethodDef(
|
||||
mods, name, restype, typarams, null, params,
|
||||
thrown, body, defaultValue);
|
||||
}
|
||||
|
||||
public JCMethodDecl MethodDef(JCModifiers mods,
|
||||
Name name,
|
||||
JCExpression restype,
|
||||
List<JCTypeParameter> typarams,
|
||||
JCVariableDecl recvparam,
|
||||
List<JCVariableDecl> params,
|
||||
List<JCExpression> thrown,
|
||||
JCBlock body,
|
||||
JCExpression defaultValue)
|
||||
{
|
||||
JCMethodDecl tree = new JCMethodDecl(mods,
|
||||
name,
|
||||
restype,
|
||||
typarams,
|
||||
recvparam,
|
||||
params,
|
||||
thrown,
|
||||
body,
|
||||
defaultValue,
|
||||
null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init) {
|
||||
JCVariableDecl tree = new JCVariableDecl(mods, name, vartype, init, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCVariableDecl ReceiverVarDef(JCModifiers mods, JCExpression name, JCExpression vartype) {
|
||||
JCVariableDecl tree = new JCVariableDecl(mods, name, vartype);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCSkip Skip() {
|
||||
JCSkip tree = new JCSkip();
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCBlock Block(long flags, List<JCStatement> stats) {
|
||||
JCBlock tree = new JCBlock(flags, stats);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) {
|
||||
JCDoWhileLoop tree = new JCDoWhileLoop(body, cond);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) {
|
||||
JCWhileLoop tree = new JCWhileLoop(cond, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCForLoop ForLoop(List<JCStatement> init,
|
||||
JCExpression cond,
|
||||
List<JCExpressionStatement> step,
|
||||
JCStatement body)
|
||||
{
|
||||
JCForLoop tree = new JCForLoop(init, cond, step, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
|
||||
JCEnhancedForLoop tree = new JCEnhancedForLoop(var, expr, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCLabeledStatement Labelled(Name label, JCStatement body) {
|
||||
JCLabeledStatement tree = new JCLabeledStatement(label, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
|
||||
JCSwitch tree = new JCSwitch(selector, cases);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCCase Case(JCExpression pat, List<JCStatement> stats) {
|
||||
JCCase tree = new JCCase(pat, stats);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
|
||||
JCSynchronized tree = new JCSynchronized(lock, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
|
||||
return Try(List.<JCTree>nil(), body, catchers, finalizer);
|
||||
}
|
||||
|
||||
public JCTry Try(List<JCTree> resources,
|
||||
JCBlock body,
|
||||
List<JCCatch> catchers,
|
||||
JCBlock finalizer) {
|
||||
JCTry tree = new JCTry(resources, body, catchers, finalizer);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCCatch Catch(JCVariableDecl param, JCBlock body) {
|
||||
JCCatch tree = new JCCatch(param, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCConditional Conditional(JCExpression cond,
|
||||
JCExpression thenpart,
|
||||
JCExpression elsepart)
|
||||
{
|
||||
JCConditional tree = new JCConditional(cond, thenpart, elsepart);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart) {
|
||||
JCIf tree = new JCIf(cond, thenpart, elsepart);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCExpressionStatement Exec(JCExpression expr) {
|
||||
JCExpressionStatement tree = new JCExpressionStatement(expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCBreak Break(Name label) {
|
||||
JCBreak tree = new JCBreak(label, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCContinue Continue(Name label) {
|
||||
JCContinue tree = new JCContinue(label, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCReturn Return(JCExpression expr) {
|
||||
JCReturn tree = new JCReturn(expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCThrow Throw(JCExpression expr) {
|
||||
JCThrow tree = new JCThrow(expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCAssert Assert(JCExpression cond, JCExpression detail) {
|
||||
JCAssert tree = new JCAssert(cond, detail);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCMethodInvocation Apply(List<JCExpression> typeargs,
|
||||
JCExpression fn,
|
||||
List<JCExpression> args)
|
||||
{
|
||||
JCMethodInvocation tree = new JCMethodInvocation(typeargs, fn, args);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCNewClass NewClass(JCExpression encl,
|
||||
List<JCExpression> typeargs,
|
||||
JCExpression clazz,
|
||||
List<JCExpression> args,
|
||||
JCClassDecl def)
|
||||
{
|
||||
JCNewClass tree = new JCNewClass(encl, typeargs, clazz, args, def);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCNewArray NewArray(JCExpression elemtype,
|
||||
List<JCExpression> dims,
|
||||
List<JCExpression> elems)
|
||||
{
|
||||
JCNewArray tree = new JCNewArray(elemtype, dims, elems);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCLambda Lambda(List<JCVariableDecl> params,
|
||||
JCTree body)
|
||||
{
|
||||
JCLambda tree = new JCLambda(params, body);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCParens Parens(JCExpression expr) {
|
||||
JCParens tree = new JCParens(expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCAssign Assign(JCExpression lhs, JCExpression rhs) {
|
||||
JCAssign tree = new JCAssign(lhs, rhs);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCAssignOp Assignop(JCTree.Tag opcode, JCTree lhs, JCTree rhs) {
|
||||
JCAssignOp tree = new JCAssignOp(opcode, lhs, rhs, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCUnary Unary(JCTree.Tag opcode, JCExpression arg) {
|
||||
JCUnary tree = new JCUnary(opcode, arg);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCBinary Binary(JCTree.Tag opcode, JCExpression lhs, JCExpression rhs) {
|
||||
JCBinary tree = new JCBinary(opcode, lhs, rhs, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTypeCast TypeCast(JCTree clazz, JCExpression expr) {
|
||||
JCTypeCast tree = new JCTypeCast(clazz, expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCInstanceOf TypeTest(JCExpression expr, JCTree clazz) {
|
||||
JCInstanceOf tree = new JCInstanceOf(expr, clazz);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCArrayAccess Indexed(JCExpression indexed, JCExpression index) {
|
||||
JCArrayAccess tree = new JCArrayAccess(indexed, index);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCFieldAccess Select(JCExpression selected, Name selector) {
|
||||
JCFieldAccess tree = new JCFieldAccess(selected, selector, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCMemberReference Reference(JCMemberReference.ReferenceMode mode, Name name,
|
||||
JCExpression expr, List<JCExpression> typeargs) {
|
||||
JCMemberReference tree = new JCMemberReference(mode, name, expr, typeargs);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCIdent Ident(Name name) {
|
||||
JCIdent tree = new JCIdent(name, null);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCLiteral Literal(TypeTag tag, Object value) {
|
||||
JCLiteral tree = new JCLiteral(tag, value);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCPrimitiveTypeTree TypeIdent(TypeTag typetag) {
|
||||
JCPrimitiveTypeTree tree = new JCPrimitiveTypeTree(typetag);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCArrayTypeTree TypeArray(JCExpression elemtype) {
|
||||
JCArrayTypeTree tree = new JCArrayTypeTree(elemtype);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) {
|
||||
JCTypeApply tree = new JCTypeApply(clazz, arguments);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTypeUnion TypeUnion(List<JCExpression> components) {
|
||||
JCTypeUnion tree = new JCTypeUnion(components);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTypeIntersection TypeIntersection(List<JCExpression> components) {
|
||||
JCTypeIntersection tree = new JCTypeIntersection(components);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds) {
|
||||
return TypeParameter(name, bounds, List.<JCAnnotation>nil());
|
||||
}
|
||||
|
||||
public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annos) {
|
||||
JCTypeParameter tree = new JCTypeParameter(name, bounds, annos);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCWildcard Wildcard(TypeBoundKind kind, JCTree type) {
|
||||
JCWildcard tree = new JCWildcard(kind, type);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public TypeBoundKind TypeBoundKind(BoundKind kind) {
|
||||
TypeBoundKind tree = new TypeBoundKind(kind);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args) {
|
||||
JCAnnotation tree = new JCAnnotation(Tag.ANNOTATION, annotationType, args);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCAnnotation TypeAnnotation(JCTree annotationType, List<JCExpression> args) {
|
||||
JCAnnotation tree = new JCAnnotation(Tag.TYPE_ANNOTATION, annotationType, args);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCModifiers Modifiers(long flags, List<JCAnnotation> annotations) {
|
||||
JCModifiers tree = new JCModifiers(flags, annotations);
|
||||
boolean noFlags = (flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0;
|
||||
tree.pos = (noFlags && annotations.isEmpty()) ? Position.NOPOS : pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCModifiers Modifiers(long flags) {
|
||||
return Modifiers(flags, List.<JCAnnotation>nil());
|
||||
}
|
||||
|
||||
public JCAnnotatedType AnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
|
||||
JCAnnotatedType tree = new JCAnnotatedType(annotations, underlyingType);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCErroneous Erroneous() {
|
||||
return Erroneous(List.<JCTree>nil());
|
||||
}
|
||||
|
||||
public JCErroneous Erroneous(List<? extends JCTree> errs) {
|
||||
JCErroneous tree = new JCErroneous(errs);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
public LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr) {
|
||||
LetExpr tree = new LetExpr(defs, expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* ***************************************************************************
|
||||
* Derived building blocks.
|
||||
****************************************************************************/
|
||||
|
||||
public JCClassDecl AnonymousClassDef(JCModifiers mods,
|
||||
List<JCTree> defs)
|
||||
{
|
||||
return ClassDef(mods,
|
||||
names.empty,
|
||||
List.<JCTypeParameter>nil(),
|
||||
null,
|
||||
List.<JCExpression>nil(),
|
||||
defs);
|
||||
}
|
||||
|
||||
public LetExpr LetExpr(JCVariableDecl def, JCTree expr) {
|
||||
LetExpr tree = new LetExpr(List.of(def), expr);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
}
|
||||
|
||||
/** Create an identifier from a symbol.
|
||||
*/
|
||||
public JCIdent Ident(Symbol sym) {
|
||||
return (JCIdent)new JCIdent((sym.name != names.empty)
|
||||
? sym.name
|
||||
: sym.flatName(), sym)
|
||||
.setPos(pos)
|
||||
.setType(sym.type);
|
||||
}
|
||||
|
||||
/** Create a selection node from a qualifier tree and a symbol.
|
||||
* @param base The qualifier tree.
|
||||
*/
|
||||
public JCExpression Select(JCExpression base, Symbol sym) {
|
||||
return new JCFieldAccess(base, sym.name, sym).setPos(pos).setType(sym.type);
|
||||
}
|
||||
|
||||
/** Create a qualified identifier from a symbol, adding enough qualifications
|
||||
* to make the reference unique.
|
||||
*/
|
||||
public JCExpression QualIdent(Symbol sym) {
|
||||
return isUnqualifiable(sym)
|
||||
? Ident(sym)
|
||||
: Select(QualIdent(sym.owner), sym);
|
||||
}
|
||||
|
||||
/** Create an identifier that refers to the variable declared in given variable
|
||||
* declaration.
|
||||
*/
|
||||
public JCExpression Ident(JCVariableDecl param) {
|
||||
return Ident(param.sym);
|
||||
}
|
||||
|
||||
/** Create a list of identifiers referring to the variables declared
|
||||
* in given list of variable declarations.
|
||||
*/
|
||||
public List<JCExpression> Idents(List<JCVariableDecl> params) {
|
||||
ListBuffer<JCExpression> ids = new ListBuffer<JCExpression>();
|
||||
for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail)
|
||||
ids.append(Ident(l.head));
|
||||
return ids.toList();
|
||||
}
|
||||
|
||||
/** Create a tree representing `this', given its type.
|
||||
*/
|
||||
public JCExpression This(Type t) {
|
||||
return Ident(new VarSymbol(FINAL, names._this, t, t.tsym));
|
||||
}
|
||||
|
||||
/** Create a tree representing qualified `this' given its type
|
||||
*/
|
||||
public JCExpression QualThis(Type t) {
|
||||
return Select(Type(t), new VarSymbol(FINAL, names._this, t, t.tsym));
|
||||
}
|
||||
|
||||
/** Create a tree representing a class literal.
|
||||
*/
|
||||
public JCExpression ClassLiteral(ClassSymbol clazz) {
|
||||
return ClassLiteral(clazz.type);
|
||||
}
|
||||
|
||||
/** Create a tree representing a class literal.
|
||||
*/
|
||||
public JCExpression ClassLiteral(Type t) {
|
||||
VarSymbol lit = new VarSymbol(STATIC | PUBLIC | FINAL,
|
||||
names._class,
|
||||
t,
|
||||
t.tsym);
|
||||
return Select(Type(t), lit);
|
||||
}
|
||||
|
||||
/** Create a tree representing `super', given its type and owner.
|
||||
*/
|
||||
public JCIdent Super(Type t, TypeSymbol owner) {
|
||||
return Ident(new VarSymbol(FINAL, names._super, t, owner));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a method invocation from a method tree and a list of
|
||||
* argument trees.
|
||||
*/
|
||||
public JCMethodInvocation App(JCExpression meth, List<JCExpression> args) {
|
||||
return Apply(null, meth, args).setType(meth.type.getReturnType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a no-arg method invocation from a method tree
|
||||
*/
|
||||
public JCMethodInvocation App(JCExpression meth) {
|
||||
return Apply(null, meth, List.<JCExpression>nil()).setType(meth.type.getReturnType());
|
||||
}
|
||||
|
||||
/** Create a method invocation from a method tree and a list of argument trees.
|
||||
*/
|
||||
public JCExpression Create(Symbol ctor, List<JCExpression> args) {
|
||||
Type t = ctor.owner.erasure(types);
|
||||
JCNewClass newclass = NewClass(null, null, Type(t), args, null);
|
||||
newclass.constructor = ctor;
|
||||
newclass.setType(t);
|
||||
return newclass;
|
||||
}
|
||||
|
||||
/** Create a tree representing given type.
|
||||
*/
|
||||
public JCExpression Type(Type t) {
|
||||
if (t == null) return null;
|
||||
JCExpression tp;
|
||||
switch (t.getTag()) {
|
||||
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
|
||||
case DOUBLE: case BOOLEAN: case VOID:
|
||||
tp = TypeIdent(t.getTag());
|
||||
break;
|
||||
case TYPEVAR:
|
||||
tp = Ident(t.tsym);
|
||||
break;
|
||||
case WILDCARD: {
|
||||
WildcardType a = ((WildcardType) t);
|
||||
tp = Wildcard(TypeBoundKind(a.kind), Type(a.type));
|
||||
break;
|
||||
}
|
||||
case CLASS:
|
||||
Type outer = t.getEnclosingType();
|
||||
JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
|
||||
? Select(Type(outer), t.tsym)
|
||||
: QualIdent(t.tsym);
|
||||
tp = t.getTypeArguments().isEmpty()
|
||||
? clazz
|
||||
: TypeApply(clazz, Types(t.getTypeArguments()));
|
||||
break;
|
||||
case ARRAY:
|
||||
tp = TypeArray(Type(types.elemtype(t)));
|
||||
break;
|
||||
case ERROR:
|
||||
tp = TypeIdent(ERROR);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("unexpected type: " + t);
|
||||
}
|
||||
return tp.setType(t);
|
||||
}
|
||||
|
||||
/** Create a list of trees representing given list of types.
|
||||
*/
|
||||
public List<JCExpression> Types(List<Type> ts) {
|
||||
ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>();
|
||||
for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
|
||||
lb.append(Type(l.head));
|
||||
return lb.toList();
|
||||
}
|
||||
|
||||
/** Create a variable definition from a variable symbol and an initializer
|
||||
* expression.
|
||||
*/
|
||||
public JCVariableDecl VarDef(VarSymbol v, JCExpression init) {
|
||||
return (JCVariableDecl)
|
||||
new JCVariableDecl(
|
||||
Modifiers(v.flags(), Annotations(v.getRawAttributes())),
|
||||
v.name,
|
||||
Type(v.type),
|
||||
init,
|
||||
v).setPos(pos).setType(v.type);
|
||||
}
|
||||
|
||||
/** Create annotation trees from annotations.
|
||||
*/
|
||||
public List<JCAnnotation> Annotations(List<Attribute.Compound> attributes) {
|
||||
if (attributes == null) return List.nil();
|
||||
ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
|
||||
for (List<Attribute.Compound> i = attributes; i.nonEmpty(); i=i.tail) {
|
||||
Attribute a = i.head;
|
||||
result.append(Annotation(a));
|
||||
}
|
||||
return result.toList();
|
||||
}
|
||||
|
||||
public JCLiteral Literal(Object value) {
|
||||
JCLiteral result = null;
|
||||
if (value instanceof String) {
|
||||
result = Literal(CLASS, value).
|
||||
setType(syms.stringType.constType(value));
|
||||
} else if (value instanceof Integer) {
|
||||
result = Literal(INT, value).
|
||||
setType(syms.intType.constType(value));
|
||||
} else if (value instanceof Long) {
|
||||
result = Literal(LONG, value).
|
||||
setType(syms.longType.constType(value));
|
||||
} else if (value instanceof Byte) {
|
||||
result = Literal(BYTE, value).
|
||||
setType(syms.byteType.constType(value));
|
||||
} else if (value instanceof Character) {
|
||||
int v = (int) (((Character) value).toString().charAt(0));
|
||||
result = Literal(CHAR, value).
|
||||
setType(syms.charType.constType(v));
|
||||
} else if (value instanceof Double) {
|
||||
result = Literal(DOUBLE, value).
|
||||
setType(syms.doubleType.constType(value));
|
||||
} else if (value instanceof Float) {
|
||||
result = Literal(FLOAT, value).
|
||||
setType(syms.floatType.constType(value));
|
||||
} else if (value instanceof Short) {
|
||||
result = Literal(SHORT, value).
|
||||
setType(syms.shortType.constType(value));
|
||||
} else if (value instanceof Boolean) {
|
||||
int v = ((Boolean) value) ? 1 : 0;
|
||||
result = Literal(BOOLEAN, v).
|
||||
setType(syms.booleanType.constType(v));
|
||||
} else {
|
||||
throw new AssertionError(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class AnnotationBuilder implements Attribute.Visitor {
|
||||
JCExpression result = null;
|
||||
public void visitConstant(Attribute.Constant v) {
|
||||
result = Literal(v.type.getTag(), v.value);
|
||||
}
|
||||
public void visitClass(Attribute.Class clazz) {
|
||||
result = ClassLiteral(clazz.classType).setType(syms.classType);
|
||||
}
|
||||
public void visitEnum(Attribute.Enum e) {
|
||||
result = QualIdent(e.value);
|
||||
}
|
||||
public void visitError(Attribute.Error e) {
|
||||
result = Erroneous();
|
||||
}
|
||||
public void visitCompound(Attribute.Compound compound) {
|
||||
if (compound instanceof Attribute.TypeCompound) {
|
||||
result = visitTypeCompoundInternal((Attribute.TypeCompound) compound);
|
||||
} else {
|
||||
result = visitCompoundInternal(compound);
|
||||
}
|
||||
}
|
||||
public JCAnnotation visitCompoundInternal(Attribute.Compound compound) {
|
||||
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
|
||||
for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) {
|
||||
Pair<MethodSymbol,Attribute> pair = values.head;
|
||||
JCExpression valueTree = translate(pair.snd);
|
||||
args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type));
|
||||
}
|
||||
return Annotation(Type(compound.type), args.toList());
|
||||
}
|
||||
public JCAnnotation visitTypeCompoundInternal(Attribute.TypeCompound compound) {
|
||||
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
|
||||
for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) {
|
||||
Pair<MethodSymbol,Attribute> pair = values.head;
|
||||
JCExpression valueTree = translate(pair.snd);
|
||||
args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type));
|
||||
}
|
||||
return TypeAnnotation(Type(compound.type), args.toList());
|
||||
}
|
||||
public void visitArray(Attribute.Array array) {
|
||||
ListBuffer<JCExpression> elems = new ListBuffer<JCExpression>();
|
||||
for (int i = 0; i < array.values.length; i++)
|
||||
elems.append(translate(array.values[i]));
|
||||
result = NewArray(null, List.<JCExpression>nil(), elems.toList()).setType(array.type);
|
||||
}
|
||||
JCExpression translate(Attribute a) {
|
||||
a.accept(this);
|
||||
return result;
|
||||
}
|
||||
JCAnnotation translate(Attribute.Compound a) {
|
||||
return visitCompoundInternal(a);
|
||||
}
|
||||
JCAnnotation translate(Attribute.TypeCompound a) {
|
||||
return visitTypeCompoundInternal(a);
|
||||
}
|
||||
}
|
||||
|
||||
AnnotationBuilder annotationBuilder = new AnnotationBuilder();
|
||||
|
||||
/** Create an annotation tree from an attribute.
|
||||
*/
|
||||
public JCAnnotation Annotation(Attribute a) {
|
||||
return annotationBuilder.translate((Attribute.Compound)a);
|
||||
}
|
||||
|
||||
public JCAnnotation TypeAnnotation(Attribute a) {
|
||||
return annotationBuilder.translate((Attribute.TypeCompound) a);
|
||||
}
|
||||
|
||||
/** Create a method definition from a method symbol and a method body.
|
||||
*/
|
||||
public JCMethodDecl MethodDef(MethodSymbol m, JCBlock body) {
|
||||
return MethodDef(m, m.type, body);
|
||||
}
|
||||
|
||||
/** Create a method definition from a method symbol, method type
|
||||
* and a method body.
|
||||
*/
|
||||
public JCMethodDecl MethodDef(MethodSymbol m, Type mtype, JCBlock body) {
|
||||
return (JCMethodDecl)
|
||||
new JCMethodDecl(
|
||||
Modifiers(m.flags(), Annotations(m.getRawAttributes())),
|
||||
m.name,
|
||||
Type(mtype.getReturnType()),
|
||||
TypeParams(mtype.getTypeArguments()),
|
||||
null, // receiver type
|
||||
Params(mtype.getParameterTypes(), m),
|
||||
Types(mtype.getThrownTypes()),
|
||||
body,
|
||||
null,
|
||||
m).setPos(pos).setType(mtype);
|
||||
}
|
||||
|
||||
/** Create a type parameter tree from its name and type.
|
||||
*/
|
||||
public JCTypeParameter TypeParam(Name name, TypeVar tvar) {
|
||||
return (JCTypeParameter)
|
||||
TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar);
|
||||
}
|
||||
|
||||
/** Create a list of type parameter trees from a list of type variables.
|
||||
*/
|
||||
public List<JCTypeParameter> TypeParams(List<Type> typarams) {
|
||||
ListBuffer<JCTypeParameter> tparams = new ListBuffer<JCTypeParameter>();
|
||||
for (List<Type> l = typarams; l.nonEmpty(); l = l.tail)
|
||||
tparams.append(TypeParam(l.head.tsym.name, (TypeVar)l.head));
|
||||
return tparams.toList();
|
||||
}
|
||||
|
||||
/** Create a value parameter tree from its name, type, and owner.
|
||||
*/
|
||||
public JCVariableDecl Param(Name name, Type argtype, Symbol owner) {
|
||||
return VarDef(new VarSymbol(PARAMETER, name, argtype, owner), null);
|
||||
}
|
||||
|
||||
/** Create a a list of value parameter trees x0, ..., xn from a list of
|
||||
* their types and an their owner.
|
||||
*/
|
||||
public List<JCVariableDecl> Params(List<Type> argtypes, Symbol owner) {
|
||||
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
|
||||
MethodSymbol mth = (owner.kind == MTH) ? ((MethodSymbol)owner) : null;
|
||||
if (mth != null && mth.params != null && argtypes.length() == mth.params.length()) {
|
||||
for (VarSymbol param : ((MethodSymbol)owner).params)
|
||||
params.append(VarDef(param, null));
|
||||
} else {
|
||||
int i = 0;
|
||||
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
|
||||
params.append(Param(paramName(i++), l.head, owner));
|
||||
}
|
||||
return params.toList();
|
||||
}
|
||||
|
||||
/** Wrap a method invocation in an expression statement or return statement,
|
||||
* depending on whether the method invocation expression's type is void.
|
||||
*/
|
||||
public JCStatement Call(JCExpression apply) {
|
||||
return apply.type.hasTag(VOID) ? Exec(apply) : Return(apply);
|
||||
}
|
||||
|
||||
/** Construct an assignment from a variable symbol and a right hand side.
|
||||
*/
|
||||
public JCStatement Assignment(Symbol v, JCExpression rhs) {
|
||||
return Exec(Assign(Ident(v), rhs).setType(v.type));
|
||||
}
|
||||
|
||||
/** Construct an index expression from a variable and an expression.
|
||||
*/
|
||||
public JCArrayAccess Indexed(Symbol v, JCExpression index) {
|
||||
JCArrayAccess tree = new JCArrayAccess(QualIdent(v), index);
|
||||
tree.type = ((ArrayType)v.type).elemtype;
|
||||
return tree;
|
||||
}
|
||||
|
||||
/** Make an attributed type cast expression.
|
||||
*/
|
||||
public JCTypeCast TypeCast(Type type, JCExpression expr) {
|
||||
return (JCTypeCast)TypeCast(Type(type), expr).setType(type);
|
||||
}
|
||||
|
||||
/* ***************************************************************************
|
||||
* Helper methods.
|
||||
****************************************************************************/
|
||||
|
||||
/** Can given symbol be referred to in unqualified form?
|
||||
*/
|
||||
boolean isUnqualifiable(Symbol sym) {
|
||||
if (sym.name == names.empty ||
|
||||
sym.owner == null ||
|
||||
sym.owner == syms.rootPackage ||
|
||||
sym.owner.kind == MTH || sym.owner.kind == VAR) {
|
||||
return true;
|
||||
} else if (sym.kind == TYP && toplevel != null) {
|
||||
Scope.Entry e;
|
||||
e = toplevel.namedImportScope.lookup(sym.name);
|
||||
if (e.scope != null) {
|
||||
return
|
||||
e.sym == sym &&
|
||||
e.next().scope == null;
|
||||
}
|
||||
e = toplevel.packge.members().lookup(sym.name);
|
||||
if (e.scope != null) {
|
||||
return
|
||||
e.sym == sym &&
|
||||
e.next().scope == null;
|
||||
}
|
||||
e = toplevel.starImportScope.lookup(sym.name);
|
||||
if (e.scope != null) {
|
||||
return
|
||||
e.sym == sym &&
|
||||
e.next().scope == null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** The name of synthetic parameter number `i'.
|
||||
*/
|
||||
public Name paramName(int i) { return names.fromString("x" + i); }
|
||||
|
||||
/** The name of synthetic type parameter number `i'.
|
||||
*/
|
||||
public Name typaramName(int i) { return names.fromString("A" + i); }
|
||||
}
|
339
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeScanner.java
Normal file
339
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeScanner.java
Normal file
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
|
||||
/** A subclass of Tree.Visitor, this class defines
|
||||
* a general tree scanner pattern. Translation proceeds recursively in
|
||||
* left-to-right order down a tree. There is one visitor method in this class
|
||||
* for every possible kind of tree node. To obtain a specific
|
||||
* scanner, it suffices to override those visitor methods which
|
||||
* do some interesting work. The scanner class itself takes care of all
|
||||
* navigational aspects.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class TreeScanner extends Visitor {
|
||||
|
||||
/** Visitor method: Scan a single node.
|
||||
*/
|
||||
public void scan(JCTree tree) {
|
||||
if(tree!=null) tree.accept(this);
|
||||
}
|
||||
|
||||
/** Visitor method: scan a list of nodes.
|
||||
*/
|
||||
public void scan(List<? extends JCTree> trees) {
|
||||
if (trees != null)
|
||||
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
|
||||
scan(l.head);
|
||||
}
|
||||
|
||||
|
||||
/* ***************************************************************************
|
||||
* Visitor methods
|
||||
****************************************************************************/
|
||||
|
||||
public void visitTopLevel(JCCompilationUnit tree) {
|
||||
scan(tree.packageAnnotations);
|
||||
scan(tree.pid);
|
||||
scan(tree.defs);
|
||||
}
|
||||
|
||||
public void visitImport(JCImport tree) {
|
||||
scan(tree.qualid);
|
||||
}
|
||||
|
||||
public void visitClassDef(JCClassDecl tree) {
|
||||
scan(tree.mods);
|
||||
scan(tree.typarams);
|
||||
scan(tree.extending);
|
||||
scan(tree.implementing);
|
||||
scan(tree.defs);
|
||||
}
|
||||
|
||||
public void visitMethodDef(JCMethodDecl tree) {
|
||||
scan(tree.mods);
|
||||
scan(tree.restype);
|
||||
scan(tree.typarams);
|
||||
scan(tree.recvparam);
|
||||
scan(tree.params);
|
||||
scan(tree.thrown);
|
||||
scan(tree.defaultValue);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitVarDef(JCVariableDecl tree) {
|
||||
scan(tree.mods);
|
||||
scan(tree.vartype);
|
||||
scan(tree.nameexpr);
|
||||
scan(tree.init);
|
||||
}
|
||||
|
||||
public void visitSkip(JCSkip tree) {
|
||||
}
|
||||
|
||||
public void visitBlock(JCBlock tree) {
|
||||
scan(tree.stats);
|
||||
}
|
||||
|
||||
public void visitDoLoop(JCDoWhileLoop tree) {
|
||||
scan(tree.body);
|
||||
scan(tree.cond);
|
||||
}
|
||||
|
||||
public void visitWhileLoop(JCWhileLoop tree) {
|
||||
scan(tree.cond);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitForLoop(JCForLoop tree) {
|
||||
scan(tree.init);
|
||||
scan(tree.cond);
|
||||
scan(tree.step);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitForeachLoop(JCEnhancedForLoop tree) {
|
||||
scan(tree.var);
|
||||
scan(tree.expr);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitLabelled(JCLabeledStatement tree) {
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitSwitch(JCSwitch tree) {
|
||||
scan(tree.selector);
|
||||
scan(tree.cases);
|
||||
}
|
||||
|
||||
public void visitCase(JCCase tree) {
|
||||
scan(tree.pat);
|
||||
scan(tree.stats);
|
||||
}
|
||||
|
||||
public void visitSynchronized(JCSynchronized tree) {
|
||||
scan(tree.lock);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitTry(JCTry tree) {
|
||||
scan(tree.resources);
|
||||
scan(tree.body);
|
||||
scan(tree.catchers);
|
||||
scan(tree.finalizer);
|
||||
}
|
||||
|
||||
public void visitCatch(JCCatch tree) {
|
||||
scan(tree.param);
|
||||
scan(tree.body);
|
||||
}
|
||||
|
||||
public void visitConditional(JCConditional tree) {
|
||||
scan(tree.cond);
|
||||
scan(tree.truepart);
|
||||
scan(tree.falsepart);
|
||||
}
|
||||
|
||||
public void visitIf(JCIf tree) {
|
||||
scan(tree.cond);
|
||||
scan(tree.thenpart);
|
||||
scan(tree.elsepart);
|
||||
}
|
||||
|
||||
public void visitExec(JCExpressionStatement tree) {
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitBreak(JCBreak tree) {
|
||||
}
|
||||
|
||||
public void visitContinue(JCContinue tree) {
|
||||
}
|
||||
|
||||
public void visitReturn(JCReturn tree) {
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitThrow(JCThrow tree) {
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitAssert(JCAssert tree) {
|
||||
scan(tree.cond);
|
||||
scan(tree.detail);
|
||||
}
|
||||
|
||||
public void visitApply(JCMethodInvocation tree) {
|
||||
scan(tree.typeargs);
|
||||
scan(tree.meth);
|
||||
scan(tree.args);
|
||||
}
|
||||
|
||||
public void visitNewClass(JCNewClass tree) {
|
||||
scan(tree.encl);
|
||||
scan(tree.typeargs);
|
||||
scan(tree.clazz);
|
||||
scan(tree.args);
|
||||
scan(tree.def);
|
||||
}
|
||||
|
||||
public void visitNewArray(JCNewArray tree) {
|
||||
scan(tree.annotations);
|
||||
scan(tree.elemtype);
|
||||
scan(tree.dims);
|
||||
for (List<JCAnnotation> annos : tree.dimAnnotations)
|
||||
scan(annos);
|
||||
scan(tree.elems);
|
||||
}
|
||||
|
||||
public void visitLambda(JCLambda tree) {
|
||||
scan(tree.body);
|
||||
scan(tree.params);
|
||||
}
|
||||
|
||||
public void visitParens(JCParens tree) {
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitAssign(JCAssign tree) {
|
||||
scan(tree.lhs);
|
||||
scan(tree.rhs);
|
||||
}
|
||||
|
||||
public void visitAssignop(JCAssignOp tree) {
|
||||
scan(tree.lhs);
|
||||
scan(tree.rhs);
|
||||
}
|
||||
|
||||
public void visitUnary(JCUnary tree) {
|
||||
scan(tree.arg);
|
||||
}
|
||||
|
||||
public void visitBinary(JCBinary tree) {
|
||||
scan(tree.lhs);
|
||||
scan(tree.rhs);
|
||||
}
|
||||
|
||||
public void visitTypeCast(JCTypeCast tree) {
|
||||
scan(tree.clazz);
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitTypeTest(JCInstanceOf tree) {
|
||||
scan(tree.expr);
|
||||
scan(tree.clazz);
|
||||
}
|
||||
|
||||
public void visitIndexed(JCArrayAccess tree) {
|
||||
scan(tree.indexed);
|
||||
scan(tree.index);
|
||||
}
|
||||
|
||||
public void visitSelect(JCFieldAccess tree) {
|
||||
scan(tree.selected);
|
||||
}
|
||||
|
||||
public void visitReference(JCMemberReference tree) {
|
||||
scan(tree.expr);
|
||||
scan(tree.typeargs);
|
||||
}
|
||||
|
||||
public void visitIdent(JCIdent tree) {
|
||||
}
|
||||
|
||||
public void visitLiteral(JCLiteral tree) {
|
||||
}
|
||||
|
||||
public void visitTypeIdent(JCPrimitiveTypeTree tree) {
|
||||
}
|
||||
|
||||
public void visitTypeArray(JCArrayTypeTree tree) {
|
||||
scan(tree.elemtype);
|
||||
}
|
||||
|
||||
public void visitTypeApply(JCTypeApply tree) {
|
||||
scan(tree.clazz);
|
||||
scan(tree.arguments);
|
||||
}
|
||||
|
||||
public void visitTypeUnion(JCTypeUnion tree) {
|
||||
scan(tree.alternatives);
|
||||
}
|
||||
|
||||
public void visitTypeIntersection(JCTypeIntersection tree) {
|
||||
scan(tree.bounds);
|
||||
}
|
||||
|
||||
public void visitTypeParameter(JCTypeParameter tree) {
|
||||
scan(tree.annotations);
|
||||
scan(tree.bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWildcard(JCWildcard tree) {
|
||||
scan(tree.kind);
|
||||
if (tree.inner != null)
|
||||
scan(tree.inner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeBoundKind(TypeBoundKind that) {
|
||||
}
|
||||
|
||||
public void visitModifiers(JCModifiers tree) {
|
||||
scan(tree.annotations);
|
||||
}
|
||||
|
||||
public void visitAnnotation(JCAnnotation tree) {
|
||||
scan(tree.annotationType);
|
||||
scan(tree.args);
|
||||
}
|
||||
|
||||
public void visitAnnotatedType(JCAnnotatedType tree) {
|
||||
scan(tree.annotations);
|
||||
scan(tree.underlyingType);
|
||||
}
|
||||
|
||||
public void visitErroneous(JCErroneous tree) {
|
||||
}
|
||||
|
||||
public void visitLetExpr(LetExpr tree) {
|
||||
scan(tree.defs);
|
||||
scan(tree.expr);
|
||||
}
|
||||
|
||||
public void visitTree(JCTree tree) {
|
||||
Assert.error();
|
||||
}
|
||||
}
|
442
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeTranslator.java
Normal file
442
jdkSrc/jdk8/com/sun/tools/javac/tree/TreeTranslator.java
Normal file
@@ -0,0 +1,442 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
|
||||
/** A subclass of Tree.Visitor, this class defines
|
||||
* a general tree translator pattern. Translation proceeds recursively in
|
||||
* left-to-right order down a tree, constructing translated nodes by
|
||||
* overwriting existing ones. There is one visitor method in this class
|
||||
* for every possible kind of tree node. To obtain a specific
|
||||
* translator, it suffices to override those visitor methods which
|
||||
* do some interesting work. The translator class itself takes care of all
|
||||
* navigational aspects.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class TreeTranslator extends JCTree.Visitor {
|
||||
|
||||
/** Visitor result field: a tree
|
||||
*/
|
||||
protected JCTree result;
|
||||
|
||||
/** Visitor method: Translate a single node.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends JCTree> T translate(T tree) {
|
||||
if (tree == null) {
|
||||
return null;
|
||||
} else {
|
||||
tree.accept(this);
|
||||
JCTree tmpResult = this.result;
|
||||
this.result = null;
|
||||
return (T)tmpResult; // XXX cast
|
||||
}
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of nodes.
|
||||
*/
|
||||
public <T extends JCTree> List<T> translate(List<T> trees) {
|
||||
if (trees == null) return null;
|
||||
for (List<T> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of variable definitions.
|
||||
*/
|
||||
public List<JCVariableDecl> translateVarDefs(List<JCVariableDecl> trees) {
|
||||
for (List<JCVariableDecl> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of type parameters.
|
||||
*/
|
||||
public List<JCTypeParameter> translateTypeParams(List<JCTypeParameter> trees) {
|
||||
for (List<JCTypeParameter> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of case parts of switch statements.
|
||||
*/
|
||||
public List<JCCase> translateCases(List<JCCase> trees) {
|
||||
for (List<JCCase> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of catch clauses in try statements.
|
||||
*/
|
||||
public List<JCCatch> translateCatchers(List<JCCatch> trees) {
|
||||
for (List<JCCatch> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/** Visitor method: translate a list of catch clauses in try statements.
|
||||
*/
|
||||
public List<JCAnnotation> translateAnnotations(List<JCAnnotation> trees) {
|
||||
for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail)
|
||||
l.head = translate(l.head);
|
||||
return trees;
|
||||
}
|
||||
|
||||
/* ***************************************************************************
|
||||
* Visitor methods
|
||||
****************************************************************************/
|
||||
|
||||
public void visitTopLevel(JCCompilationUnit tree) {
|
||||
tree.pid = translate(tree.pid);
|
||||
tree.defs = translate(tree.defs);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitImport(JCImport tree) {
|
||||
tree.qualid = translate(tree.qualid);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitClassDef(JCClassDecl tree) {
|
||||
tree.mods = translate(tree.mods);
|
||||
tree.typarams = translateTypeParams(tree.typarams);
|
||||
tree.extending = translate(tree.extending);
|
||||
tree.implementing = translate(tree.implementing);
|
||||
tree.defs = translate(tree.defs);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitMethodDef(JCMethodDecl tree) {
|
||||
tree.mods = translate(tree.mods);
|
||||
tree.restype = translate(tree.restype);
|
||||
tree.typarams = translateTypeParams(tree.typarams);
|
||||
tree.recvparam = translate(tree.recvparam);
|
||||
tree.params = translateVarDefs(tree.params);
|
||||
tree.thrown = translate(tree.thrown);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitVarDef(JCVariableDecl tree) {
|
||||
tree.mods = translate(tree.mods);
|
||||
tree.nameexpr = translate(tree.nameexpr);
|
||||
tree.vartype = translate(tree.vartype);
|
||||
tree.init = translate(tree.init);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitSkip(JCSkip tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitBlock(JCBlock tree) {
|
||||
tree.stats = translate(tree.stats);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitDoLoop(JCDoWhileLoop tree) {
|
||||
tree.body = translate(tree.body);
|
||||
tree.cond = translate(tree.cond);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitWhileLoop(JCWhileLoop tree) {
|
||||
tree.cond = translate(tree.cond);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitForLoop(JCForLoop tree) {
|
||||
tree.init = translate(tree.init);
|
||||
tree.cond = translate(tree.cond);
|
||||
tree.step = translate(tree.step);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitForeachLoop(JCEnhancedForLoop tree) {
|
||||
tree.var = translate(tree.var);
|
||||
tree.expr = translate(tree.expr);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitLabelled(JCLabeledStatement tree) {
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitSwitch(JCSwitch tree) {
|
||||
tree.selector = translate(tree.selector);
|
||||
tree.cases = translateCases(tree.cases);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitCase(JCCase tree) {
|
||||
tree.pat = translate(tree.pat);
|
||||
tree.stats = translate(tree.stats);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitSynchronized(JCSynchronized tree) {
|
||||
tree.lock = translate(tree.lock);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTry(JCTry tree) {
|
||||
tree.resources = translate(tree.resources);
|
||||
tree.body = translate(tree.body);
|
||||
tree.catchers = translateCatchers(tree.catchers);
|
||||
tree.finalizer = translate(tree.finalizer);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitCatch(JCCatch tree) {
|
||||
tree.param = translate(tree.param);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitConditional(JCConditional tree) {
|
||||
tree.cond = translate(tree.cond);
|
||||
tree.truepart = translate(tree.truepart);
|
||||
tree.falsepart = translate(tree.falsepart);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitIf(JCIf tree) {
|
||||
tree.cond = translate(tree.cond);
|
||||
tree.thenpart = translate(tree.thenpart);
|
||||
tree.elsepart = translate(tree.elsepart);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitExec(JCExpressionStatement tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitBreak(JCBreak tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitContinue(JCContinue tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitReturn(JCReturn tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitThrow(JCThrow tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitAssert(JCAssert tree) {
|
||||
tree.cond = translate(tree.cond);
|
||||
tree.detail = translate(tree.detail);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitApply(JCMethodInvocation tree) {
|
||||
tree.meth = translate(tree.meth);
|
||||
tree.args = translate(tree.args);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitNewClass(JCNewClass tree) {
|
||||
tree.encl = translate(tree.encl);
|
||||
tree.clazz = translate(tree.clazz);
|
||||
tree.args = translate(tree.args);
|
||||
tree.def = translate(tree.def);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitLambda(JCLambda tree) {
|
||||
tree.params = translate(tree.params);
|
||||
tree.body = translate(tree.body);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitNewArray(JCNewArray tree) {
|
||||
tree.annotations = translate(tree.annotations);
|
||||
List<List<JCAnnotation>> dimAnnos = List.nil();
|
||||
for (List<JCAnnotation> origDimAnnos : tree.dimAnnotations)
|
||||
dimAnnos = dimAnnos.append(translate(origDimAnnos));
|
||||
tree.dimAnnotations = dimAnnos;
|
||||
tree.elemtype = translate(tree.elemtype);
|
||||
tree.dims = translate(tree.dims);
|
||||
tree.elems = translate(tree.elems);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitParens(JCParens tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitAssign(JCAssign tree) {
|
||||
tree.lhs = translate(tree.lhs);
|
||||
tree.rhs = translate(tree.rhs);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitAssignop(JCAssignOp tree) {
|
||||
tree.lhs = translate(tree.lhs);
|
||||
tree.rhs = translate(tree.rhs);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitUnary(JCUnary tree) {
|
||||
tree.arg = translate(tree.arg);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitBinary(JCBinary tree) {
|
||||
tree.lhs = translate(tree.lhs);
|
||||
tree.rhs = translate(tree.rhs);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeCast(JCTypeCast tree) {
|
||||
tree.clazz = translate(tree.clazz);
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeTest(JCInstanceOf tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
tree.clazz = translate(tree.clazz);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitIndexed(JCArrayAccess tree) {
|
||||
tree.indexed = translate(tree.indexed);
|
||||
tree.index = translate(tree.index);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitSelect(JCFieldAccess tree) {
|
||||
tree.selected = translate(tree.selected);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitReference(JCMemberReference tree) {
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitIdent(JCIdent tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitLiteral(JCLiteral tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeIdent(JCPrimitiveTypeTree tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeArray(JCArrayTypeTree tree) {
|
||||
tree.elemtype = translate(tree.elemtype);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeApply(JCTypeApply tree) {
|
||||
tree.clazz = translate(tree.clazz);
|
||||
tree.arguments = translate(tree.arguments);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeUnion(JCTypeUnion tree) {
|
||||
tree.alternatives = translate(tree.alternatives);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeIntersection(JCTypeIntersection tree) {
|
||||
tree.bounds = translate(tree.bounds);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTypeParameter(JCTypeParameter tree) {
|
||||
tree.annotations = translate(tree.annotations);
|
||||
tree.bounds = translate(tree.bounds);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWildcard(JCWildcard tree) {
|
||||
tree.kind = translate(tree.kind);
|
||||
tree.inner = translate(tree.inner);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeBoundKind(TypeBoundKind tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitErroneous(JCErroneous tree) {
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitLetExpr(LetExpr tree) {
|
||||
tree.defs = translateVarDefs(tree.defs);
|
||||
tree.expr = translate(tree.expr);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitModifiers(JCModifiers tree) {
|
||||
tree.annotations = translateAnnotations(tree.annotations);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitAnnotation(JCAnnotation tree) {
|
||||
tree.annotationType = translate(tree.annotationType);
|
||||
tree.args = translate(tree.args);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitAnnotatedType(JCAnnotatedType tree) {
|
||||
tree.annotations = translate(tree.annotations);
|
||||
tree.underlyingType = translate(tree.underlyingType);
|
||||
result = tree;
|
||||
}
|
||||
|
||||
public void visitTree(JCTree tree) {
|
||||
throw new AssertionError(tree);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user