當前位置: 首頁>>代碼示例>>Java>>正文


Java Tree.accept方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:EditorContextSupport.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:EvaluatorVisitor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:EvaluatorVisitor.java

示例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;
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:24,代碼來源:TreePathScanner2.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:TreePathHandle.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:EvaluatorVisitor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:EvaluatorVisitor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:80,代碼來源:EditorContextSupport.java

示例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);
                }
            }
        }
    }

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:82,代碼來源:EditorContextSupport.java

示例10: accept

import com.sun.source.tree.Tree; //導入方法依賴的package包/類
private static void accept(TreeVisitor<?, ?> visitor, Tree node) {
  node.accept(visitor, null);
}
 
開發者ID:forax,項目名稱:moduletools,代碼行數:4,代碼來源:JavacModuleParser.java

示例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);
}
 
開發者ID:FermioCloud,項目名稱:java-code-templates,代碼行數:11,代碼來源:Inventory.java


注:本文中的com.sun.source.tree.Tree.accept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。