List of usage examples for javax.lang.model.type TypeKind TYPEVAR
TypeKind TYPEVAR
To view the source code for javax.lang.model.type TypeKind TYPEVAR.
Click Source Link
From source file:com.vimeo.stag.processor.utils.TypeUtils.java
/** * Determines whether or not the TypeMirror is a concrete type. * If the type is a generic type or contains generic type * arguments (i.e. a parameterized type), this method will * return false.//from w w w. j ava 2 s . co m * * @param typeMirror the element to check. * @return true if the type is not generic and * contains no generic type arguments, false otherwise. */ public static boolean isConcreteType(@NotNull TypeMirror typeMirror) { if (typeMirror.getKind() == TypeKind.TYPEVAR) { return false; } if (isPrimitive(typeMirror, getUtils())) { return true; } if (typeMirror instanceof DeclaredType) { List<? extends TypeMirror> typeMirrors = ((DeclaredType) typeMirror).getTypeArguments(); for (TypeMirror type : typeMirrors) { if (!isConcreteType(type)) { return false; } } } return true; }
From source file:android.databinding.tool.store.SetterStore.java
private static boolean hasTypeVar(TypeMirror typeMirror) { TypeKind kind = typeMirror.getKind(); if (kind == TypeKind.TYPEVAR) { return true; } else if (kind == TypeKind.ARRAY) { return hasTypeVar(((ArrayType) typeMirror).getComponentType()); } else if (kind == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments == null || typeArguments.isEmpty()) { return false; }// ww w . j a v a2 s. co m for (TypeMirror arg : typeArguments) { if (hasTypeVar(arg)) { return true; } } return false; } else { return false; } }
From source file:org.leandreck.endpoints.processor.model.TypeNodeFactory.java
private TypeNode initType(final String fieldName, final String parameterName, final boolean optional, final TypeNodeKind typeNodeKind, final TypeMirror typeMirror, final DeclaredType containingType) { final String key = typeMirror.toString(); if (nodes.containsKey(key) && !TypeKind.TYPEVAR.equals(typeMirror.getKind())) { final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional); proxyNode.setNode(nodes.get(key)); return proxyNode; }/*from w w w . j a va2 s. co m*/ try { final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional); nodes.put(key, proxyNode); final ConcreteTypeNodeFactory nodeFactory = factories.get(typeNodeKind); final TypeNode newTypeNode = nodeFactory.createTypeNode(fieldName, parameterName, optional, typeMirror, containingType); proxyNode.setNode(newTypeNode); nodes.put(key, newTypeNode); return newTypeNode; } catch (Exception e) { throw new UnkownTypeProcessingException(e); } }
From source file:com.vimeo.stag.processor.utils.TypeUtils.java
/** * Determines where the the type mirrors contains type var params or not * * @param typeMirror the element to check. * @return true if it contains type variables *//*ww w . j a v a 2 s. co m*/ public static boolean containsTypeVarParams(@NotNull TypeMirror typeMirror) { if (typeMirror.getKind() == TypeKind.TYPEVAR) { return true; } if (typeMirror instanceof DeclaredType) { List<? extends TypeMirror> typeMirrors = ((DeclaredType) typeMirror).getTypeArguments(); for (TypeMirror type : typeMirrors) { if (containsTypeVarParams(type)) { return true; } } } return false; }
From source file:com.vimeo.stag.processor.utils.TypeUtils.java
@NotNull private static TypeMirror resolveTypeVars(@NotNull TypeMirror element, @NotNull final List<? extends TypeMirror> inheritedTypes, @NotNull final List<? extends TypeMirror> concreteTypes) { if (isConcreteType(element)) { return element; }// w w w. j av a2s .c o m if (element.getKind() == TypeKind.TYPEVAR) { int index = inheritedTypes.indexOf(element); return concreteTypes.get(index); } Types types = getUtils(); List<? extends TypeMirror> typeMirrors = ((DeclaredType) element).getTypeArguments(); TypeElement typeElement = (TypeElement) types.asElement(element); List<TypeMirror> concreteGenericTypes = new ArrayList<>(typeMirrors.size()); for (TypeMirror type : typeMirrors) { concreteGenericTypes.add(resolveTypeVars(type, inheritedTypes, concreteTypes)); } TypeMirror[] concreteTypeArray = concreteGenericTypes.toArray(new TypeMirror[concreteGenericTypes.size()]); return types.getDeclaredType(typeElement, concreteTypeArray); }
From source file:org.jsweet.transpiler.Java2TypeScriptTranslator.java
@Override public void visitTypeCast(JCTypeCast cast) { if (substituteAssignedExpression(cast.type, cast.expr)) { return;//from ww w.j a v a2 s . c o m } if (Util.isIntegral(cast.type)) { if (cast.type.getKind() == TypeKind.LONG) { print("Math.floor("); } else { print("("); } } if (!context.hasAnnotationType(cast.clazz.type.tsym, ANNOTATION_ERASED, ANNOTATION_OBJECT_TYPE, ANNOTATION_FUNCTIONAL_INTERFACE)) { // Java is more permissive than TypeScript when casting type // variables if (cast.expr.type.getKind() == TypeKind.TYPEVAR) { print("<any>"); } else { print("<"); substituteAndPrintType(cast.clazz).print(">"); } } print(cast.expr); if (Util.isIntegral(cast.type)) { if (cast.type.getKind() == TypeKind.LONG) { print(")"); } else { print("|0)"); } } }