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


Java CompilationInfo.getTypes方法代码示例

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


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

示例1: ConvertToLambdaPreconditionChecker

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
public ConvertToLambdaPreconditionChecker(TreePath pathToNewClassTree, CompilationInfo info) {

        this.pathToNewClassTree = pathToNewClassTree;
        this.newClassTree = (NewClassTree) pathToNewClassTree.getLeaf();
        this.info = info;
        this.types = info.getTypes();

        Element el = info.getTrees().getElement(pathToNewClassTree);
        if (el != null && el.getKind() == ElementKind.CONSTRUCTOR) {
            createdClass = el.getEnclosingElement();
        } else {
            createdClass = null;
        }
        this.lambdaMethodTree = getMethodFromFunctionalInterface(this.pathToNewClassTree);
        this.localScope = getScopeFromTree(this.pathToNewClassTree);
        this.ownerClass = findFieldOwner();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ConvertToLambdaPreconditionChecker.java

示例2: 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

示例3: 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

示例4: 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

示例5: detectKind

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static KindOfType detectKind(CompilationInfo info, TypeMirror tm) {
    if (tm.getKind().isPrimitive()) {
        return KindOfType.valueOf(tm.getKind().name());
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        return ((ArrayType) tm).getComponentType().getKind().isPrimitive() ? KindOfType.ARRAY_PRIMITIVE : KindOfType.ARRAY;
    }

    if (tm.getKind() == TypeKind.DECLARED) {
        Types t = info.getTypes();
        TypeElement en = info.getElements().getTypeElement("java.lang.Enum");

        if (en != null) {
            if (t.isSubtype(tm, t.erasure(en.asType()))) {
                return KindOfType.ENUM;
            }
        }

        if (((DeclaredType)tm).asElement().getKind().isClass() && ((TypeElement) ((DeclaredType) tm).asElement()).getQualifiedName().contentEquals("java.lang.String")) {
            return KindOfType.STRING;
        }
    }

    return KindOfType.OTHER;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:EqualsHashCodeGenerator.java

示例6: throwsNonRuntimeExceptions

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
/**
 */
private static boolean throwsNonRuntimeExceptions(CompilationInfo compInfo,
                                                  ExecutableElement method) {
    List<? extends TypeMirror> thrownTypes = method.getThrownTypes();
    if (thrownTypes.isEmpty()) {
        return false;
    }

    String runtimeExcName = "java.lang.RuntimeException";           //NOI18N
    TypeElement runtimeExcElement = compInfo.getElements()
                                    .getTypeElement(runtimeExcName);
    if (runtimeExcElement == null) {
        Logger.getLogger("testng").log(                              //NOI18N
                Level.WARNING,
                "Could not find TypeElement for "                   //NOI18N
                        + runtimeExcName);
        return true;
    }

    Types types = compInfo.getTypes();
    TypeMirror runtimeExcType = runtimeExcElement.asType();
    for (TypeMirror exceptionType : thrownTypes) {
        if (!types.isSubtype(exceptionType, runtimeExcType)) {
            return true;
        }
    }

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

示例7: throwsNonRuntimeExceptions

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
/**
 */
private static boolean throwsNonRuntimeExceptions(CompilationInfo compInfo,
                                                  ExecutableElement method) {
    List<? extends TypeMirror> thrownTypes = method.getThrownTypes();
    if (thrownTypes.isEmpty()) {
        return false;
    }

    String runtimeExcName = "java.lang.RuntimeException";           //NOI18N
    TypeElement runtimeExcElement = compInfo.getElements()
                                    .getTypeElement(runtimeExcName);
    if (runtimeExcElement == null) {
        Logger.getLogger("junit").log(                              //NOI18N
                Level.WARNING,
                "Could not find TypeElement for "                   //NOI18N
                        + runtimeExcName);
        return true;
    }

    Types types = compInfo.getTypes();
    TypeMirror runtimeExcType = runtimeExcElement.asType();
    for (TypeMirror exceptionType : thrownTypes) {
        if (!types.isSubtype(exceptionType, runtimeExcType)) {
            return true;
        }
    }

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

示例8: testType

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static boolean testType(CompilationInfo info, TypeMirror actualType, String superClass) {
    TypeElement juCollection = info.getElements().getTypeElement(superClass);

    if (juCollection == null) return false;

    Types t = info.getTypes();

    return t.isAssignable(t.erasure(actualType), t.erasure(juCollection.asType()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Unbalanced.java


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