当前位置: 首页>>代码示例>>Java>>正文


Java Tree类代码示例

本文整理汇总了Java中com.sun.source.tree.Tree的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tree类属于com.sun.source.tree包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scan

import com.sun.source.tree.Tree; //导入依赖的package包/类
protected <R, P> R scan(CancellableTreePathScanner<R, P> scanner, Tree toScan, P p) {
    if (isCancelled())
        return null;
    
    try {
        synchronized (this) {
            this.pathScanner = scanner;
        }
        
        if (isCancelled())
            return null;
        
        return scanner.scan(toScan, p);
    } finally {
        synchronized (this) {
            this.pathScanner = null;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ScanningCancellableTask.java

示例2: scan

import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
public Tree scan(Tree tree, Element p) {
    final TreePath currentPath = getCurrentPath();
    if(docScanner != null && tree != null && currentPath != null) {
        switch(tree.getKind()) {
            case METHOD:
            case ANNOTATION_TYPE:
            case CLASS:
            case ENUM:
            case INTERFACE:
            case VARIABLE:
                TreePath path = new TreePath(currentPath, tree);
                scanJavadoc(path, p);
            default:
                break;
        }
    }
    return super.scan(tree, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:RefactoringVisitor.java

示例3: visitThrow

import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
public Boolean visitThrow(ThrowTree node, Void p) {
    TypeMirror type = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
    boolean isCaught = false;

    OUTER: for (Pair<Set<TypeMirror>, Tree> pair : caughtExceptions) {
        Set<TypeMirror> caught = pair.first();
        for (TypeMirror c : caught) {
            if (info.getTypes().isSubtype(type, c)) {
                isCaught = true;
                targetTrees.add(pair.second());
                break OUTER;
            }
        }
    }

    return super.visitThrow(node, p) == Boolean.TRUE || !isCaught;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Utilities.java

示例4: getJavaSource

import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected JavaSource getJavaSource(Phase p) {
    if (treePathHandle == null && docTreePathHandle == null) {
        return null;
    }
    switch (p) {
        case PRECHECK:
        case FASTCHECKPARAMETERS:
            return JavaSource.forFileObject(docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
                                                                     : treePathHandle.getFileObject());
        case PREPARE:
        case CHECKPARAMETERS:
            if(treePathHandle != null && treePathHandle.getKind() == Tree.Kind.LABELED_STATEMENT) {
                return JavaSource.forFileObject(treePathHandle.getFileObject());
            }
            ClasspathInfo cpInfo = getClasspathInfo(refactoring);
            JavaSource source = JavaSource.create(cpInfo, docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
                                                                     : treePathHandle.getFileObject());
            return source;
            
    }
    throw new IllegalStateException();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:RenameRefactoringPlugin.java

示例5: DiffContext

import com.sun.source.tree.Tree; //导入依赖的package包/类
/**
 * Note: the constructor is only used when creating new compilation units; a special flag will be set up, so an initial comment is not skipped.
 */
public DiffContext(CompilationInfo copy, CompilationUnitTree cut, String code, PositionConverter positionConverter, FileObject file, Set<Tree> syntheticTrees, CompilationUnitTree mainUnit, String mainCode) {
    this.tokenSequence = TokenHierarchy.create(code, JavaTokenId.language()).tokenSequence(JavaTokenId.language());
    this.origText = code;
    this.style = getCodeStyle(copy);
    this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext();
    this.origUnit = (JCCompilationUnit) cut;
    this.trees = copy.getTrees();
    this.doc = null;
    this.positionConverter = positionConverter;
    this.file = file;
    this.syntheticTrees = syntheticTrees;
    this.mainUnit = (JCCompilationUnit) mainUnit;
    this.mainCode = mainCode;
    
    this.textLength = copy.getSnapshot() == null ? Integer.MAX_VALUE : copy.getSnapshot().getOriginalOffset(copy.getSnapshot().getText().length());
    this.blockSequences = new BlockSequences(this.tokenSequence, doc, textLength);
    this.forceInitialComment = true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:DiffContext.java

示例6: resolve

import com.sun.source.tree.Tree; //导入依赖的package包/类
public TreePath resolve(CompilationInfo compilationInfo) throws IllegalArgumentException {
    TreePath p = parent.resolve(compilationInfo);

    if (p == null) return null;

    List<Tree> children = listChildren(p.getLeaf());

    if (index < children.size()) {
        Tree t = children.get(index);

        if (t.getKind() == kind) {
            return new TreePath(p, t);
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TreePathHandle.java

示例7: isFakeClass

import com.sun.source.tree.Tree; //导入依赖的package包/类
public static boolean isFakeClass(Tree t) {
    if (!(t instanceof ClassTree)) {
        return false;
    }

    ClassTree ct = (ClassTree) t;

    if (ct.getMembers().isEmpty()) {
        return false;
    }

    CharSequence wildcardTreeName = Utilities.getWildcardTreeName(ct.getMembers().get(0));

    if (wildcardTreeName == null) {
        return false;
    }

    return wildcardTreeName.toString().startsWith("$$");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Utilities.java

示例8: isCaretInsideDeclarationName

import com.sun.source.tree.Tree; //导入依赖的package包/类
private static boolean isCaretInsideDeclarationName(CompilationInfo info, Tree t, TreePath path, int caret) {
    try {
        switch (t.getKind()) {
            case ANNOTATION_TYPE:
            case CLASS:
            case ENUM:
            case INTERFACE:
            case METHOD:
            case VARIABLE:
                int[] span = org.netbeans.modules.java.editor.base.semantic.Utilities.findIdentifierSpan(path, info, info.getDocument());

                if (span == null || span[0] == (-1) || span[1] == (-1)) {
                    return false;
                }

                return span[0] <= caret && caret <= span[1];
            default:
                return false;
        }

    } catch (IOException iOException) {
        Exceptions.printStackTrace(iOException);
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:GoToSupport.java

示例9: checkAmbiguous

import com.sun.source.tree.Tree; //导入依赖的package包/类
/**
 * Checks whether a method or constructor call would become ambiguous if the parameter type changes.
 * 
 * @param info compilation context
 * @param parentExec path to the constructor or method invocation
 * @param argIndex
 * @param casteeType
 * @return 
 */
private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) {
    CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN);
    String prefix = null;
    if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) {
        prefix = "(" + altType + ")"; // NOI18N
    }
    Tree leaf = parentExec.getLeaf();
    List<? extends Tree> arguments;
    if (leaf instanceof MethodInvocationTree) {
        MethodInvocationTree mi = (MethodInvocationTree)leaf;
        arguments = mi.getArguments();
    } else {
        arguments = ((NewClassTree)leaf).getArguments();
    }
    Tree argTree = arguments.get(argIndex);
    TreePath argPath = new TreePath(parentExec, argTree);
    return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:TooStrongCast.java

示例10: performRewrite

import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    TreePath p = ctx.getPath();
    if (p.getLeaf().getKind() != Tree.Kind.NEW_CLASS) {
        return;
    }
    NewClassTree origNct = (NewClassTree)p.getLeaf();
    if (origNct.getArguments().size() != 1) {
        return;
    }
    NewClassTree nct = GeneratorUtilities.get(ctx.getWorkingCopy()).importComments(origNct, ctx.getWorkingCopy().getCompilationUnit());
    ExpressionTree charArg = nct.getArguments().get(0);
    TreeMaker mk = ctx.getWorkingCopy().getTreeMaker();
    
    ExpressionTree newExpr = mk.NewClass(nct.getEnclosingExpression(), (List<ExpressionTree>)nct.getTypeArguments(), nct.getIdentifier(), 
            Collections.<ExpressionTree>emptyList(), nct.getClassBody());

    Tree replace = mk.MethodInvocation(
            Collections.<ExpressionTree>emptyList(), 
            mk.MemberSelect(newExpr, "append"), // NOI18N
            Collections.singletonList(charArg));
    ctx.getWorkingCopy().rewrite(nct, replace);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:StringBufferCharConstructor.java

示例11: generateMethodContents

import com.sun.source.tree.Tree; //导入依赖的package包/类
private void generateMethodContents(List<StatementTree> methodStatements) {
    Iterator<TypeMirrorHandle> additionalType = additionalLocalTypes.iterator();
    Iterator<String> additionalName = additionalLocalNames.iterator();
    while (additionalType.hasNext() && additionalName.hasNext()) {
        TypeMirror tm = additionalType.next().resolve(copy);
        if (tm == null) {
            //XXX:
            return;
        }
        Tree type = make.Type(tm);
        methodStatements.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), additionalName.next(), type, null));
    }
    if (from == to && statements.get(from).getKind() == Tree.Kind.BLOCK) {
        methodStatements.addAll(((BlockTree) statements.get(from)).getStatements());
    } else {
        methodStatements.addAll(statements.subList(from, to + 1));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:IntroduceMethodFix.java

示例12: moveToEnd

import com.sun.source.tree.Tree; //导入依赖的package包/类
public void moveToEnd(Tree t) {
    if (t == null) {
        return ;
    }

    long end = sourcePositions.getEndPosition(info.getCompilationUnit(), t);

    if (end == (-1))
        return ;

    if (t.getKind() == Kind.ARRAY_TYPE) {
        moveToEnd(((ArrayTypeTree) t).getType());
        return ;
    }
    moveToOffset(end);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TokenList.java

示例13: performRewrite

import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    // path should be the typecast expression
    TreePath path = ctx.getPath();
    TreePath exprPath = exprHandle.resolve(ctx.getWorkingCopy());
    
    if (path.getLeaf().getKind() != Tree.Kind.TYPE_CAST || exprPath == null || !EXPRESSION_KINDS.contains(exprPath.getLeaf().getKind())) {
        // PENDING - some message ?
        return;
    }
    WorkingCopy copy = ctx.getWorkingCopy();
    TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
    TypeCastTree cast = (TypeCastTree)path.getLeaf();
    // rewrite the type cast to the casted Math.random()
    copy.rewrite(path.getLeaf(), cast.getExpression());
    // rewrite the outermost expression to a typecast of it
    ExpressionTree expr = (ExpressionTree)exprPath.getLeaf();
    if (expr.getKind() != Tree.Kind.PARENTHESIZED) {
        expr = make.Parenthesized(expr);
    }
    copy.rewrite(exprPath.getLeaf(), make.TypeCast(cast.getType(), (ExpressionTree)expr));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:MathRandomCast.java

示例14: computeMethodInvocation

import com.sun.source.tree.Tree; //导入依赖的package包/类
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;
    
    for (Tree param : nat.getArguments()) {
        errorInRealArguments |= param == error;
    }
    
    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CreateElementUtilities.java

示例15: getStart

import com.sun.source.tree.Tree; //导入依赖的package包/类
public int getStart() {
    final int[] result = new int[] {-1};

    try {
        JavaSource.create(info.getClasspathInfo()).runUserActionTask(new Task<CompilationController>() {
            public void run(CompilationController parameter) throws Exception {
                Tree tree = info.getTrees().getTree(element);
                if (tree != null) {
                    result[0] = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tree);
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return result[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ElementNode.java


注:本文中的com.sun.source.tree.Tree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。