use of javax.lang.model.type.WildcardType in project tiger by google.
the class Utils method isPublicRecurively.
/**
* Returns true is the type includes only public types.
*/
public boolean isPublicRecurively(TypeMirror type) {
switch(type.getKind()) {
case TYPEVAR:
throw new RuntimeException("non-specilized type found: " + type);
case DECLARED:
if (!isSelfAndEnclosingPublic((TypeElement) ((DeclaredType) type).asElement())) {
return false;
}
for (TypeMirror i : ((DeclaredType) type).getTypeArguments()) {
if (!isPublicRecurively(i)) {
return false;
}
}
break;
case WILDCARD:
WildcardType wildcardType = (WildcardType) type;
TypeMirror extendsBound = wildcardType.getExtendsBound();
if (extendsBound != null && !isPublicRecurively(extendsBound)) {
return false;
}
TypeMirror superBound = wildcardType.getSuperBound();
if (superBound != null && !isPublicRecurively(superBound)) {
return false;
}
break;
default:
break;
}
return true;
}
use of javax.lang.model.type.WildcardType in project checker-framework by typetools.
the class CFAbstractValue method getEffectTypeVar.
/**
* Returns the AnnotatedTypeVariable associated with the given TypeMirror or null.
*
* <p>If TypeMirror is a type variable, then the AnnotatedTypeVariable return is the declaration
* of that TypeMirror. If the TypeMirror is a wildcard that extends a type variable, the
* AnnotatedTypeVariable return is the declaration of that type variable. Otherwise, null is
* returned.
*/
private AnnotatedTypeVariable getEffectTypeVar(TypeMirror typeMirror) {
if (typeMirror == null) {
return null;
} else if (typeMirror.getKind() == TypeKind.WILDCARD) {
return getEffectTypeVar(((WildcardType) typeMirror).getExtendsBound());
} else if (typeMirror.getKind() == TypeKind.TYPEVAR) {
TypeVariable typevar = ((TypeVariable) typeMirror);
AnnotatedTypeMirror atm = analysis.getTypeFactory().getAnnotatedType(typevar.asElement());
return (AnnotatedTypeVariable) atm;
} else {
return null;
}
}
use of javax.lang.model.type.WildcardType in project checker-framework by typetools.
the class CFTreeBuilder method createAnnotatedType.
private Tree createAnnotatedType(AnnotatedTypeMirror annotatedType) {
// Implementation based on com.sun.tools.javac.tree.TreeMaker.Type
// Convert the annotations from a set of AnnotationMirrors
// to a list of AnnotationTrees.
Set<AnnotationMirror> annotations = annotatedType.getAnnotations();
List<JCTree.JCAnnotation> annotationTrees = List.nil();
for (AnnotationMirror am : annotations) {
// TODO: what TypeAnnotationPosition should be used?
Attribute.TypeCompound typeCompound = TypeAnnotationUtils.createTypeCompoundFromAnnotationMirror(am, TypeAnnotationUtils.unknownTAPosition(), env);
JCTree.JCAnnotation annotationTree = maker.Annotation(typeCompound);
JCTree.JCAnnotation typeAnnotationTree = maker.TypeAnnotation(annotationTree.getAnnotationType(), annotationTree.getArguments());
typeAnnotationTree.attribute = typeCompound;
annotationTrees = annotationTrees.append(typeAnnotationTree);
}
// Convert the underlying type from a TypeMirror to an
// ExpressionTree and combine with the AnnotationTrees
// to form a ClassTree of kind ANNOTATION_TYPE.
Tree underlyingTypeTree;
switch(annotatedType.getKind()) {
case BYTE:
underlyingTypeTree = maker.TypeIdent(TypeTag.BYTE);
break;
case CHAR:
underlyingTypeTree = maker.TypeIdent(TypeTag.BYTE);
break;
case SHORT:
underlyingTypeTree = maker.TypeIdent(TypeTag.SHORT);
break;
case INT:
underlyingTypeTree = maker.TypeIdent(TypeTag.INT);
break;
case LONG:
underlyingTypeTree = maker.TypeIdent(TypeTag.LONG);
break;
case FLOAT:
underlyingTypeTree = maker.TypeIdent(TypeTag.FLOAT);
break;
case DOUBLE:
underlyingTypeTree = maker.TypeIdent(TypeTag.DOUBLE);
break;
case BOOLEAN:
underlyingTypeTree = maker.TypeIdent(TypeTag.BOOLEAN);
break;
case VOID:
underlyingTypeTree = maker.TypeIdent(TypeTag.VOID);
break;
case TYPEVAR:
{
// No recursive annotations.
AnnotatedTypeMirror.AnnotatedTypeVariable variable = (AnnotatedTypeMirror.AnnotatedTypeVariable) annotatedType;
TypeVariable underlyingTypeVar = variable.getUnderlyingType();
underlyingTypeTree = maker.Ident((Symbol.TypeSymbol) (underlyingTypeVar).asElement());
break;
}
case WILDCARD:
{
AnnotatedTypeMirror.AnnotatedWildcardType wildcard = (AnnotatedTypeMirror.AnnotatedWildcardType) annotatedType;
WildcardType wildcardType = wildcard.getUnderlyingType();
if (wildcardType.getExtendsBound() != null) {
Tree annotatedExtendsBound = createAnnotatedType(wildcard.getExtendsBound());
underlyingTypeTree = maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), (JCTree) annotatedExtendsBound);
} else if (wildcardType.getSuperBound() != null) {
Tree annotatedSuperBound = createAnnotatedType(wildcard.getSuperBound());
underlyingTypeTree = maker.Wildcard(maker.TypeBoundKind(BoundKind.SUPER), (JCTree) annotatedSuperBound);
} else {
underlyingTypeTree = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null);
}
break;
}
case DECLARED:
{
underlyingTypeTree = maker.Type((Type) annotatedType.getUnderlyingType());
if (underlyingTypeTree instanceof JCTree.JCTypeApply) {
// Replace the type parameters with annotated versions.
AnnotatedTypeMirror.AnnotatedDeclaredType annotatedDeclaredType = (AnnotatedTypeMirror.AnnotatedDeclaredType) annotatedType;
List<JCTree.JCExpression> typeArgTrees = List.nil();
for (AnnotatedTypeMirror arg : annotatedDeclaredType.getTypeArguments()) {
typeArgTrees = typeArgTrees.append((JCTree.JCExpression) createAnnotatedType(arg));
}
JCTree.JCExpression clazz = (JCTree.JCExpression) ((JCTree.JCTypeApply) underlyingTypeTree).getType();
underlyingTypeTree = maker.TypeApply(clazz, typeArgTrees);
}
break;
}
case ARRAY:
{
AnnotatedTypeMirror.AnnotatedArrayType annotatedArrayType = (AnnotatedTypeMirror.AnnotatedArrayType) annotatedType;
Tree annotatedComponentTree = createAnnotatedType(annotatedArrayType.getComponentType());
underlyingTypeTree = maker.TypeArray((JCTree.JCExpression) annotatedComponentTree);
break;
}
case ERROR:
underlyingTypeTree = maker.TypeIdent(TypeTag.ERROR);
break;
default:
assert false : "unexpected type: " + annotatedType;
underlyingTypeTree = null;
break;
}
((JCTree) underlyingTypeTree).setType((Type) annotatedType.getUnderlyingType());
if (annotationTrees.isEmpty()) {
return underlyingTypeTree;
}
JCTree.JCAnnotatedType annotatedTypeTree = maker.AnnotatedType(annotationTrees, (JCTree.JCExpression) underlyingTypeTree);
annotatedTypeTree.setType((Type) annotatedType.getUnderlyingType());
return annotatedTypeTree;
}
use of javax.lang.model.type.WildcardType in project checker-framework by typetools.
the class AnnotatedTypeFactory method getUninferredWildcardType.
/**
* Returns a wildcard type to be used as a type argument when the correct type could not be
* inferred. The wildcard will be marked as an uninferred wildcard so that {@link
* AnnotatedWildcardType#isUninferredTypeArgument()} returns true.
*
* <p>This method should only be used by type argument inference.
* org.checkerframework.framework.util.AnnotatedTypes.inferTypeArguments(ProcessingEnvironment,
* AnnotatedTypeFactory, ExpressionTree, ExecutableElement)
*
* @param typeVar TypeVariable which could not be inferred
* @return a wildcard that is marked as an uninferred type argument
*/
public AnnotatedWildcardType getUninferredWildcardType(AnnotatedTypeVariable typeVar) {
final boolean intersectionType;
final TypeMirror boundType;
if (typeVar.getUpperBound().getKind() == TypeKind.INTERSECTION) {
boundType = typeVar.getUpperBound().directSuperTypes().get(0).getUnderlyingType();
intersectionType = true;
} else {
boundType = typeVar.getUnderlyingType().getUpperBound();
intersectionType = false;
}
WildcardType wc = types.getWildcardType(boundType, null);
AnnotatedWildcardType wctype = (AnnotatedWildcardType) AnnotatedTypeMirror.createType(wc, this, false);
wctype.setTypeVariable(typeVar.getUnderlyingType());
if (!intersectionType) {
wctype.setExtendsBound(typeVar.getUpperBound().deepCopy());
} else {
wctype.getExtendsBound().addAnnotations(typeVar.getUpperBound().getAnnotations());
}
wctype.setSuperBound(typeVar.getLowerBound().deepCopy());
wctype.addAnnotations(typeVar.getAnnotations());
addDefaultAnnotations(wctype);
wctype.setUninferredTypeArgument();
return wctype;
}
use of javax.lang.model.type.WildcardType in project mapstruct by mapstruct.
the class Type method isWildCardSuperBound.
public boolean isWildCardSuperBound() {
boolean result = false;
if (typeMirror.getKind() == TypeKind.WILDCARD) {
WildcardType wildcardType = (WildcardType) typeMirror;
result = wildcardType.getSuperBound() != null;
}
return result;
}
Aggregations