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


Java TreeUtilities.parseType方法代码示例

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


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

示例1: findMethod

import org.netbeans.api.java.source.TreeUtilities; //导入方法依赖的package包/类
/** Gets the method we are looking for
 */
private static ElementHandle findMethod(CompilationController ctrl, TypeElement ce, String member) {
    TreeUtilities utils = ctrl.getTreeUtilities();

    int pi = member.indexOf( '(' );
    String name = member.substring( 0, pi );

    StringTokenizer tokenizer = new StringTokenizer( member.substring( pi ), " ,()" ); // NOI18N
    List<TypeMirror> paramList = new ArrayList<TypeMirror>();

    while( tokenizer.hasMoreTokens() ) {
        String token = tokenizer.nextToken();
        if (token.endsWith("...")) { // NOI18N
            // translate varargs to array
            token = token.substring(0, token.length() - 3);
            token += "[]"; // NOI18N
        }
        TypeMirror type = utils.parseType(token, ce);
        paramList.add(type);
    }
    
    // search method or constructor
    for (Element e: ce.getEnclosedElements()) {
        if (e.getKind() == ElementKind.METHOD
                && name.equals(e.getSimpleName().toString())
                && compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
            return ElementHandle.create(e);
        } else if (e.getKind() == ElementKind.CONSTRUCTOR
                && name.equals(ce.getSimpleName().toString())
                && compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
            return ElementHandle.create(e);
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:SrcFinder.java

示例2: check

import org.netbeans.api.java.source.TreeUtilities; //导入方法依赖的package包/类
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
    if (attrib.getModelElement() instanceof Version) {
        TreeUtilities treeUtils = ctx.getCompilationInfo().getTreeUtilities();
        Types types = ctx.getCompilationInfo().getTypes();
        TypeMirror attrType = attrib.getType();

        for (String typeName : validVersionTypes) {
            TypeMirror type = treeUtils.parseType(typeName,
                    ctx.getJavaClass());

            if (type != null && types.isSameType(attrType, type)) {
                return null;
            }
        }
        Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());

        Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
                ctx.getCompilationInfo(), elementTree);

        ErrorDescription error = ErrorDescriptionFactory.forSpan(
                hc,
                underlineSpan.getStartOffset(),
                underlineSpan.getEndOffset(),
                NbBundle.getMessage(ValidVersionType.class, "MSG_InvalidVersionType"));//TODO: may need to have "error" fo some/ warning for another
        return Collections.singleton(error);

    }

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

示例3: getMethods

import org.netbeans.api.java.source.TreeUtilities; //导入方法依赖的package包/类
private List<? extends ExecutableElement> getMethods(
            final @NonNull String clz,
            final @NullAllowed String methodName,
            final boolean rt,
            final @NullAllowed String returnType,
            final @NullAllowed String... parameterTypes) throws QueryException {
        final TypeElement te = findClass(clz);
        if (te == null) {
            return Collections.<ExecutableElement>emptyList();
        }
        final TreeUtilities treeUtils = control.getTreeUtilities();
        final Types types = control.getTypes();
        final List<? extends TypeElement> topLevels = control.getTopLevelElements();
        if (topLevels.isEmpty()) {
            return Collections.<ExecutableElement>emptyList();
        }
        TypeMirror rType = null;
        List<TypeMirror> pTypes = null;
        if (returnType != null) {
            rType = treeUtils.parseType(
                returnType,
                topLevels.get(0));
            if (rType == null) {
                return Collections.<ExecutableElement>emptyList();
            } else if (rt) {
                rType = types.erasure(rType);
            }
        }
        if (parameterTypes != null) {
            pTypes = new ArrayList<TypeMirror>(parameterTypes.length + 1);
            for (final String parameterType : parameterTypes) {
                TypeMirror tm = treeUtils.parseType(
                    parameterType,
                    topLevels.get(0));
                if (tm == null) {
                    return Collections.<ExecutableElement>emptyList();
                } else if (rt) {
                    tm = types.erasure(tm);
                }
                pTypes.add(tm);
            }
        }
        final List<ExecutableElement> result = new ArrayList<ExecutableElement>();
nextM:  for (ExecutableElement me : ElementFilter.methodsIn(te.getEnclosedElements())) {
            if (methodName != null && !methodName.contentEquals(me.getSimpleName())) {
                continue nextM;
            }
            if (pTypes != null) {
                final List<? extends VariableElement> params = me.getParameters();
                if (params.size() != pTypes.size()) {
                    continue nextM;
                }
                final Iterator<? extends VariableElement> paramsIt = params.iterator();
                final Iterator<? extends TypeMirror> pTypesIt = pTypes.iterator();
                for (;paramsIt.hasNext();) {
                    if (!isSameType(types, pTypesIt.next(), paramsIt.next().asType(), rt)) {
                        continue nextM;
                    }
                }
            }
            if (!isSameType(types, rType, me.getReturnType(), rt)) {
                continue nextM;
            }
            result.add(me);
        }
        return result;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:68,代码来源:JavaOperationsImpl.java

示例4: check

import org.netbeans.api.java.source.TreeUtilities; //导入方法依赖的package包/类
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
    if (!(attrib.getModelElement() instanceof Basic)) {
        return null;
    }

    TreeUtilities treeUtils = ctx.getCompilationInfo().getTreeUtilities();
    Types types = ctx.getCompilationInfo().getTypes();
    TypeMirror attrType = attrib.getType();

    TypeMirror typeSerializable = treeUtils.parseType("java.io.Serializable", //NOI18N
            ctx.getJavaClass());

    TypeMirror typeEnum = treeUtils.parseType("java.lang.Enum", //NOI18N
            ctx.getJavaClass());

    TypeMirror typeCollection = treeUtils.parseType("java.util.Collection", //NOI18N
            ctx.getJavaClass());

    if (types.isAssignable(attrType, typeSerializable)
            || types.isAssignable(attrType, typeEnum)
            || types.isAssignable(attrType, typeCollection)) {
        return null;
    }

    for (String typeName : fixedBasicTypes) {
        TypeMirror type = treeUtils.parseType(typeName,
                ctx.getJavaClass());

        if (type != null && types.isSameType(attrType, type)) {
            return null;
        }
    }

    if (Utilities.hasAnnotation(attrib.getJavaElement(), JPAAnnotations.ELEMENT_COLLECTION)) {
        //according to annotation it's not basic  type and need to be verified in appropriate validator
        return null;
    }
    if (Utilities.hasAnnotation(attrib.getJavaElement(), JPAAnnotations.EMBEDDED)) {
        //@Embedded, see also #167419
        return null;
    }
    Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());

    Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
            ctx.getCompilationInfo(), elementTree);

    ErrorDescription error = ErrorDescriptionFactory.forSpan(
            hc,
            underlineSpan.getStartOffset(),
            underlineSpan.getEndOffset(),
            NbBundle.getMessage(ValidBasicType.class, "MSG_ValidBasicType"));//TODO: may need to have "error" as default
    return Collections.singleton(error);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:ValidBasicType.java


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