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


Java CompilationInfo.getTrees方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo.getTrees方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo.getTrees方法的具体用法?Java CompilationInfo.getTrees怎么用?Java CompilationInfo.getTrees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.CompilationInfo的用法示例。


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

示例1: findTopClassElems

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
/**
 * 
 * @return  list of {@code Element}s representing top classes,
 *          or an empty list of none were found
 */
private static List<TypeElement> findTopClassElems(
                                    CompilationInfo compInfo,
                                    CompilationUnitTree compilationUnit,
                                    Filter filter) {
    List<? extends Tree> typeDecls = compilationUnit.getTypeDecls();
    if ((typeDecls == null) || typeDecls.isEmpty()) {
        return Collections.<TypeElement>emptyList();
    }
    
    List<TypeElement> result = new ArrayList<TypeElement>(typeDecls.size());

    Trees trees = compInfo.getTrees();
    for (Tree typeDecl : typeDecls) {
        if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) {
            Element element = trees.getElement(
                    new TreePath(new TreePath(compilationUnit), typeDecl));
            TypeElement typeElement = (TypeElement) element;
            if (filter.passes(typeElement, compInfo)) {
                result.add(typeElement);
            }
        }
    }

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

示例2: DiffContext

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
public DiffContext(CompilationInfo copy, Set<Tree> syntheticTrees) {
    this.tokenSequence = copy.getTokenHierarchy().tokenSequence(JavaTokenId.language());
    this.mainCode = this.origText = copy.getText();
    this.style = getCodeStyle(copy);
    this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext();
    this.mainUnit = this.origUnit = (JCCompilationUnit) copy.getCompilationUnit();
    this.trees = copy.getTrees();
    this.doc = copy.getSnapshot().getSource().getDocument(false); //TODO: true or false?
    this.positionConverter = copy.getPositionConverter();
    this.file = copy.getFileObject();
    this.syntheticTrees = syntheticTrees;
    
    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 = false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DiffContext.java

示例3: run

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:RenameConstructor.java

示例4: addInnerClasses

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private void addInnerClasses(TypeElement te, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for (Element e : controller.getElementUtilities().getMembers(te.asType(), null)) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && trees.isAccessible(scope, (TypeElement)e) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JavadocCompletionQuery.java

示例5: addPackageContent

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    ElementUtilities eu = controller.getElementUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for(Element e : pe.getEnclosedElements()) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, (TypeElement)e)
                    && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
                    && !Utilities.isExcluded(eu.getElementName(e, true))) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavadocCompletionQuery.java

示例6: getDelegate

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@Override
protected JavaCompletionItem getDelegate(CompilationInfo info, Scope scope, TypeElement te) {
    Elements elements = info.getElements();
    Trees trees = info.getTrees();
    if (te != null) {
        Element element = null;
        boolean multiVersion = false;
        for (Element e : te.getEnclosedElements()) {
            if ((e.getKind().isField() || e.getKind() == ElementKind.METHOD)
                    && name.contentEquals(Utilities.isCaseSensitive() ? e.getSimpleName() : e.getSimpleName().toString().toLowerCase())
                    && e.getModifiers().contains(Modifier.STATIC)
                    && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, e, (DeclaredType) te.asType())) {
                if (element != null) {
                    multiVersion = true;
                    break;
                }
                element = e;
            }
        }
        if (element != null) {
            name = element.getSimpleName().toString();
            return createStaticMemberItem(info, (DeclaredType) te.asType(), element, element.asType(), multiVersion, substitutionOffset, elements.isDeprecated(element), addSemicolon, getWhiteList());
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:LazyJavaCompletionItem.java

示例7: run

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@TriggerPatterns({
    @TriggerPattern(value="$left == $right", constraints={@ConstraintVariableType(variable="$left", type=STRING_TYPE),
                                                          @ConstraintVariableType(variable="$right", type=STRING_TYPE)}),
    @TriggerPattern(value="$left != $right", constraints={@ConstraintVariableType(variable="$left", type=STRING_TYPE),
                                                          @ConstraintVariableType(variable="$right", type=STRING_TYPE)})
})
public static ErrorDescription run(HintContext ctx) {
    CompilationInfo info = ctx.getInfo();
    TreePath treePath = ctx.getPath();
    Tree t = treePath.getLeaf();
    
    BinaryTree bt = (BinaryTree) t;
    
    TreePath left = new TreePath(treePath, bt.getLeftOperand() );
    TreePath right = new TreePath(treePath, bt.getRightOperand() );
    
    Trees trees = info.getTrees(); 
    TypeMirror leftType = left == null ? null : trees.getTypeMirror(left);
    TypeMirror rightType = right == null ? null : trees.getTypeMirror(right);

    if ( leftType != null && rightType != null && 
         STRING_TYPE.equals(leftType.toString()) && 
         STRING_TYPE.equals(rightType.toString())) {
        
        if (checkInsideGeneratedEquals(ctx, treePath, left.getLeaf(), right.getLeaf())) {
            return null;
        }

        FileObject file = info.getFileObject();
        TreePathHandle tph = TreePathHandle.create(treePath, info);
        ArrayList<Fix> fixes = new ArrayList<Fix>();
        boolean reverseOperands = false;
        if (bt.getLeftOperand().getKind() != Tree.Kind.STRING_LITERAL) {
            if (bt.getRightOperand().getKind() == Tree.Kind.STRING_LITERAL) {
                if (getStringLiteralsFirst(ctx.getPreferences())) {
                    reverseOperands = true;
                } else {
                    fixes.add(new WrongStringComparisonFix(tph, WrongStringComparisonFix.Kind.NULL_CHECK).toEditorFix());
                }
            } else {
                fixes.add(new WrongStringComparisonFix(tph, WrongStringComparisonFix.Kind.ternaryNullCheck(getTernaryNullCheck(ctx.getPreferences()))).toEditorFix());
            }
        }
        fixes.add(new WrongStringComparisonFix(tph, WrongStringComparisonFix.Kind.reverseOperands(reverseOperands)).toEditorFix());
        return ErrorDescriptionFactory.forTree(
                  ctx,
                  t,
                  NbBundle.getMessage(WrongStringComparison.class, "LBL_WrongStringComparison"), 
                  fixes.toArray(new Fix[0]));

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


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