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


Java Types.isSubtype方法代碼示例

本文整理匯總了Java中javax.lang.model.util.Types.isSubtype方法的典型用法代碼示例。如果您正苦於以下問題:Java Types.isSubtype方法的具體用法?Java Types.isSubtype怎麽用?Java Types.isSubtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.util.Types的用法示例。


在下文中一共展示了Types.isSubtype方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: detectKind

import javax.lang.model.util.Types; //導入方法依賴的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,代碼來源:IntroduceLocalExtensionTransformer.java

示例2: typeToImport

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static TypeMirror typeToImport(CompilationInfo info, TreePath tp, TypeMirror origin) {
    if (tp.getLeaf().getKind() == Tree.Kind.MEMBER_SELECT) {
        MemberSelectTree mst = (MemberSelectTree) tp.getLeaf();
        if (mst.getExpression().getKind() == Tree.Kind.IDENTIFIER) {
            ClassIndex index = info.getClasspathInfo().getClassIndex();
            Types types = info.getTypes();
            Trees trees = info.getTrees();
            Scope scope = trees.getScope(tp);
            for (ElementHandle<TypeElement> teHandle : index.getDeclaredTypes(((IdentifierTree)mst.getExpression()).getName().toString(), ClassIndex.NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class))) {
                TypeElement te = teHandle.resolve(info);
                if (te != null && trees.isAccessible(scope, te)) {
                    TypeMirror toImport = te.asType();
                    if (types.isSubtype(toImport, origin)) {
                        return toImport;
                    }
                }
            }
        }
    }
    return origin;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JavaCompletionItem.java

示例3: sameMethod

