use of com.github.javaparser.ast.type.WildcardType in project checker-framework by typetools.
the class StubParser method annotate.
/**
* Add to {@code atype}:
*
* <ol>
* <li>the annotations from {@code typeDef}, and
* <li>any type annotations that parsed as declaration annotations (ie those in {@code
* declAnnos}).
* </ol>
*
* @param atype annotated type to which to add annotations
* @param typeDef parsed type
* @param declAnnos annotations stored on the declaration of the variable with this type, or
* null
*/
private void annotate(AnnotatedTypeMirror atype, Type typeDef, NodeList<AnnotationExpr> declAnnos) {
if (atype.getKind() == TypeKind.ARRAY) {
annotateAsArray((AnnotatedArrayType) atype, (ReferenceType) typeDef, declAnnos);
return;
}
clearAnnotations(atype, typeDef);
// Primary annotations for the type of a variable declaration are not stored in typeDef, but
// rather as declaration annotations (passed as declAnnos to this method). But, if typeDef
// is not the type of a variable, then the primary annotations are stored in typeDef.
NodeList<AnnotationExpr> primaryAnnotations;
if (typeDef.getAnnotations().isEmpty() && declAnnos != null) {
primaryAnnotations = declAnnos;
} else {
primaryAnnotations = typeDef.getAnnotations();
}
if (atype.getKind() != TypeKind.WILDCARD) {
// The primary annotation on a wildcard applies to the super or extends bound and
// are added below.
annotate(atype, primaryAnnotations);
}
switch(atype.getKind()) {
case DECLARED:
ClassOrInterfaceType declType = unwrapDeclaredType(typeDef);
if (declType == null) {
break;
}
AnnotatedDeclaredType adeclType = (AnnotatedDeclaredType) atype;
if (declType.getTypeArguments().isPresent() && !declType.getTypeArguments().get().isEmpty() && !adeclType.getTypeArguments().isEmpty()) {
assert declType.getTypeArguments().get().size() == adeclType.getTypeArguments().size() : String.format("Mismatch in type argument size between %s (%d) and %s (%d)", declType, declType.getTypeArguments().get().size(), adeclType, adeclType.getTypeArguments().size());
for (int i = 0; i < declType.getTypeArguments().get().size(); ++i) {
annotate(adeclType.getTypeArguments().get(i), declType.getTypeArguments().get().get(i), null);
}
}
break;
case WILDCARD:
AnnotatedWildcardType wildcardType = (AnnotatedWildcardType) atype;
WildcardType wildcardDef = (WildcardType) typeDef;
if (wildcardDef.getExtendedType().isPresent()) {
annotate(wildcardType.getExtendsBound(), wildcardDef.getExtendedType().get(), null);
annotate(wildcardType.getSuperBound(), primaryAnnotations);
} else if (wildcardDef.getSuperType().isPresent()) {
annotate(wildcardType.getSuperBound(), wildcardDef.getSuperType().get(), null);
annotate(wildcardType.getExtendsBound(), primaryAnnotations);
} else {
annotate(atype, primaryAnnotations);
}
break;
case TYPEVAR:
// Add annotations from the declaration of the TypeVariable
AnnotatedTypeVariable typeVarUse = (AnnotatedTypeVariable) atype;
for (AnnotatedTypeVariable typePar : typeParameters) {
if (typePar.getUnderlyingType() == atype.getUnderlyingType()) {
AnnotatedTypeMerger.merge(typePar.getUpperBound(), typeVarUse.getUpperBound());
AnnotatedTypeMerger.merge(typePar.getLowerBound(), typeVarUse.getLowerBound());
}
}
break;
default:
}
}
Aggregations