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


Java TypeMirror.getKind方法代码示例

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


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

示例1: createCompleter

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
@Override
public Completer createCompleter(CompletionContext ctx) {
    FxProperty p = ctx.getEnclosingProperty();
    if (p == null || p.getType() == null) {
        return null;
    }
    TypeMirror m = p.getType().resolve(ctx.getCompilationInfo());
    if (m.getKind() == TypeKind.BOOLEAN) {
        return new EnumValueCompleter(ctx);
    }
    if (m.getKind() != TypeKind.DECLARED) {
        return null;
    }
    DeclaredType t = (DeclaredType)m;
    TypeElement tel = (TypeElement)t.asElement();
    if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) {
        return new EnumValueCompleter(ctx);
    }
    if (tel.getKind() == ElementKind.ENUM) {
        return new EnumValueCompleter(ctx, tel);
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:EnumValueCompleter.java

示例2: MethodItem

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
public MethodItem(int substitutionOffset, ExecutableElement element, boolean isInherited, boolean isDeprecated) {
    super(substitutionOffset);
    this.elementHandle = ElementHandle.create(element);
    this.isDeprecated = isDeprecated;
    this.isInherited = isInherited;
    this.simpleName = element.getSimpleName().toString();
    this.modifiers = element.getModifiers();
    this.params = new ArrayList<ParamDesc>();
    Iterator<? extends VariableElement> it = element.getParameters().iterator();
    Iterator<? extends TypeMirror> tIt = ((ExecutableType) element.asType()).getParameterTypes().iterator();
    while(it.hasNext() && tIt.hasNext()) {
        TypeMirror tm = tIt.next();
        this.params.add(new ParamDesc(tm.toString(), getTypeName(tm, false, element.isVarArgs() && !tIt.hasNext()).toString(), it.next().getSimpleName().toString()));
    }
    TypeMirror retType = element.getReturnType();

    this.typeName = getTypeName(retType, false).toString();
    this.isPrimitive = retType.getKind().isPrimitive() || retType.getKind() == TypeKind.VOID;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SpringXMLConfigCompletionItem.java

示例3: isIterbale

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private boolean isIterbale(ExpressionTree expression) {
    TypeMirror tm = workingCopy.getTrees().getTypeMirror(TreePath.getPath(workingCopy.getCompilationUnit(), expression));
    if (!Utilities.isValidType(tm)) {
        return false;
    }
    if (tm.getKind() == TypeKind.ARRAY) {
        return false;
    } else {
        tm = workingCopy.getTypes().erasure(tm);
        TypeElement typeEl = workingCopy.getElements().getTypeElement("java.util.Collection");
        if (typeEl != null) {
            TypeMirror collection = typeEl.asType();
            collection = workingCopy.getTypes().erasure(collection);
            if (this.workingCopy.getTypes().isSubtype(tm, collection)) {
                return true;
            }
        }
    }

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

示例4: isOfKindAndType

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private boolean isOfKindAndType(TypeMirror type, Element e, EnumSet<ElementKind> kinds, TypeMirror base, Scope scope, Trees trees, Types types) {
    if (type.getKind() != TypeKind.ERROR && kinds.contains(e.getKind())) {
        if (base == null)
            return true;
        if (types.isSubtype(type, base))
            return true;
    }
    if ((e.getKind().isClass() || e.getKind().isInterface()) && 
        (kinds.contains(ANNOTATION_TYPE) || kinds.contains(CLASS) || kinds.contains(ENUM) || kinds.contains(INTERFACE))) {
        DeclaredType dt = (DeclaredType)e.asType();
        for (Element ee : e.getEnclosedElements())
            if (trees.isAccessible(scope, ee, dt) && isOfKindAndType(ee.asType(), ee, kinds, base, scope, trees, types))
                return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavadocCompletionQuery.java

示例5: CreateEnumConstant

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
    this.name = name;
    this.inFQN = target.getQualifiedName().toString();
    this.cpInfo = info.getClasspathInfo();
    this.targetFile = targetFile;
    this.target = ElementHandle.create(target);
    if (proposedType.getKind() == TypeKind.NULL) {
        TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
        if (tel != null) {
            proposedType = tel.asType();
            this.proposedType = TypeMirrorHandle.create(proposedType);
        } else {
            this.proposedType = null;
        }
    } else {
        this.proposedType = TypeMirrorHandle.create(proposedType);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CreateEnumConstant.java

示例6: resolveTypeName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
/**
 * uses FQNs where possible since javadoc does not match imports for
 * parameter types
 */
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
    CharSequence ptype;
    if (asType.getKind() == TypeKind.DECLARED) {
        // snip generics
        Element e = ((DeclaredType) asType).asElement();
        ptype = e.getKind().isClass() || e.getKind().isInterface()
                ? ((TypeElement) e).getQualifiedName()
                : e.getSimpleName();
    } else if (asType.getKind() == TypeKind.TYPEVAR) {
        do {
            // Type Erasure JLS 4.6
            asType = ((TypeVariable) asType).getUpperBound();
        } while (asType.getKind() == TypeKind.TYPEVAR);
        ptype = resolveTypeName(asType, isVarArgs);
    } else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
        ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
    } else {
        ptype = asType.toString();
    }
    
    return ptype;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:JavadocCompletionItem.java

示例7: checkBinaryOp

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static boolean checkBinaryOp(CompilationInfo ci, TreePath expr, Tree prev) {
    BinaryTree bt = (BinaryTree)expr.getLeaf();
    Tree other = prev == bt.getLeftOperand() ? bt.getRightOperand() : bt.getLeftOperand();
    Boolean b = checkTwoArguments(ci, expr, other, prev);
    if (Boolean.TRUE == b) {
        return true;
    }
    if (b == null) {
        return false;
    }
    TypeMirror tm  = ci.getTrees().getTypeMirror(new TreePath(expr, other));
    if (tm != null && tm.getKind() == TypeKind.DECLARED) {
        Element el = ((DeclaredType)tm).asElement();
        if (el != null && el.getKind() == ElementKind.CLASS) {
            return ((TypeElement)el).getQualifiedName().contentEquals("java.lang.String"); // NOI18N
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:UnnecessaryBoxing.java

示例8: lambda2Class

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
@Hint(displayName="#DN_lambda2Class", description="#DESC_lambda2Class", category="suggestions", hintKind=Hint.Kind.ACTION,
        minSourceVersion = "8")
@Messages({
    "DN_lambda2Class=Convert Lambda Expression to Anonymous Innerclass",
    "DESC_lambda2Class=Converts lambda expressions to anonymous inner classes",
    "ERR_lambda2Class=Anonymous class can be used"
})
@TriggerTreeKind(Kind.LAMBDA_EXPRESSION)
public static ErrorDescription lambda2Class(HintContext ctx) {
    TypeMirror samType = ctx.getInfo().getTrees().getTypeMirror(ctx.getPath());
    
    if (samType == null || samType.getKind() != TypeKind.DECLARED) {
        return null;
    }
    
    return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), Bundle.ERR_lambda2Class(), new Lambda2Anonymous(ctx.getInfo(), ctx.getPath()).toEditorFix());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Lambda.java

示例9: toString

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
String toString(TypeMirror bound) {
    if (bound.getKind() == TypeKind.TYPEVAR) {
        TypeVariable var = (TypeVariable) bound;
        return toString(var.asElement());
    }
    return bound.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:NestedTypeVars.java

示例10: getCodeToPopulatePkField

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
public String getCodeToPopulatePkField(TypeElement type, ExecutableElement pkAccessorMethod) {
    EmbeddedPkSupportInfo info = getInfo(type);
    String code = info.getCodeToPopulatePkField(pkAccessorMethod);
    if (code != null) {
        return code;
    }
    
    code = "";
    ExecutableElement relationshipMethod = info.getRelationshipMethod(pkAccessorMethod);
    String referencedColumnName = info.getReferencedColumnName(pkAccessorMethod);
    if (relationshipMethod == null || referencedColumnName == null) {
        info.putCodeToPopulatePkField(pkAccessorMethod, code);
        return code;
    }
    
    TypeMirror relationshipTypeMirror = relationshipMethod.getReturnType();
    if (TypeKind.DECLARED != relationshipTypeMirror.getKind()) {
        info.putCodeToPopulatePkField(pkAccessorMethod, code);
        return code;
    }
    DeclaredType declaredType = (DeclaredType) relationshipTypeMirror;
    TypeElement relationshipType = (TypeElement) declaredType.asElement();
    
    EmbeddedPkSupportInfo relatedInfo = getInfo(relationshipType);
    String accessorString = relatedInfo.getAccessorString(referencedColumnName);
    if (accessorString == null) {
        info.putCodeToPopulatePkField(pkAccessorMethod, code);
        return code;
    }
    
    code = relationshipMethod.getSimpleName().toString() + "()." + accessorString;
    info.putCodeToPopulatePkField(pkAccessorMethod, code);
    return code;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:JpaControllerUtil.java

示例11: conditions2Constraints

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static Map<String, TypeMirror> conditions2Constraints(CompilationInfo info, List<Condition> conditions) {
    Map<String, TypeMirror> constraints = new HashMap<String, TypeMirror>();

    for (Entry<String, String> e : org.netbeans.modules.java.hints.declarative.Utilities.conditions2Constraints(conditions).entrySet()) {
        TypeMirror designedType = Hacks.parseFQNType(info, e.getValue());

        if (designedType == null || designedType.getKind() == TypeKind.ERROR) {
            continue ;
        }

        constraints.put(e.getKey(), designedType);
    }
    
    return constraints;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:HintsTask.java

示例12: asMemberOf

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static 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 (types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType)type, element);
            break;
        }
        type = ((DeclaredType)type).getEnclosingType();
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:JavadocCompletionQuery.java

示例13: canContainArrays

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
/**
 * Determines whether the array can contain other arrays. Checks if the component type is an array type.
 * Otherwise, checks whether the component type is a declared one, and that it is an Object. Other declared
 * types cannot hold array references.
 * 
 * @param ci context
 * @param tp path to the array expression
 * @return true, if the expression (assuming array type) can hold other arrays as members
 */
static boolean canContainArrays(CompilationInfo ci, TreePath tp) {
    TypeMirror tm = ci.getTrees().getTypeMirror(tp);
    if (!Utilities.isValidType(tm)) {
        return false;
    }
    tm = ci.getTypes().erasure(tm);
    if (tm == null || tm.getKind() != TypeKind.ARRAY) {
        return false;
    }
    ArrayType arrayType = (ArrayType)tm;
    TypeMirror ct = arrayType.getComponentType();
    boolean enableDeep = false;
    
    if (ct.getKind() == TypeKind.ARRAY) {
        // if the component kind is known to be an array, enable deepHash
        enableDeep = true;
    } else if (ct.getKind() == TypeKind.DECLARED) {
        Element obj = ci.getElements().getTypeElement("java.lang.Object"); // NOI18N
        if (obj == null) {
            return false;
        }
        // other ref types than Object cannot hold array instances, deepHash is a nonsense
        enableDeep = ci.getTypes().isSameType(obj.asType(), ct);
    }
    return enableDeep;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:ArrayStringConversions.java

示例14: readResultsFromStub

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
@Override
public void readResultsFromStub(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
    if (resultType.getKind() == TypeKind.ARRAY) {
        methodBuilder.addStatement("reply.writeDoubleArray(result)");
    } else {
        methodBuilder.addStatement("reply.writeDouble(result)");
    }
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:9,代码来源:DoubleParamBuilder.java

示例15: assignableToSomeType

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static boolean assignableToSomeType(CompilationInfo info, TypeMirror theValue, Collection<? extends TypeMirror> alternatives) {
    for (TypeMirror target : alternatives) {
        if (target.getKind() == TypeKind.VOID) {
            return true;
        }
        if (info.getTypes().isAssignable(theValue, target)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ExpectedTypeResolver.java


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