feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
98
jdkSrc/jdk8/com/sun/source/util/DocSourcePositions.java
Normal file
98
jdkSrc/jdk8/com/sun/source/util/DocSourcePositions.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 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.source.util;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
|
||||
/**
|
||||
* Provides methods to obtain the position of a DocTree within a javadoc comment.
|
||||
* A position is defined as a simple character offset from the start of a
|
||||
* CompilationUnit where the first character is at offset 0.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface DocSourcePositions extends SourcePositions {
|
||||
|
||||
/**
|
||||
* Gets the starting position of the tree within the comment within the file. If tree is not found within
|
||||
* file, or if the starting position is not available,
|
||||
* return {@link javax.tools.Diagnostic#NOPOS}.
|
||||
* The given tree should be under the given comment tree, and the given documentation
|
||||
* comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) }
|
||||
* for a tree under the given file.
|
||||
* The returned position must be at the start of the yield of this tree, that
|
||||
* is for any sub-tree of this tree, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br>
|
||||
* {@code tree.getStartPosition() == NOPOS} or <br>
|
||||
* {@code subtree.getStartPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* @param file CompilationUnit in which to find tree.
|
||||
* @param comment the comment tree that encloses the tree for which the
|
||||
* position is being sought
|
||||
* @param tree tree for which a position is sought.
|
||||
* @return the start position of tree.
|
||||
*/
|
||||
long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree);
|
||||
|
||||
/**
|
||||
* Gets the ending position of the tree within the comment within the file. If tree is not found within
|
||||
* file, or if the ending position is not available,
|
||||
* return {@link javax.tools.Diagnostic#NOPOS}.
|
||||
* The given tree should be under the given comment tree, and the given documentation
|
||||
* comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) }
|
||||
* for a tree under the given file.
|
||||
* The returned position must be at the end of the yield of this tree,
|
||||
* that is for any sub-tree of this tree, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br>
|
||||
* {@code tree.getEndPosition() == NOPOS} or <br>
|
||||
* {@code subtree.getEndPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* In addition, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getStartPosition() <= tree.getEndPosition()} or <br>
|
||||
* {@code tree.getStartPosition() == NOPOS} or <br>
|
||||
* {@code tree.getEndPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* @param file CompilationUnit in which to find tree.
|
||||
* @param comment the comment tree that encloses the tree for which the
|
||||
* position is being sought
|
||||
* @param tree tree for which a position is sought.
|
||||
* @return the start position of tree.
|
||||
*/
|
||||
long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree);
|
||||
|
||||
}
|
||||
171
jdkSrc/jdk8/com/sun/source/util/DocTreePath.java
Normal file
171
jdkSrc/jdk8/com/sun/source/util/DocTreePath.java
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A path of tree nodes, typically used to represent the sequence of ancestor
|
||||
* nodes of a tree node up to the top level DocCommentTree node.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class DocTreePath implements Iterable<DocTree> {
|
||||
/**
|
||||
* Gets a documentation tree path for a tree node within a compilation unit.
|
||||
* @return null if the node is not found
|
||||
*/
|
||||
public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree target) {
|
||||
return getPath(new DocTreePath(treePath, doc), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a documentation tree path for a tree node within a subtree identified by a DocTreePath object.
|
||||
* @return null if the node is not found
|
||||
*/
|
||||
public static DocTreePath getPath(DocTreePath path, DocTree target) {
|
||||
path.getClass();
|
||||
target.getClass();
|
||||
|
||||
class Result extends Error {
|
||||
static final long serialVersionUID = -5942088234594905625L;
|
||||
DocTreePath path;
|
||||
Result(DocTreePath path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
class PathFinder extends DocTreePathScanner<DocTreePath,DocTree> {
|
||||
public DocTreePath scan(DocTree tree, DocTree target) {
|
||||
if (tree == target) {
|
||||
throw new Result(new DocTreePath(getCurrentPath(), target));
|
||||
}
|
||||
return super.scan(tree, target);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.getLeaf() == target) {
|
||||
return path;
|
||||
}
|
||||
|
||||
try {
|
||||
new PathFinder().scan(path, target);
|
||||
} catch (Result result) {
|
||||
return result.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DocTreePath for a root node.
|
||||
*
|
||||
* @param treePath the TreePath from which the root node was created.
|
||||
* @param t the DocCommentTree to create the path for.
|
||||
*/
|
||||
public DocTreePath(TreePath treePath, DocCommentTree t) {
|
||||
treePath.getClass();
|
||||
t.getClass();
|
||||
|
||||
this.treePath = treePath;
|
||||
this.docComment = t;
|
||||
this.parent = null;
|
||||
this.leaf = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DocTreePath for a child node.
|
||||
*/
|
||||
public DocTreePath(DocTreePath p, DocTree t) {
|
||||
if (t.getKind() == DocTree.Kind.DOC_COMMENT) {
|
||||
throw new IllegalArgumentException("Use DocTreePath(TreePath, DocCommentTree) to construct DocTreePath for a DocCommentTree.");
|
||||
} else {
|
||||
treePath = p.treePath;
|
||||
docComment = p.docComment;
|
||||
parent = p;
|
||||
}
|
||||
leaf = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TreePath associated with this path.
|
||||
* @return TreePath for this DocTreePath
|
||||
*/
|
||||
public TreePath getTreePath() {
|
||||
return treePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DocCommentTree associated with this path.
|
||||
* @return DocCommentTree for this DocTreePath
|
||||
*/
|
||||
public DocCommentTree getDocComment() {
|
||||
return docComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the leaf node for this path.
|
||||
* @return DocTree for this DocTreePath
|
||||
*/
|
||||
public DocTree getLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path for the enclosing node, or null if there is no enclosing node.
|
||||
* @return DocTreePath of parent
|
||||
*/
|
||||
public DocTreePath getParentPath() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Iterator<DocTree> iterator() {
|
||||
return new Iterator<DocTree>() {
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
public DocTree next() {
|
||||
DocTree t = next.leaf;
|
||||
next = next.parent;
|
||||
return t;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private DocTreePath next = DocTreePath.this;
|
||||
};
|
||||
}
|
||||
|
||||
private final TreePath treePath;
|
||||
private final DocCommentTree docComment;
|
||||
private final DocTree leaf;
|
||||
private final DocTreePath parent;
|
||||
}
|
||||
80
jdkSrc/jdk8/com/sun/source/util/DocTreePathScanner.java
Normal file
80
jdkSrc/jdk8/com/sun/source/util/DocTreePathScanner.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
|
||||
/**
|
||||
* A DocTreeVisitor that visits all the child tree nodes, and provides
|
||||
* support for maintaining a path for the parent nodes.
|
||||
* To visit nodes of a particular type, just override the
|
||||
* corresponding visitorXYZ method.
|
||||
* Inside your method, call super.visitXYZ to visit descendant
|
||||
* nodes.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
|
||||
/**
|
||||
* Scan a tree from a position identified by a TreePath.
|
||||
*/
|
||||
public R scan(DocTreePath path, P p) {
|
||||
this.path = path;
|
||||
try {
|
||||
return path.getLeaf().accept(this, p);
|
||||
} finally {
|
||||
this.path = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a single node.
|
||||
* The current path is updated for the duration of the scan.
|
||||
*/
|
||||
@Override
|
||||
public R scan(DocTree tree, P p) {
|
||||
if (tree == null)
|
||||
return null;
|
||||
|
||||
DocTreePath prev = path;
|
||||
path = new DocTreePath(path, tree);
|
||||
try {
|
||||
return tree.accept(this, p);
|
||||
} finally {
|
||||
path = prev;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current path for the node, as built up by the currently
|
||||
* active set of scan calls.
|
||||
*/
|
||||
public DocTreePath getCurrentPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
private DocTreePath path;
|
||||
}
|
||||
274
jdkSrc/jdk8/com/sun/source/util/DocTreeScanner.java
Normal file
274
jdkSrc/jdk8/com/sun/source/util/DocTreeScanner.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
|
||||
|
||||
/**
|
||||
* A TreeVisitor that visits all the child tree nodes.
|
||||
* To visit nodes of a particular type, just override the
|
||||
* corresponding visitXYZ method.
|
||||
* Inside your method, call super.visitXYZ to visit descendant
|
||||
* nodes.
|
||||
*
|
||||
* <p>The default implementation of the visitXYZ methods will determine
|
||||
* a result as follows:
|
||||
* <ul>
|
||||
* <li>If the node being visited has no children, the result will be null.
|
||||
* <li>If the node being visited has one child, the result will be the
|
||||
* result of calling {@code scan} on that child. The child may be a simple node
|
||||
* or itself a list of nodes.
|
||||
* <li> If the node being visited has more than one child, the result will
|
||||
* be determined by calling {@code scan} each child in turn, and then combining the
|
||||
* result of each scan after the first with the cumulative result
|
||||
* so far, as determined by the {@link #reduce} method. Each child may be either
|
||||
* a simple node of a list of nodes. The default behavior of the {@code reduce}
|
||||
* method is such that the result of the visitXYZ method will be the result of
|
||||
* the last child scanned.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Here is an example to count the number of erroneous nodes in a tree:
|
||||
* <pre>
|
||||
* class CountErrors extends DocTreeScanner<Integer,Void> {
|
||||
* {@literal @}Override
|
||||
* public Integer visitErroneous(ErroneousTree node, Void p) {
|
||||
* return 1;
|
||||
* }
|
||||
* {@literal @}Override
|
||||
* public Integer reduce(Integer r1, Integer r2) {
|
||||
* return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class DocTreeScanner<R,P> implements DocTreeVisitor<R,P> {
|
||||
|
||||
/**
|
||||
* Scan a single node.
|
||||
*/
|
||||
public R scan(DocTree node, P p) {
|
||||
return (node == null) ? null : node.accept(this, p);
|
||||
}
|
||||
|
||||
private R scanAndReduce(DocTree node, P p, R r) {
|
||||
return reduce(scan(node, p), r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a list of nodes.
|
||||
*/
|
||||
public R scan(Iterable<? extends DocTree> nodes, P p) {
|
||||
R r = null;
|
||||
if (nodes != null) {
|
||||
boolean first = true;
|
||||
for (DocTree node : nodes) {
|
||||
r = (first ? scan(node, p) : scanAndReduce(node, p, r));
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private R scanAndReduce(Iterable<? extends DocTree> nodes, P p, R r) {
|
||||
return reduce(scan(nodes, p), r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces two results into a combined result.
|
||||
* The default implementation is to return the first parameter.
|
||||
* The general contract of the method is that it may take any action whatsoever.
|
||||
*/
|
||||
public R reduce(R r1, R r2) {
|
||||
return r1;
|
||||
}
|
||||
|
||||
|
||||
/* ***************************************************************************
|
||||
* Visitor methods
|
||||
****************************************************************************/
|
||||
|
||||
@Override
|
||||
public R visitAttribute(AttributeTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitAuthor(AuthorTree node, P p) {
|
||||
return scan(node.getName(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitComment(CommentTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitDeprecated(DeprecatedTree node, P p) {
|
||||
return scan(node.getBody(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitDocComment(DocCommentTree node, P p) {
|
||||
R r = scan(node.getFirstSentence(), p);
|
||||
r = scanAndReduce(node.getBody(), p, r);
|
||||
r = scanAndReduce(node.getBlockTags(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitDocRoot(DocRootTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitEndElement(EndElementTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitEntity(EntityTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitErroneous(ErroneousTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitIdentifier(IdentifierTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitInheritDoc(InheritDocTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitLink(LinkTree node, P p) {
|
||||
R r = scan(node.getReference(), p);
|
||||
r = scanAndReduce(node.getLabel(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitLiteral(LiteralTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitParam(ParamTree node, P p) {
|
||||
R r = scan(node.getName(), p);
|
||||
r = scanAndReduce(node.getDescription(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitReference(ReferenceTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitReturn(ReturnTree node, P p) {
|
||||
return scan(node.getDescription(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSee(SeeTree node, P p) {
|
||||
return scan(node.getReference(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSerial(SerialTree node, P p) {
|
||||
return scan(node.getDescription(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSerialData(SerialDataTree node, P p) {
|
||||
return scan(node.getDescription(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSerialField(SerialFieldTree node, P p) {
|
||||
R r = scan(node.getName(), p);
|
||||
r = scanAndReduce(node.getType(), p, r);
|
||||
r = scanAndReduce(node.getDescription(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSince(SinceTree node, P p) {
|
||||
return scan(node.getBody(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitStartElement(StartElementTree node, P p) {
|
||||
return scan(node.getAttributes(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitText(TextTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitThrows(ThrowsTree node, P p) {
|
||||
R r = scan(node.getExceptionName(), p);
|
||||
r = scanAndReduce(node.getDescription(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitUnknownBlockTag(UnknownBlockTagTree node, P p) {
|
||||
return scan(node.getContent(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitUnknownInlineTag(UnknownInlineTagTree node, P p) {
|
||||
return scan(node.getContent(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitValue(ValueTree node, P p) {
|
||||
return scan(node.getReference(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitVersion(VersionTree node, P p) {
|
||||
return scan(node.getBody(), p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitOther(DocTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
89
jdkSrc/jdk8/com/sun/source/util/DocTrees.java
Normal file
89
jdkSrc/jdk8/com/sun/source/util/DocTrees.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
* Provides access to syntax trees for doc comments.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class DocTrees extends Trees {
|
||||
/**
|
||||
* Gets a DocTrees object for a given CompilationTask.
|
||||
* @param task the compilation task for which to get the Trees object
|
||||
* @throws IllegalArgumentException if the task does not support the Trees API.
|
||||
*/
|
||||
public static DocTrees instance(CompilationTask task) {
|
||||
return (DocTrees) Trees.instance(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a DocTrees object for a given ProcessingEnvironment.
|
||||
* @param env the processing environment for which to get the Trees object
|
||||
* @throws IllegalArgumentException if the env does not support the Trees API.
|
||||
*/
|
||||
public static DocTrees instance(ProcessingEnvironment env) {
|
||||
if (!env.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment"))
|
||||
throw new IllegalArgumentException();
|
||||
return (DocTrees) getJavacTrees(ProcessingEnvironment.class, env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the doc comment tree, if any, for the Tree node identified by a given TreePath.
|
||||
* Returns null if no doc comment was found.
|
||||
*/
|
||||
public abstract DocCommentTree getDocCommentTree(TreePath path);
|
||||
|
||||
/**
|
||||
* Gets the language model element referred to by the leaf node of the given
|
||||
* {@link DocTreePath}, or null if unknown.
|
||||
*/
|
||||
public abstract Element getElement(DocTreePath path);
|
||||
|
||||
public abstract DocSourcePositions getSourcePositions();
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* tree within the provided compilation unit
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param t the tree to use as a position hint
|
||||
* @param root the compilation unit that contains tree
|
||||
*/
|
||||
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
|
||||
com.sun.source.doctree.DocTree t,
|
||||
com.sun.source.doctree.DocCommentTree c,
|
||||
com.sun.source.tree.CompilationUnitTree root);
|
||||
}
|
||||
153
jdkSrc/jdk8/com/sun/source/util/JavacTask.java
Normal file
153
jdkSrc/jdk8/com/sun/source/util/JavacTask.java
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.tools.javac.api.BasicJavacTask;
|
||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
|
||||
/**
|
||||
* Provides access to functionality specific to the JDK Java Compiler, javac.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class JavacTask implements CompilationTask {
|
||||
|
||||
/**
|
||||
* Get the {@code JavacTask} for a {@code ProcessingEnvironment}.
|
||||
* If the compiler is being invoked using a
|
||||
* {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},
|
||||
* then that task will be returned.
|
||||
* @param processingEnvironment the processing environment
|
||||
* @return the {@code JavacTask} for a {@code ProcessingEnvironment}
|
||||
* @since 1.8
|
||||
*/
|
||||
public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
|
||||
if (!processingEnvironment.getClass().getName().equals(
|
||||
"com.sun.tools.javac.processing.JavacProcessingEnvironment"))
|
||||
throw new IllegalArgumentException();
|
||||
Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
|
||||
JavacTask t = c.get(JavacTask.class);
|
||||
return (t != null) ? t : new BasicJavacTask(c, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the specified files returning a list of abstract syntax trees.
|
||||
*
|
||||
* @return a list of abstract syntax trees
|
||||
* @throws IOException if an unhandled I/O error occurred in the compiler.
|
||||
* @throws IllegalStateException if the operation cannot be performed at this time.
|
||||
*/
|
||||
public abstract Iterable<? extends CompilationUnitTree> parse()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Complete all analysis.
|
||||
*
|
||||
* @return a list of elements that were analyzed
|
||||
* @throws IOException if an unhandled I/O error occurred in the compiler.
|
||||
* @throws IllegalStateException if the operation cannot be performed at this time.
|
||||
*/
|
||||
public abstract Iterable<? extends Element> analyze() throws IOException;
|
||||
|
||||
/**
|
||||
* Generate code.
|
||||
*
|
||||
* @return a list of files that were generated
|
||||
* @throws IOException if an unhandled I/O error occurred in the compiler.
|
||||
* @throws IllegalStateException if the operation cannot be performed at this time.
|
||||
*/
|
||||
public abstract Iterable<? extends JavaFileObject> generate() throws IOException;
|
||||
|
||||
/**
|
||||
* The specified listener will receive notification of events
|
||||
* describing the progress of this compilation task.
|
||||
*
|
||||
* If another listener is receiving notifications as a result of a prior
|
||||
* call of this method, then that listener will no longer receive notifications.
|
||||
*
|
||||
* Informally, this method is equivalent to calling {@code removeTaskListener} for
|
||||
* any listener that has been previously set, followed by {@code addTaskListener}
|
||||
* for the new listener.
|
||||
*
|
||||
* @throws IllegalStateException if the specified listener has already been added.
|
||||
*/
|
||||
public abstract void setTaskListener(TaskListener taskListener);
|
||||
|
||||
/**
|
||||
* The specified listener will receive notification of events
|
||||
* describing the progress of this compilation task.
|
||||
*
|
||||
* This method may be called at any time before or during the compilation.
|
||||
*
|
||||
* @throws IllegalStateException if the specified listener has already been added.
|
||||
* @since 1.8
|
||||
*/
|
||||
public abstract void addTaskListener(TaskListener taskListener);
|
||||
|
||||
/**
|
||||
* The specified listener will no longer receive notification of events
|
||||
* describing the progress of this compilation task.
|
||||
*
|
||||
* This method may be called at any time before or during the compilation.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
public abstract void removeTaskListener(TaskListener taskListener);
|
||||
|
||||
/**
|
||||
* Get a type mirror of the tree node determined by the specified path.
|
||||
* This method has been superceded by methods on
|
||||
* {@link com.sun.source.util.Trees Trees}.
|
||||
* @see com.sun.source.util.Trees#getTypeMirror
|
||||
*/
|
||||
public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);
|
||||
|
||||
/**
|
||||
* Get a utility object for dealing with program elements.
|
||||
*/
|
||||
public abstract Elements getElements();
|
||||
|
||||
/**
|
||||
* Get a utility object for dealing with type mirrors.
|
||||
*/
|
||||
public abstract Types getTypes();
|
||||
}
|
||||
65
jdkSrc/jdk8/com/sun/source/util/Plugin.java
Normal file
65
jdkSrc/jdk8/com/sun/source/util/Plugin.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
/**
|
||||
* The interface for a javac plug-in.
|
||||
*
|
||||
* <p>The javac plug-in mechanism allows a user to specify one or more plug-ins
|
||||
* on the javac command line, to be started soon after the compilation
|
||||
* has begun. Plug-ins are identified by a user-friendly name. Each plug-in that
|
||||
* is started will be passed an array of strings, which may be used to
|
||||
* provide the plug-in with values for any desired options or other arguments.
|
||||
*
|
||||
* <p>Plug-ins are located via a {@link ServiceLoader},
|
||||
* using the same class path as annotation processors (i.e.
|
||||
* {@link StandardLocation#ANNOTATION_PROCESSOR_PATH ANNOTATION_PROCESSOR_PATH} or
|
||||
* {@code -processorpath}).
|
||||
*
|
||||
* <p>It is expected that a typical plug-in will simply register a
|
||||
* {@link TaskListener} to be informed of events during the execution
|
||||
* of the compilation, and that the rest of the work will be done
|
||||
* by the task listener.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface Plugin {
|
||||
/**
|
||||
* Get the user-friendly name of this plug-in.
|
||||
* @return the user-friendly name of the plug-in
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Initialize the plug-in for a given compilation task.
|
||||
* @param task The compilation task that has just been started
|
||||
* @param args Arguments, if any, for the plug-in
|
||||
*/
|
||||
void init(JavacTask task, String... args);
|
||||
}
|
||||
180
jdkSrc/jdk8/com/sun/source/util/SimpleDocTreeVisitor.java
Normal file
180
jdkSrc/jdk8/com/sun/source/util/SimpleDocTreeVisitor.java
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for tree nodes.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class SimpleDocTreeVisitor<R,P> implements DocTreeVisitor<R, P> {
|
||||
protected final R DEFAULT_VALUE;
|
||||
|
||||
protected SimpleDocTreeVisitor() {
|
||||
DEFAULT_VALUE = null;
|
||||
}
|
||||
|
||||
protected SimpleDocTreeVisitor(R defaultValue) {
|
||||
DEFAULT_VALUE = defaultValue;
|
||||
}
|
||||
|
||||
protected R defaultAction(DocTree node, P p) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public final R visit(DocTree node, P p) {
|
||||
return (node == null) ? null : node.accept(this, p);
|
||||
}
|
||||
|
||||
public final R visit(Iterable<? extends DocTree> nodes, P p) {
|
||||
R r = null;
|
||||
if (nodes != null) {
|
||||
for (DocTree node : nodes)
|
||||
r = visit(node, p);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitAttribute(AttributeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitAuthor(AuthorTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitComment(CommentTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitDeprecated(DeprecatedTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitDocComment(DocCommentTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitDocRoot(DocRootTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitEndElement(EndElementTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitEntity(EntityTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitErroneous(ErroneousTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitIdentifier(IdentifierTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitInheritDoc(InheritDocTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitLink(LinkTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitLiteral(LiteralTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitParam(ParamTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitReference(ReferenceTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitReturn(ReturnTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSee(SeeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSerial(SerialTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSerialData(SerialDataTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSerialField(SerialFieldTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSince(SinceTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitStartElement(StartElementTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitText(TextTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitThrows(ThrowsTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitUnknownBlockTag(UnknownBlockTagTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitUnknownInlineTag(UnknownInlineTagTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitValue(ValueTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitVersion(VersionTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitOther(DocTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
}
|
||||
275
jdkSrc/jdk8/com/sun/source/util/SimpleTreeVisitor.java
Normal file
275
jdkSrc/jdk8/com/sun/source/util/SimpleTreeVisitor.java
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for tree nodes.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> {
|
||||
protected final R DEFAULT_VALUE;
|
||||
|
||||
protected SimpleTreeVisitor() {
|
||||
DEFAULT_VALUE = null;
|
||||
}
|
||||
|
||||
protected SimpleTreeVisitor(R defaultValue) {
|
||||
DEFAULT_VALUE = defaultValue;
|
||||
}
|
||||
|
||||
protected R defaultAction(Tree node, P p) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public final R visit(Tree node, P p) {
|
||||
return (node == null) ? null : node.accept(this, p);
|
||||
}
|
||||
|
||||
public final R visit(Iterable<? extends Tree> nodes, P p) {
|
||||
R r = null;
|
||||
if (nodes != null)
|
||||
for (Tree node : nodes)
|
||||
r = visit(node, p);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitCompilationUnit(CompilationUnitTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitImport(ImportTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitClass(ClassTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitMethod(MethodTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitVariable(VariableTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitEmptyStatement(EmptyStatementTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitBlock(BlockTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitWhileLoop(WhileLoopTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitForLoop(ForLoopTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitLabeledStatement(LabeledStatementTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSwitch(SwitchTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitCase(CaseTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitSynchronized(SynchronizedTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitTry(TryTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitCatch(CatchTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitIf(IfTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitExpressionStatement(ExpressionStatementTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitBreak(BreakTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitContinue(ContinueTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitReturn(ReturnTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitThrow(ThrowTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitAssert(AssertTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitMethodInvocation(MethodInvocationTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitNewClass(NewClassTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitNewArray(NewArrayTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitLambdaExpression(LambdaExpressionTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitParenthesized(ParenthesizedTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitAssignment(AssignmentTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitUnary(UnaryTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitBinary(BinaryTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitTypeCast(TypeCastTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitInstanceOf(InstanceOfTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitArrayAccess(ArrayAccessTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitMemberSelect(MemberSelectTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitMemberReference(MemberReferenceTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitIdentifier(IdentifierTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitLiteral(LiteralTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitArrayType(ArrayTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitParameterizedType(ParameterizedTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitUnionType(UnionTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitIntersectionType(IntersectionTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitTypeParameter(TypeParameterTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitWildcard(WildcardTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitModifiers(ModifiersTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitAnnotation(AnnotationTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitErroneous(ErroneousTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
||||
public R visitOther(Tree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
}
|
||||
87
jdkSrc/jdk8/com/sun/source/util/SourcePositions.java
Normal file
87
jdkSrc/jdk8/com/sun/source/util/SourcePositions.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
|
||||
/**
|
||||
* Provides methods to obtain the position of a Tree within a CompilationUnit.
|
||||
* A position is defined as a simple character offset from the start of a
|
||||
* CompilationUnit where the first character is at offset 0.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface SourcePositions {
|
||||
|
||||
/**
|
||||
* Gets the starting position of tree within file. If tree is not found within
|
||||
* file, or if the starting position is not available,
|
||||
* return {@link javax.tools.Diagnostic#NOPOS}.
|
||||
* The returned position must be at the start of the yield of this tree, that
|
||||
* is for any sub-tree of this tree, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br>
|
||||
* {@code tree.getStartPosition() == NOPOS} or <br>
|
||||
* {@code subtree.getStartPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* @param file CompilationUnit in which to find tree.
|
||||
* @param tree tree for which a position is sought.
|
||||
* @return the start position of tree.
|
||||
*/
|
||||
long getStartPosition(CompilationUnitTree file, Tree tree);
|
||||
|
||||
/**
|
||||
* Gets the ending position of tree within file. If tree is not found within
|
||||
* file, or if the ending position is not available,
|
||||
* return {@link javax.tools.Diagnostic#NOPOS}.
|
||||
* The returned position must be at the end of the yield of this tree,
|
||||
* that is for any sub-tree of this tree, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br>
|
||||
* {@code tree.getEndPosition() == NOPOS} or <br>
|
||||
* {@code subtree.getEndPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* In addition, the following must hold:
|
||||
*
|
||||
* <p>
|
||||
* {@code tree.getStartPosition() <= tree.getEndPosition()} or <br>
|
||||
* {@code tree.getStartPosition() == NOPOS} or <br>
|
||||
* {@code tree.getEndPosition() == NOPOS}
|
||||
* </p>
|
||||
*
|
||||
* @param file CompilationUnit in which to find tree.
|
||||
* @param tree tree for which a position is sought.
|
||||
* @return the end position of tree.
|
||||
*/
|
||||
long getEndPosition(CompilationUnitTree file, Tree tree);
|
||||
|
||||
}
|
||||
125
jdkSrc/jdk8/com/sun/source/util/TaskEvent.java
Normal file
125
jdkSrc/jdk8/com/sun/source/util/TaskEvent.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
|
||||
/**
|
||||
* Provides details about work that has been done by the JDK Java Compiler, javac.
|
||||
*
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public final class TaskEvent
|
||||
{
|
||||
/**
|
||||
* Kind of task event.
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public enum Kind {
|
||||
/**
|
||||
* For events related to the parsing of a file.
|
||||
*/
|
||||
PARSE,
|
||||
/**
|
||||
* For events relating to elements being entered.
|
||||
**/
|
||||
ENTER,
|
||||
/**
|
||||
* For events relating to elements being analyzed for errors.
|
||||
**/
|
||||
ANALYZE,
|
||||
/**
|
||||
* For events relating to class files being generated.
|
||||
**/
|
||||
GENERATE,
|
||||
/**
|
||||
* For events relating to overall annotation processing.
|
||||
**/
|
||||
ANNOTATION_PROCESSING,
|
||||
/**
|
||||
* For events relating to an individual annotation processing round.
|
||||
**/
|
||||
ANNOTATION_PROCESSING_ROUND
|
||||
};
|
||||
|
||||
public TaskEvent(Kind kind) {
|
||||
this(kind, null, null, null);
|
||||
}
|
||||
|
||||
public TaskEvent(Kind kind, JavaFileObject sourceFile) {
|
||||
this(kind, sourceFile, null, null);
|
||||
}
|
||||
|
||||
public TaskEvent(Kind kind, CompilationUnitTree unit) {
|
||||
this(kind, unit.getSourceFile(), unit, null);
|
||||
}
|
||||
|
||||
public TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz) {
|
||||
this(kind, unit.getSourceFile(), unit, clazz);
|
||||
}
|
||||
|
||||
private TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz) {
|
||||
this.kind = kind;
|
||||
this.file = file;
|
||||
this.unit = unit;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public JavaFileObject getSourceFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public CompilationUnitTree getCompilationUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public TypeElement getTypeElement() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "TaskEvent["
|
||||
+ kind + ","
|
||||
+ file + ","
|
||||
// the compilation unit is identified by the file
|
||||
+ clazz + "]";
|
||||
}
|
||||
|
||||
private Kind kind;
|
||||
private JavaFileObject file;
|
||||
private CompilationUnitTree unit;
|
||||
private TypeElement clazz;
|
||||
}
|
||||
41
jdkSrc/jdk8/com/sun/source/util/TaskListener.java
Normal file
41
jdkSrc/jdk8/com/sun/source/util/TaskListener.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
|
||||
/**
|
||||
* Provides a listener to monitor the activity of the JDK Java Compiler, javac.
|
||||
*
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface TaskListener
|
||||
{
|
||||
public void started(TaskEvent e);
|
||||
|
||||
public void finished(TaskEvent e);
|
||||
}
|
||||
158
jdkSrc/jdk8/com/sun/source/util/TreePath.java
Normal file
158
jdkSrc/jdk8/com/sun/source/util/TreePath.java
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
|
||||
/**
|
||||
* A path of tree nodes, typically used to represent the sequence of ancestor
|
||||
* nodes of a tree node up to the top level CompilationUnitTree node.
|
||||
*
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class TreePath implements Iterable<Tree> {
|
||||
/**
|
||||
* Gets a tree path for a tree node within a compilation unit.
|
||||
* @return null if the node is not found
|
||||
*/
|
||||
public static TreePath getPath(CompilationUnitTree unit, Tree target) {
|
||||
return getPath(new TreePath(unit), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a tree path for a tree node within a subtree identified by a TreePath object.
|
||||
* @return null if the node is not found
|
||||
*/
|
||||
public static TreePath getPath(TreePath path, Tree target) {
|
||||
path.getClass();
|
||||
target.getClass();
|
||||
|
||||
class Result extends Error {
|
||||
static final long serialVersionUID = -5942088234594905625L;
|
||||
TreePath path;
|
||||
Result(TreePath path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
class PathFinder extends TreePathScanner<TreePath,Tree> {
|
||||
public TreePath scan(Tree tree, Tree target) {
|
||||
if (tree == target) {
|
||||
throw new Result(new TreePath(getCurrentPath(), target));
|
||||
}
|
||||
return super.scan(tree, target);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.getLeaf() == target) {
|
||||
return path;
|
||||
}
|
||||
|
||||
try {
|
||||
new PathFinder().scan(path, target);
|
||||
} catch (Result result) {
|
||||
return result.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TreePath for a root node.
|
||||
*/
|
||||
public TreePath(CompilationUnitTree t) {
|
||||
this(null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TreePath for a child node.
|
||||
*/
|
||||
public TreePath(TreePath p, Tree t) {
|
||||
if (t.getKind() == Tree.Kind.COMPILATION_UNIT) {
|
||||
compilationUnit = (CompilationUnitTree) t;
|
||||
parent = null;
|
||||
}
|
||||
else {
|
||||
compilationUnit = p.compilationUnit;
|
||||
parent = p;
|
||||
}
|
||||
leaf = t;
|
||||
}
|
||||
/**
|
||||
* Get the compilation unit associated with this path.
|
||||
*/
|
||||
public CompilationUnitTree getCompilationUnit() {
|
||||
return compilationUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the leaf node for this path.
|
||||
*/
|
||||
public Tree getLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path for the enclosing node, or null if there is no enclosing node.
|
||||
*/
|
||||
public TreePath getParentPath() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates from leaves to root.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Tree> iterator() {
|
||||
return new Iterator<Tree>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree next() {
|
||||
Tree t = next.leaf;
|
||||
next = next.parent;
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private TreePath next = TreePath.this;
|
||||
};
|
||||
}
|
||||
|
||||
private CompilationUnitTree compilationUnit;
|
||||
private Tree leaf;
|
||||
private TreePath parent;
|
||||
}
|
||||
83
jdkSrc/jdk8/com/sun/source/util/TreePathScanner.java
Normal file
83
jdkSrc/jdk8/com/sun/source/util/TreePathScanner.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.source.util;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
|
||||
/**
|
||||
* A TreeVisitor that visits all the child tree nodes, and provides
|
||||
* support for maintaining a path for the parent nodes.
|
||||
* To visit nodes of a particular type, just override the
|
||||
* corresponding visitorXYZ method.
|
||||
* Inside your method, call super.visitXYZ to visit descendant
|
||||
* nodes.
|
||||
*
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class TreePathScanner<R, P> extends TreeScanner<R, P> {
|
||||
|
||||
/**
|
||||
* Scan a tree from a position identified by a TreePath.
|
||||
*/
|
||||
public R scan(TreePath path, P p) {
|
||||
this.path = path;
|
||||
try {
|
||||
return path.getLeaf().accept(this, p);
|
||||
} finally {
|
||||
this.path = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a single node.
|
||||
* The current path is updated for the duration of the scan.
|
||||
*/
|
||||
@Override
|
||||
public R scan(Tree tree, P p) {
|
||||
if (tree == null)
|
||||
return null;
|
||||
|
||||
TreePath prev = path;
|
||||
path = new TreePath(path, tree);
|
||||
try {
|
||||
return tree.accept(this, p);
|
||||
} finally {
|
||||
path = prev;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current path for the node, as built up by the currently
|
||||
* active set of scan calls.
|
||||
*/
|
||||
public TreePath getCurrentPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
private TreePath path;
|
||||
}
|
||||
418
jdkSrc/jdk8/com/sun/source/util/TreeScanner.java
Normal file
418
jdkSrc/jdk8/com/sun/source/util/TreeScanner.java
Normal file
@@ -0,0 +1,418 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import com.sun.source.tree.*;
|
||||
|
||||
/**
|
||||
* A TreeVisitor that visits all the child tree nodes.
|
||||
* To visit nodes of a particular type, just override the
|
||||
* corresponding visitXYZ method.
|
||||
* Inside your method, call super.visitXYZ to visit descendant
|
||||
* nodes.
|
||||
*
|
||||
* <p>The default implementation of the visitXYZ methods will determine
|
||||
* a result as follows:
|
||||
* <ul>
|
||||
* <li>If the node being visited has no children, the result will be null.
|
||||
* <li>If the node being visited has one child, the result will be the
|
||||
* result of calling {@code scan} on that child. The child may be a simple node
|
||||
* or itself a list of nodes.
|
||||
* <li> If the node being visited has more than one child, the result will
|
||||
* be determined by calling {@code scan} each child in turn, and then combining the
|
||||
* result of each scan after the first with the cumulative result
|
||||
* so far, as determined by the {@link #reduce} method. Each child may be either
|
||||
* a simple node of a list of nodes. The default behavior of the {@code reduce}
|
||||
* method is such that the result of the visitXYZ method will be the result of
|
||||
* the last child scanned.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Here is an example to count the number of identifier nodes in a tree:
|
||||
* <pre>
|
||||
* class CountIdentifiers extends TreeScanner<Integer,Void> {
|
||||
* {@literal @}Override
|
||||
* public Integer visitIdentifier(IdentifierTree node, Void p) {
|
||||
* return 1;
|
||||
* }
|
||||
* {@literal @}Override
|
||||
* public Integer reduce(Integer r1, Integer r2) {
|
||||
* return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class TreeScanner<R,P> implements TreeVisitor<R,P> {
|
||||
|
||||
/** Scan a single node.
|
||||
*/
|
||||
public R scan(Tree node, P p) {
|
||||
return (node == null) ? null : node.accept(this, p);
|
||||
}
|
||||
|
||||
private R scanAndReduce(Tree node, P p, R r) {
|
||||
return reduce(scan(node, p), r);
|
||||
}
|
||||
|
||||
/** Scan a list of nodes.
|
||||
*/
|
||||
public R scan(Iterable<? extends Tree> nodes, P p) {
|
||||
R r = null;
|
||||
if (nodes != null) {
|
||||
boolean first = true;
|
||||
for (Tree node : nodes) {
|
||||
r = (first ? scan(node, p) : scanAndReduce(node, p, r));
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) {
|
||||
return reduce(scan(nodes, p), r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces two results into a combined result.
|
||||
* The default implementation is to return the first parameter.
|
||||
* The general contract of the method is that it may take any action whatsoever.
|
||||
*/
|
||||
public R reduce(R r1, R r2) {
|
||||
return r1;
|
||||
}
|
||||
|
||||
|
||||
/* ***************************************************************************
|
||||
* Visitor methods
|
||||
****************************************************************************/
|
||||
|
||||
public R visitCompilationUnit(CompilationUnitTree node, P p) {
|
||||
R r = scan(node.getPackageAnnotations(), p);
|
||||
r = scanAndReduce(node.getPackageName(), p, r);
|
||||
r = scanAndReduce(node.getImports(), p, r);
|
||||
r = scanAndReduce(node.getTypeDecls(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitImport(ImportTree node, P p) {
|
||||
return scan(node.getQualifiedIdentifier(), p);
|
||||
}
|
||||
|
||||
public R visitClass(ClassTree node, P p) {
|
||||
R r = scan(node.getModifiers(), p);
|
||||
r = scanAndReduce(node.getTypeParameters(), p, r);
|
||||
r = scanAndReduce(node.getExtendsClause(), p, r);
|
||||
r = scanAndReduce(node.getImplementsClause(), p, r);
|
||||
r = scanAndReduce(node.getMembers(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitMethod(MethodTree node, P p) {
|
||||
R r = scan(node.getModifiers(), p);
|
||||
r = scanAndReduce(node.getReturnType(), p, r);
|
||||
r = scanAndReduce(node.getTypeParameters(), p, r);
|
||||
r = scanAndReduce(node.getParameters(), p, r);
|
||||
r = scanAndReduce(node.getReceiverParameter(), p, r);
|
||||
r = scanAndReduce(node.getThrows(), p, r);
|
||||
r = scanAndReduce(node.getBody(), p, r);
|
||||
r = scanAndReduce(node.getDefaultValue(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitVariable(VariableTree node, P p) {
|
||||
R r = scan(node.getModifiers(), p);
|
||||
r = scanAndReduce(node.getType(), p, r);
|
||||
r = scanAndReduce(node.getNameExpression(), p, r);
|
||||
r = scanAndReduce(node.getInitializer(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitEmptyStatement(EmptyStatementTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitBlock(BlockTree node, P p) {
|
||||
return scan(node.getStatements(), p);
|
||||
}
|
||||
|
||||
public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
|
||||
R r = scan(node.getStatement(), p);
|
||||
r = scanAndReduce(node.getCondition(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitWhileLoop(WhileLoopTree node, P p) {
|
||||
R r = scan(node.getCondition(), p);
|
||||
r = scanAndReduce(node.getStatement(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitForLoop(ForLoopTree node, P p) {
|
||||
R r = scan(node.getInitializer(), p);
|
||||
r = scanAndReduce(node.getCondition(), p, r);
|
||||
r = scanAndReduce(node.getUpdate(), p, r);
|
||||
r = scanAndReduce(node.getStatement(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
|
||||
R r = scan(node.getVariable(), p);
|
||||
r = scanAndReduce(node.getExpression(), p, r);
|
||||
r = scanAndReduce(node.getStatement(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitLabeledStatement(LabeledStatementTree node, P p) {
|
||||
return scan(node.getStatement(), p);
|
||||
}
|
||||
|
||||
public R visitSwitch(SwitchTree node, P p) {
|
||||
R r = scan(node.getExpression(), p);
|
||||
r = scanAndReduce(node.getCases(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitCase(CaseTree node, P p) {
|
||||
R r = scan(node.getExpression(), p);
|
||||
r = scanAndReduce(node.getStatements(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitSynchronized(SynchronizedTree node, P p) {
|
||||
R r = scan(node.getExpression(), p);
|
||||
r = scanAndReduce(node.getBlock(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitTry(TryTree node, P p) {
|
||||
R r = scan(node.getResources(), p);
|
||||
r = scanAndReduce(node.getBlock(), p, r);
|
||||
r = scanAndReduce(node.getCatches(), p, r);
|
||||
r = scanAndReduce(node.getFinallyBlock(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitCatch(CatchTree node, P p) {
|
||||
R r = scan(node.getParameter(), p);
|
||||
r = scanAndReduce(node.getBlock(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
|
||||
R r = scan(node.getCondition(), p);
|
||||
r = scanAndReduce(node.getTrueExpression(), p, r);
|
||||
r = scanAndReduce(node.getFalseExpression(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitIf(IfTree node, P p) {
|
||||
R r = scan(node.getCondition(), p);
|
||||
r = scanAndReduce(node.getThenStatement(), p, r);
|
||||
r = scanAndReduce(node.getElseStatement(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitExpressionStatement(ExpressionStatementTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitBreak(BreakTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitContinue(ContinueTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitReturn(ReturnTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitThrow(ThrowTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitAssert(AssertTree node, P p) {
|
||||
R r = scan(node.getCondition(), p);
|
||||
r = scanAndReduce(node.getDetail(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitMethodInvocation(MethodInvocationTree node, P p) {
|
||||
R r = scan(node.getTypeArguments(), p);
|
||||
r = scanAndReduce(node.getMethodSelect(), p, r);
|
||||
r = scanAndReduce(node.getArguments(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitNewClass(NewClassTree node, P p) {
|
||||
R r = scan(node.getEnclosingExpression(), p);
|
||||
r = scanAndReduce(node.getIdentifier(), p, r);
|
||||
r = scanAndReduce(node.getTypeArguments(), p, r);
|
||||
r = scanAndReduce(node.getArguments(), p, r);
|
||||
r = scanAndReduce(node.getClassBody(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitNewArray(NewArrayTree node, P p) {
|
||||
R r = scan(node.getType(), p);
|
||||
r = scanAndReduce(node.getDimensions(), p, r);
|
||||
r = scanAndReduce(node.getInitializers(), p, r);
|
||||
r = scanAndReduce(node.getAnnotations(), p, r);
|
||||
for (Iterable< ? extends Tree> dimAnno : node.getDimAnnotations()) {
|
||||
r = scanAndReduce(dimAnno, p, r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitLambdaExpression(LambdaExpressionTree node, P p) {
|
||||
R r = scan(node.getParameters(), p);
|
||||
r = scanAndReduce(node.getBody(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitParenthesized(ParenthesizedTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitAssignment(AssignmentTree node, P p) {
|
||||
R r = scan(node.getVariable(), p);
|
||||
r = scanAndReduce(node.getExpression(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
|
||||
R r = scan(node.getVariable(), p);
|
||||
r = scanAndReduce(node.getExpression(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitUnary(UnaryTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitBinary(BinaryTree node, P p) {
|
||||
R r = scan(node.getLeftOperand(), p);
|
||||
r = scanAndReduce(node.getRightOperand(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitTypeCast(TypeCastTree node, P p) {
|
||||
R r = scan(node.getType(), p);
|
||||
r = scanAndReduce(node.getExpression(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitInstanceOf(InstanceOfTree node, P p) {
|
||||
R r = scan(node.getExpression(), p);
|
||||
r = scanAndReduce(node.getType(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitArrayAccess(ArrayAccessTree node, P p) {
|
||||
R r = scan(node.getExpression(), p);
|
||||
r = scanAndReduce(node.getIndex(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitMemberSelect(MemberSelectTree node, P p) {
|
||||
return scan(node.getExpression(), p);
|
||||
}
|
||||
|
||||
public R visitMemberReference(MemberReferenceTree node, P p) {
|
||||
R r = scan(node.getQualifierExpression(), p);
|
||||
r = scanAndReduce(node.getTypeArguments(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitIdentifier(IdentifierTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitLiteral(LiteralTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitArrayType(ArrayTypeTree node, P p) {
|
||||
return scan(node.getType(), p);
|
||||
}
|
||||
|
||||
public R visitParameterizedType(ParameterizedTypeTree node, P p) {
|
||||
R r = scan(node.getType(), p);
|
||||
r = scanAndReduce(node.getTypeArguments(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitUnionType(UnionTypeTree node, P p) {
|
||||
return scan(node.getTypeAlternatives(), p);
|
||||
}
|
||||
|
||||
public R visitIntersectionType(IntersectionTypeTree node, P p) {
|
||||
return scan(node.getBounds(), p);
|
||||
}
|
||||
|
||||
public R visitTypeParameter(TypeParameterTree node, P p) {
|
||||
R r = scan(node.getAnnotations(), p);
|
||||
r = scanAndReduce(node.getBounds(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitWildcard(WildcardTree node, P p) {
|
||||
return scan(node.getBound(), p);
|
||||
}
|
||||
|
||||
public R visitModifiers(ModifiersTree node, P p) {
|
||||
return scan(node.getAnnotations(), p);
|
||||
}
|
||||
|
||||
public R visitAnnotation(AnnotationTree node, P p) {
|
||||
R r = scan(node.getAnnotationType(), p);
|
||||
r = scanAndReduce(node.getArguments(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
|
||||
R r = scan(node.getAnnotations(), p);
|
||||
r = scanAndReduce(node.getUnderlyingType(), p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R visitOther(Tree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitErroneous(ErroneousTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
223
jdkSrc/jdk8/com/sun/source/util/Trees.java
Normal file
223
jdkSrc/jdk8/com/sun/source/util/Trees.java
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.source.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.ErrorType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
|
||||
import com.sun.source.tree.CatchTree;
|
||||
import com.sun.source.tree.ClassTree;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.tree.MethodTree;
|
||||
import com.sun.source.tree.Scope;
|
||||
import com.sun.source.tree.Tree;
|
||||
|
||||
/**
|
||||
* Bridges JSR 199, JSR 269, and the Tree API.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class Trees {
|
||||
/**
|
||||
* Gets a Trees object for a given CompilationTask.
|
||||
* @param task the compilation task for which to get the Trees object
|
||||
* @throws IllegalArgumentException if the task does not support the Trees API.
|
||||
*/
|
||||
public static Trees instance(CompilationTask task) {
|
||||
String taskClassName = task.getClass().getName();
|
||||
if (!taskClassName.equals("com.sun.tools.javac.api.JavacTaskImpl")
|
||||
&& !taskClassName.equals("com.sun.tools.javac.api.BasicJavacTask"))
|
||||
throw new IllegalArgumentException();
|
||||
return getJavacTrees(CompilationTask.class, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Trees object for a given ProcessingEnvironment.
|
||||
* @param env the processing environment for which to get the Trees object
|
||||
* @throws IllegalArgumentException if the env does not support the Trees API.
|
||||
*/
|
||||
public static Trees instance(ProcessingEnvironment env) {
|
||||
if (!env.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment"))
|
||||
throw new IllegalArgumentException();
|
||||
return getJavacTrees(ProcessingEnvironment.class, env);
|
||||
}
|
||||
|
||||
static Trees getJavacTrees(Class<?> argType, Object arg) {
|
||||
try {
|
||||
ClassLoader cl = arg.getClass().getClassLoader();
|
||||
Class<?> c = Class.forName("com.sun.tools.javac.api.JavacTrees", false, cl);
|
||||
argType = Class.forName(argType.getName(), false, cl);
|
||||
Method m = c.getMethod("instance", new Class<?>[] { argType });
|
||||
return (Trees) m.invoke(null, new Object[] { arg });
|
||||
} catch (Throwable e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a utility object for obtaining source positions.
|
||||
*/
|
||||
public abstract SourcePositions getSourcePositions();
|
||||
|
||||
/**
|
||||
* Gets the Tree node for a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract Tree getTree(Element element);
|
||||
|
||||
/**
|
||||
* Gets the ClassTree node for a given TypeElement.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract ClassTree getTree(TypeElement element);
|
||||
|
||||
/**
|
||||
* Gets the MethodTree node for a given ExecutableElement.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract MethodTree getTree(ExecutableElement method);
|
||||
|
||||
/**
|
||||
* Gets the Tree node for an AnnotationMirror on a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract Tree getTree(Element e, AnnotationMirror a);
|
||||
|
||||
/**
|
||||
* Gets the Tree node for an AnnotationValue for an AnnotationMirror on a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract Tree getTree(Element e, AnnotationMirror a, AnnotationValue v);
|
||||
|
||||
/**
|
||||
* Gets the path to tree node within the specified compilation unit.
|
||||
*/
|
||||
public abstract TreePath getPath(CompilationUnitTree unit, Tree node);
|
||||
|
||||
/**
|
||||
* Gets the TreePath node for a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract TreePath getPath(Element e);
|
||||
|
||||
/**
|
||||
* Gets the TreePath node for an AnnotationMirror on a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract TreePath getPath(Element e, AnnotationMirror a);
|
||||
|
||||
/**
|
||||
* Gets the TreePath node for an AnnotationValue for an AnnotationMirror on a given Element.
|
||||
* Returns null if the node can not be found.
|
||||
*/
|
||||
public abstract TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v);
|
||||
|
||||
/**
|
||||
* Gets the Element for the Tree node identified by a given TreePath.
|
||||
* Returns null if the element is not available.
|
||||
* @throws IllegalArgumentException is the TreePath does not identify
|
||||
* a Tree node that might have an associated Element.
|
||||
*/
|
||||
public abstract Element getElement(TreePath path);
|
||||
|
||||
/**
|
||||
* Gets the TypeMirror for the Tree node identified by a given TreePath.
|
||||
* Returns null if the TypeMirror is not available.
|
||||
* @throws IllegalArgumentException is the TreePath does not identify
|
||||
* a Tree node that might have an associated TypeMirror.
|
||||
*/
|
||||
public abstract TypeMirror getTypeMirror(TreePath path);
|
||||
|
||||
/**
|
||||
* Gets the Scope for the Tree node identified by a given TreePath.
|
||||
* Returns null if the Scope is not available.
|
||||
*/
|
||||
public abstract Scope getScope(TreePath path);
|
||||
|
||||
/**
|
||||
* Gets the doc comment, if any, for the Tree node identified by a given TreePath.
|
||||
* Returns null if no doc comment was found.
|
||||
* @see DocTrees#getDocCommentTree(TreePath)
|
||||
*/
|
||||
public abstract String getDocComment(TreePath path);
|
||||
|
||||
/**
|
||||
* Checks whether a given type is accessible in a given scope.
|
||||
* @param scope the scope to be checked
|
||||
* @param type the type to be checked
|
||||
* @return true if {@code type} is accessible
|
||||
*/
|
||||
public abstract boolean isAccessible(Scope scope, TypeElement type);
|
||||
|
||||
/**
|
||||
* Checks whether the given element is accessible as a member of the given
|
||||
* type in a given scope.
|
||||
* @param scope the scope to be checked
|
||||
* @param member the member to be checked
|
||||
* @param type the type for which to check if the member is accessible
|
||||
* @return true if {@code member} is accessible in {@code type}
|
||||
*/
|
||||
public abstract boolean isAccessible(Scope scope, Element member, DeclaredType type);
|
||||
|
||||
/**
|
||||
* Gets the original type from the ErrorType object.
|
||||
* @param errorType The errorType for which we want to get the original type.
|
||||
* @return javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
|
||||
*/
|
||||
public abstract TypeMirror getOriginalType(ErrorType errorType);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* tree within the provided compilation unit
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param t the tree to use as a position hint
|
||||
* @param root the compilation unit that contains tree
|
||||
*/
|
||||
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
|
||||
com.sun.source.tree.Tree t,
|
||||
com.sun.source.tree.CompilationUnitTree root);
|
||||
|
||||
/**
|
||||
* Gets the lub of an exception parameter declared in a catch clause.
|
||||
* @param tree the tree for the catch clause
|
||||
* @return The lub of the exception parameter
|
||||
*/
|
||||
public abstract TypeMirror getLub(CatchTree tree);
|
||||
}
|
||||
34
jdkSrc/jdk8/com/sun/source/util/package-info.java
Normal file
34
jdkSrc/jdk8/com/sun/source/util/package-info.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides utilities for operations on abstract syntax trees (AST).
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
@jdk.Exported
|
||||
package com.sun.source.util;
|
||||
Reference in New Issue
Block a user