本文整理汇总了Java中com.sun.source.tree.Tree.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.accept方法的具体用法?Java Tree.accept怎么用?Java Tree.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.Tree
的用法示例。
在下文中一共展示了Tree.accept方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeMethodArguments
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static MethodArgument[] computeMethodArguments(CompilationController ci,
EditorContext.Operation operation,
ASTOperationCreationDelegate opCreationDelegate)
throws IOException {
EditorContext.MethodArgument args[];
if (!PreferredCCParser.toPhase(ci, JavaSource.Phase.RESOLVED, LOG)) {
return null;
}
int offset = operation.getMethodEndPosition().getOffset();
Scope scope = ci.getTreeUtilities().scopeFor(offset);
Element method = scope.getEnclosingMethod();
if (method == null) {
return null;
}
Tree methodTree = ci.getTrees().getTree(method);
CompilationUnitTree cu = ci.getCompilationUnit();
MethodArgumentsScanner scanner =
new MethodArgumentsScanner(offset, cu, ci.getTrees().getSourcePositions(), true,
opCreationDelegate);
args = methodTree.accept(scanner, null);
args = scanner.getArguments();
return args;
}
示例2: visitDoWhileLoop
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Mirror visitDoWhileLoop(DoWhileLoopTree arg0, EvaluationContext evaluationContext) {
ExpressionTree condition = arg0.getCondition();
Tree statement = arg0.getStatement();
Mirror result = null;
do {
try {
evaluationContext.pushBlock();
Mirror res = statement.accept(this, evaluationContext);
if (res instanceof Break) {
break;
} else if (res instanceof Continue) {
continue;
}
if (res != null) {
result = res;
}
} finally {
evaluationContext.popBlock();
}
} while (evaluateCondition(arg0, evaluationContext, condition));
return result;
}
示例3: visitWhileLoop
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Mirror visitWhileLoop(WhileLoopTree arg0, EvaluationContext evaluationContext) {
ExpressionTree condition = arg0.getCondition();
Tree statement = arg0.getStatement();
Mirror result = null;
while (evaluateCondition(arg0, evaluationContext, condition)) {
try {
evaluationContext.pushBlock();
Mirror res = statement.accept(this, evaluationContext);
if (res instanceof Break) {
break;
} else if (res instanceof Continue) {
continue;
}
if (res != null) {
result = res;
}
} finally {
evaluationContext.popBlock();
}
}
return result;
}
示例4: scan
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
* Scan a single node.
* The current path is updated for the duration of the scan.
*/
@Override
public TreePath2 scan( Tree tree, Tree p )
{
if( tree == null )
{
return null;
}
TreePath2 prev = _path;
_path = new TreePath2( _path, tree );
try
{
return tree.accept( this, p );
}
finally
{
_path = prev;
}
}
示例5: listChildren
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static List<Tree> listChildren(@NonNull Tree t) {
final List<Tree> result = new LinkedList<Tree>();
t.accept(new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void scan(Tree node, Void p) {
result.add(node);
return null;
}
}, null);
return result;
}
示例6: visitForLoop
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Mirror visitForLoop(ForLoopTree arg0, EvaluationContext evaluationContext) {
try {
evaluationContext.pushBlock();
for (StatementTree st : arg0.getInitializer()) {
st.accept(this, evaluationContext);
}
Mirror result = null;
ExpressionTree condition = arg0.getCondition();
List<? extends ExpressionStatementTree> updateList = arg0.getUpdate();
StatementTree statement = arg0.getStatement();
while (condition == null || evaluateCondition(arg0, evaluationContext, condition)) {
Mirror value = null;
try {
evaluationContext.pushBlock();
value = statement.accept(this, evaluationContext);
if (value instanceof Break) {
break;
} else if (value instanceof Continue) {
continue;
}
if (value != null) {
result = value;
}
} finally {
evaluationContext.popBlock();
if ((value instanceof Continue) || !(value instanceof CommandMirror)) {
for (Tree tree : updateList) {
tree.accept(this, evaluationContext);
} // for
} // if
} // finally
} // while
return result;
} finally {
evaluationContext.popBlock();
}
}
示例7: visitIntersectionType
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Mirror visitIntersectionType(IntersectionTypeTree node, EvaluationContext p) {
// intersection type in a cast expression
List<? extends Tree> bounds = node.getBounds();
List<ReferenceType> typeList = new ArrayList<ReferenceType>();
for (Tree type : bounds) {
Mirror typeMirror = type.accept(this, p);
if (typeMirror instanceof ReferenceType) {
typeList.add((ReferenceType) typeMirror);
}
}
Type intersectionType = new IntersectionType(typeList.toArray(new ReferenceType[] {}));
subExpressionTypes.put(node, intersectionType);
return intersectionType;
}
示例8: computeOperations
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static EditorContext.Operation[] computeOperations(CompilationController ci,
int offset,
int lineNumber,
EditorContext.BytecodeProvider bytecodeProvider,
ASTOperationCreationDelegate opCreationDelegate) throws IOException {
if (!PreferredCCParser.toPhase(ci, JavaSource.Phase.RESOLVED, LOG)) {//TODO: ELEMENTS_RESOLVED may be sufficient
return new EditorContext.Operation[] {};
}
// We need the enclosing statement/block
Tree statementTree = findStatementInScope(ci.getTreeUtilities().pathFor(offset));
LOG.log(Level.FINE, "Statement tree found at line {0}:\n{1}\n", new Object[]{ lineNumber, statementTree });
if (statementTree == null) {
Scope scope = ci.getTreeUtilities().scopeFor(offset);
Element method = scope.getEnclosingMethod();
if (method == null) {
return new EditorContext.Operation[] {};
}
statementTree = ci.getTrees().getTree(method);
}
if (statementTree == null) { // method not found
return new EditorContext.Operation[] {};
}
CompilationUnitTree cu = ci.getCompilationUnit();
SourcePositions sp = ci.getTrees().getSourcePositions();
int statementStart = (int) cu.getLineMap().getLineNumber(sp.getStartPosition(cu, statementTree));
int statementEnd = (int) cu.getLineMap().getLineNumber(sp.getEndPosition(cu, statementTree));
ExpressionScanner scanner = new ExpressionScanner(lineNumber, statementStart, statementEnd,
cu, ci.getTrees().getSourcePositions());
ExpressionScanner.ExpressionsInfo info = new ExpressionScanner.ExpressionsInfo();
List<Tree> expTrees = statementTree.accept(scanner, info);
LOG.log(Level.FINE, "expression trees = {0}", expTrees);
//com.sun.source.tree.ExpressionTree expTree = scanner.getExpressionTree();
if (expTrees == null || expTrees.isEmpty()) {
return new EditorContext.Operation[] {};
}
int treeStartLine = Integer.MAX_VALUE;
int treeEndLine = 0;
for (int i = 0; i < expTrees.size(); i++) {
Tree tree = expTrees.get(i);
int start = (int) cu.getLineMap().getLineNumber(
sp.getStartPosition(cu, tree));
int end = (int) cu.getLineMap().getLineNumber(
sp.getEndPosition(cu, tree));
if (start == Diagnostic.NOPOS || end == Diagnostic.NOPOS) {
continue;
}
if (start < treeStartLine) {
treeStartLine = start;
}
if (end > treeEndLine) {
treeEndLine = end;
}
}
if (treeStartLine == Integer.MAX_VALUE) {
return null;
}
//t3 = System.nanoTime();
int[] indexes = bytecodeProvider.indexAtLines(treeStartLine, treeEndLine);
if (indexes == null) {
return null;
}
Map<Tree, EditorContext.Operation> nodeOperations = new HashMap<Tree, EditorContext.Operation>();
EditorContext.Operation[] ops = AST2Bytecode.matchSourceTree2Bytecode(
cu,
ci,
expTrees, info, bytecodeProvider.byteCodes(),
indexes,
bytecodeProvider.constantPool(),
opCreationDelegate,
nodeOperations);
if (ops != null) {
assignNextOperations(statementTree, cu, ci,
bytecodeProvider, opCreationDelegate,
expTrees, info, nodeOperations);
}
return ops;
}
示例9: assignNextOperations
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static void assignNextOperations(Tree methodTree,
CompilationUnitTree cu,
CompilationController ci,
EditorContext.BytecodeProvider bytecodeProvider,
ASTOperationCreationDelegate opCreationDelegate,
List<Tree> treeNodes,
ExpressionScanner.ExpressionsInfo info,
Map<Tree, EditorContext.Operation> nodeOperations) {
int length = treeNodes.size();
for (int treeIndex = 0; treeIndex < length; treeIndex++) {
Tree node = treeNodes.get(treeIndex);
Set<Tree> nextNodes = info.getNextExpressions(node);
if (nextNodes != null) {
EditorContext.Operation op = nodeOperations.get(node);
if (op == null) {
for (int backIndex = treeIndex - 1; backIndex >= 0; backIndex--) {
node = treeNodes.get(backIndex);
op = nodeOperations.get(node);
if (op != null) {
break;
}
}
}
if (op != null) {
for (Tree t : nextNodes) {
EditorContext.Operation nextOp = nodeOperations.get(t);
if (nextOp == null) {
SourcePositions sp = ci.getTrees().getSourcePositions();
int treeStartLine =
(int) cu.getLineMap().getLineNumber(
sp.getStartPosition(cu, t));
if (treeStartLine == Diagnostic.NOPOS) {
continue;
}
int treeEndLine =
(int) cu.getLineMap().getLineNumber(
sp.getEndPosition(cu, t));
if (treeEndLine == Diagnostic.NOPOS) {
continue;
}
ExpressionScanner scanner = new ExpressionScanner(treeStartLine, treeStartLine, treeEndLine,
cu, ci.getTrees().getSourcePositions());
ExpressionScanner.ExpressionsInfo newInfo = new ExpressionScanner.ExpressionsInfo();
List<Tree> newExpTrees = methodTree.accept(scanner, newInfo);
if (newExpTrees == null) {
continue;
}
treeStartLine =
(int) cu.getLineMap().getLineNumber(
sp.getStartPosition(cu, newExpTrees.get(0)));
treeEndLine =
(int) cu.getLineMap().getLineNumber(
sp.getEndPosition(cu, newExpTrees.get(newExpTrees.size() - 1)));
if (treeStartLine == Diagnostic.NOPOS || treeEndLine == Diagnostic.NOPOS) {
continue;
}
int[] indexes = bytecodeProvider.indexAtLines(treeStartLine, treeEndLine);
Map<Tree, EditorContext.Operation> newNodeOperations = new HashMap<Tree, EditorContext.Operation>();
/*Operation[] newOps = */AST2Bytecode.matchSourceTree2Bytecode(
cu,
ci,
newExpTrees, newInfo, bytecodeProvider.byteCodes(),
indexes,
bytecodeProvider.constantPool(),
opCreationDelegate,
newNodeOperations);
nextOp = newNodeOperations.get(t);
if (nextOp == null) {
// Next operation not found
System.err.println("Next operation not found!");
continue;
}
}
opCreationDelegate.addNextOperationTo(op, nextOp);
}
}
}
}
}
示例10: accept
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static void accept(TreeVisitor<?, ?> visitor, Tree node) {
node.accept(visitor, null);
}
示例11: referencesSubstitutableField
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
* Tests the given expression tree to see if it contains at least one
* identifier that exactly matches any substitutable field.
*
* @param node
* @return
*/
boolean referencesSubstitutableField(final Tree node) {
return node.accept(new TemplateFieldScanner(), null);
}