import javax.lang.model.util.Types; //導入方法依賴的package包/類
protected boolean sameMethod(ExecutableElement method1, ExecutableElement method2) {
    if (!method1.getSimpleName().equals(method2.getSimpleName()))
        return false;
    Types typeUtils = builder.getProcessingEnvironment().getTypeUtils();
    if(!typeUtils.isSameType(method1.getReturnType(), method2.getReturnType())
            && !typeUtils.isSubtype(method2.getReturnType(), method1.getReturnType()))
        return false;
    List<? extends VariableElement> parameters1 = method1.getParameters();
    List<? extends VariableElement> parameters2 = method2.getParameters();
    if (parameters1.size() != parameters2.size())
        return false;
    for (int i = 0; i < parameters1.size(); i++) {
        if (!typeUtils.isSameType(parameters1.get(i).asType(), parameters2.get(i).asType()))
            return false;
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:WebServiceVisitor.java

示例4: throwsNonRuntimeExceptions

import javax.lang.model.util.Types; //導入方法依賴的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

示例5: findCommonSubtype

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private DeclaredType findCommonSubtype(DeclaredType type1, DeclaredType type2, Env<AttrContext> env) {
    List<DeclaredType> subtypes1 = getSubtypes(type1, env);
    List<DeclaredType> subtypes2 = getSubtypes(type2, env);
    if (subtypes1 == null || subtypes2 == null) return null;
    Types types = info.getTypes();
    for (DeclaredType subtype1 : subtypes1) {
        for (DeclaredType subtype2 : subtypes2) {
            if (types.isSubtype(subtype1, subtype2))
                return subtype1;
            if (types.isSubtype(subtype2, subtype1))
                return subtype2;
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:ElementUtilities.java

示例6: throwsNonRuntimeExceptions

import javax.lang.model.util.Types; //導入方法依賴的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

示例7: visitMethodInvocation

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Tree visitMethodInvocation(MethodInvocationTree node, Element p) {
    List<? extends ExpressionTree> arguments = node.getArguments();
    for (int i = 0; i < arguments.size(); i++) {
        ExpressionTree argument = arguments.get(i);
        Element argElement = asElement(argument); // TODO: Slow and misses ternary expressions
        if(p.equals(argElement)) {
            Element element = asElement(node);
            if (element.getKind() == ElementKind.METHOD) {
                ExecutableElement method = (ExecutableElement) element;
                VariableElement parameter = method.getParameters().get(i);
                Types types = workingCopy.getTypes();
                TypeMirror parameterType = parameter.asType();
                if(parameterType.getKind().equals(TypeKind.TYPEVAR)) {
                    TypeVariable typeVariable = (TypeVariable) parameterType;
                    TypeMirror upperBound = typeVariable.getUpperBound();
                    TypeMirror lowerBound = typeVariable.getLowerBound();
                    if(upperBound != null && !types.isSubtype(superTypeElement.asType(), upperBound)) {
                        isReplCandidate = false;
                    }
                    if(lowerBound != null && !types.isSubtype(lowerBound, superTypeElement.asType())) {
                        isReplCandidate = false;
                    }
                } else if(!types.isAssignable(superTypeElement.asType(), parameterType)) {
                    isReplCandidate = false;
                }
            }
        }
    }
    return super.visitMethodInvocation(node, p);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:VarUsageVisitor.java

示例8: isRefactorable

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public Boolean isRefactorable() {
    prospectives = this.getListRepresentation(loop.getStatement(), true);
    if (prospectives != null && !prospectives.isEmpty()) {
        prospectives.get(prospectives.size() - 1).eagerize();
        if (this.untrasformable) {
            return false;
        }
        for ( int i = 0; i < prospectives.size() - 1; i++) {
            if (!prospectives.get(i).isLazy()) {
                return false;
            }
        }
        hasIterable = false;
        VariableTree var = loop.getVariable();
        TypeElement el = workingCopy.getElements().getTypeElement("java.lang.Iterable"); // NOI18N
        if (el != null) {
            TreePath path = TreePath.getPath(workingCopy.getCompilationUnit(), loop.getExpression());
            TypeMirror m = workingCopy.getTrees().getTypeMirror(path);
            Types types  = workingCopy.getTypes();
            hasIterable = 
                    types.isSubtype(
                        types.erasure(m),
                        types.erasure(el.asType())
                    );
        }
        prospectives = ProspectiveOperation.mergeIntoComposableOperations(prospectives);
        return prospectives != null;

    } else {
        return false;
    }

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

示例9: findServiceAnnotation

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private List<TypeMirror> findServiceAnnotation(Element e) throws LayerGenerationException {
    for (AnnotationMirror ann : e.getAnnotationMirrors()) {
        if (!ProjectServiceProvider.class.getName().equals(ann.getAnnotationType().toString())) {
            continue;
        }
        for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> attr : ann.getElementValues().entrySet()) {
            if (!attr.getKey().getSimpleName().contentEquals("service")) {
                continue;
            }
            List<TypeMirror> r = new ArrayList<TypeMirror>();
            for (Object item : (List<?>) attr.getValue().getValue()) {
                TypeMirror type = (TypeMirror) ((AnnotationValue) item).getValue();
                Types typeUtils = processingEnv.getTypeUtils();
                for (TypeMirror otherType : r) {
                    for (boolean swap : new boolean[] {false, true}) {
                        TypeMirror t1 = swap ? type : otherType;
                        TypeMirror t2 = swap ? otherType : type;
                        if (typeUtils.isSubtype(t1, t2)) {
                            processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "registering under both " + typeUtils.asElement(t2).getSimpleName() + " and its subtype " + typeUtils.asElement(t1).getSimpleName() + " will not work if LookupMerger<" + typeUtils.asElement(t2).getSimpleName() + "> is used (#205151)", e, ann, attr.getValue());
                        }
                    }
                }
                r.add(type);
            }
            return r;
        }
        throw new LayerGenerationException("No service attr found", e);
    }
    throw new LayerGenerationException("No @ProjectServiceProvider found", e);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:LookupProviderAnnotationProcessor.java

示例10: isParcelableArrayList

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public static boolean isParcelableArrayList(Types typeUtils, Elements elementUtils, Element element) {
    TypeElement typeArrayList = elementUtils.getTypeElement(ArrayList.class.getName());
    TypeElement typeParcelable = elementUtils.getTypeElement(Parcelable.class.getName());
    WildcardType wildcardType = typeUtils.getWildcardType(typeParcelable.asType(), null);
    DeclaredType declaredType = typeUtils.getDeclaredType(typeArrayList, wildcardType);

    return typeUtils.isSubtype(element.asType(), declaredType);
}
 
開發者ID:srym,項目名稱:vulture,代碼行數:9,代碼來源:TypeUtils.java

示例11: addEffectivelyFinalAutoCloseables

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private void addEffectivelyFinalAutoCloseables(final Env env) throws IOException {
    final CompilationController controller = env.getController();
    final Elements elements = controller.getElements();
    final TypeElement te = elements.getTypeElement("java.lang.AutoCloseable"); //NOI18N
    if (te != null) {
        final Types types = controller.getTypes();
        final ElementUtilities eu = controller.getElementUtilities();
        final Scope scope = env.getScope();
        final Set<? extends TypeMirror> smartTypes = options.contains(Options.ALL_COMPLETION) ? null : getSmartTypes(env);
        final TypeElement enclClass = scope.getEnclosingClass();
        for (Element e : getLocalMembersAndVars(env)) {
            switch (e.getKind()) {
                case EXCEPTION_PARAMETER:
                case LOCAL_VARIABLE:
                case RESOURCE_VARIABLE:
                case PARAMETER:
                    if (types.isSubtype(e.asType(), te.asType()) && eu.isEffectivelyFinal((VariableElement) e)) {
                        results.add(itemFactory.createVariableItem(env.getController(), (VariableElement) e, e.asType(), anchorOffset, null, env.getScope().getEnclosingClass() != e.getEnclosingElement(), elements.isDeprecated(e), isOfSmartType(env, e.asType(), smartTypes), env.assignToVarPos()));
                    }
                    break;
                case FIELD:
                    if (types.isSubtype(e.asType(), te.asType())) {
                        String name = e.getSimpleName().toString();
                        if (THIS_KEYWORD.equals(name) || SUPER_KEYWORD.equals(name)) {
                            results.add(itemFactory.createKeywordItem(name, null, anchorOffset, isOfSmartType(env, e.asType(), smartTypes)));
                        } else {
                            TypeMirror tm = asMemberOf(e, enclClass != null ? enclClass.asType() : null, types);
                            results.add(itemFactory.createVariableItem(env.getController(), (VariableElement) e, tm, anchorOffset, null, env.getScope().getEnclosingClass() != e.getEnclosingElement(), elements.isDeprecated(e), isOfSmartType(env, tm, smartTypes), env.assignToVarPos()));
                        }
                    }
                    break;
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:JavaCompletionTask.java

示例12: asMemberOf

import javax.lang.model.util.Types; //導入方法依賴的package包/類
TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
    TypeMirror ret = element.asType();
    TypeMirror enclType = element.getEnclosingElement().asType();
    if (enclType.getKind() == TypeKind.DECLARED) {
        enclType = types.erasure(enclType);
    }
    while (type != null && type.getKind() == TypeKind.DECLARED) {
        if ((enclType.getKind() != TypeKind.DECLARED || ((DeclaredType) enclType).asElement().getSimpleName().length() > 0) && types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType) type, element);
            break;
        }
        type = ((DeclaredType) type).getEnclosingType();
    }
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:BaseTask.java

示例13: enumHint

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static ErrorDescription enumHint(HintContext ctx, String baseName, String targetTypeName, String key, Fix... fixes) {
    Element type = ctx.getInfo().getTrees().getElement(ctx.getVariables().get("$param"));

    if (type == null || type.getKind() != ElementKind.ENUM) {
        return null;
    }

    Element coll = ctx.getInfo().getTrees().getElement(ctx.getVariables().get("$coll"));

    if (coll == null || coll.getKind() != ElementKind.CLASS) {
        return null;
    }
    
    TypeElement base = ctx.getInfo().getElements().getTypeElement(baseName);
    
    if (base == null) {
        return null;
    }

    Types t = ctx.getInfo().getTypes();

    if (!t.isSubtype(t.erasure(coll.asType()), t.erasure(base.asType()))) {
        return null;
    }

    if (targetTypeName != null) {
        TypeElement target = ctx.getInfo().getElements().getTypeElement(targetTypeName);

        if (target == null) {
            return null;
        }

        if (t.isSubtype(t.erasure(coll.asType()), t.erasure(target.asType()))) {
            return null;
        }
        
        List<? extends TypeMirror> assignedTo = CreateElementUtilities.resolveType(EnumSet.noneOf(ElementKind.class), ctx.getInfo(), ctx.getPath().getParentPath(), ctx.getPath().getLeaf(), (int) ctx.getInfo().getTrees().getSourcePositions().getEndPosition(ctx.getPath().getCompilationUnit(), ctx.getPath().getLeaf()), new TypeMirror[1], new int[1]);
        
        if (assignedTo != null && assignedTo.size() == 1) {
            if (t.isSubtype(t.erasure(assignedTo.get(0)), t.erasure(coll.asType())))
                return null;
        }
    }

    String displayName = NbBundle.getMessage(Tiny.class, key);

    return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName, fixes);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:49,代碼來源:Tiny.java

示例14: isInActivity

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public static boolean isInActivity(Elements elements, Types types, TypeElement enclosingElement) {
    TypeMirror typeActivity = elements.getTypeElement(Constant.ACTIVITY).asType();
    return types.isSubtype(enclosingElement.asType(), typeActivity);
}
 
開發者ID:chiclaim,項目名稱:MRouter,代碼行數:5,代碼來源:ProcessorUtils.java

示例15: createBindings

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private Map<String, Object> createBindings(TypeElement clazz, ExecutableElement element) {
    CodeStyle cs = DiffContext.getCodeStyle(copy);       
    Map<String, Object> bindings = new HashMap<>();
    if (clazz != null) {
        bindings.put(CLASS_NAME, clazz.getQualifiedName().toString());
        bindings.put(SIMPLE_CLASS_NAME, clazz.getSimpleName().toString());
    }
    if (element != null) {
        bindings.put(METHOD_NAME, element.getSimpleName().toString());
        bindings.put(METHOD_RETURN_TYPE, element.getReturnType().toString()); //NOI18N
        Object value;
        switch(element.getReturnType().getKind()) {
            case BOOLEAN:
                value = "false"; //NOI18N
                break;
            case BYTE:
            case CHAR:
            case DOUBLE:
            case FLOAT:
            case INT:
            case LONG:
            case SHORT:
                value = 0;
                break;
            default:
                value = "null"; //NOI18N
        }
        bindings.put(DEFAULT_RETURN_TYPE_VALUE, value);
    }
    if (clazz != null && element != null) {
        StringBuilder sb = new StringBuilder();
        if (element.isDefault() && element.getEnclosingElement().getKind().isInterface()) {
            Types types = copy.getTypes();
            Context ctx = ((JavacTaskImpl) copy.impl.getJavacTask()).getContext();
            com.sun.tools.javac.code.Types typesImpl = com.sun.tools.javac.code.Types.instance(ctx);
            TypeMirror enclType = typesImpl.asSuper((Type)clazz.asType(), ((Type)element.getEnclosingElement().asType()).tsym);
            if (!types.isSubtype(clazz.getSuperclass(), enclType)) {
                TypeMirror selected = enclType;
                for (TypeMirror iface : clazz.getInterfaces()) {
                    if (types.isSubtype(iface, selected) &&
                        !types.isSameType(iface, enclType)) {
                        selected = iface;
                        break;
                    }
                }
                sb.append(((DeclaredType)selected).asElement().getSimpleName()).append('.');
            }
        }
        sb.append("super.").append(element.getSimpleName()).append('('); //NOI18N
        for (Iterator<? extends VariableElement> it = element.getParameters().iterator(); it.hasNext();) {
            VariableElement ve = it.next();
            sb.append(addParamPrefixSuffix(removeParamPrefixSuffix(ve, cs), cs));
            if (it.hasNext())
                sb.append(","); //NOI18N
        }
        sb.append(')'); //NOI18N
        bindings.put(SUPER_METHOD_CALL, sb);
    }
    return bindings;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:61,代碼來源:GeneratorUtilities.java


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