use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromExpressionVisitor method visitIdentifier.
@Override
public AnnotatedTypeMirror visitIdentifier(IdentifierTree node, AnnotatedTypeFactory f) {
if (node.getName().contentEquals("this") || node.getName().contentEquals("super")) {
AnnotatedDeclaredType res = f.getSelfType(node);
return res;
}
Element elt = TreeUtils.elementFromUse(node);
AnnotatedTypeMirror selfType = f.getImplicitReceiverType(node);
if (selfType != null) {
return AnnotatedTypes.asMemberOf(f.types, f, selfType, elt).asUse();
}
return f.getAnnotatedType(elt);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromMemberVisitor method inferLambdaParamAnnotations.
/**
* @return the type of the lambda parameter or null if paramElement is not a lambda parameter
*/
private static AnnotatedTypeMirror inferLambdaParamAnnotations(AnnotatedTypeFactory f, AnnotatedTypeMirror lambdaParam, Element paramElement) {
if (paramElement.getKind() != ElementKind.PARAMETER || f.declarationFromElement(paramElement) == null || f.getPath(f.declarationFromElement(paramElement)) == null || f.getPath(f.declarationFromElement(paramElement)).getParentPath() == null) {
return null;
}
Tree declaredInTree = f.getPath(f.declarationFromElement(paramElement)).getParentPath().getLeaf();
if (declaredInTree.getKind() == Kind.LAMBDA_EXPRESSION) {
LambdaExpressionTree lambdaDecl = (LambdaExpressionTree) declaredInTree;
int index = lambdaDecl.getParameters().indexOf(f.declarationFromElement(paramElement));
Pair<AnnotatedDeclaredType, AnnotatedExecutableType> res = f.getFnInterfaceFromTree(lambdaDecl);
AnnotatedExecutableType functionType = res.second;
AnnotatedTypeMirror funcTypeParam = functionType.getParameterTypes().get(index);
if (TreeUtils.isImplicitlyTypedLambda(declaredInTree)) {
if (f.types.isSubtype(funcTypeParam.actualType, lambdaParam.actualType)) {
// (#979) isn't implement, check first.
return AnnotatedTypes.asSuper(f, funcTypeParam, lambdaParam);
}
lambdaParam.addMissingAnnotations(funcTypeParam.getAnnotations());
return lambdaParam;
} else {
// The lambda expression is explicitly typed, so the parameters have declared types:
// (String s) -> ...
// The declared type may or may not have explicit annotations.
// If it does not have an annotation for a hierarchy, then copy the annotation from
// the function type rather than use usual defaulting rules.
// Note lambdaParam is a super type of funcTypeParam, so only primary annotations
// can be copied.
lambdaParam.addMissingAnnotations(funcTypeParam.getAnnotations());
return lambdaParam;
}
}
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromTree method fromClassTree.
/**
* @return an AnnotatedDeclaredType representing the input ClassTree
*/
public static AnnotatedDeclaredType fromClassTree(final AnnotatedTypeFactory typeFactory, final ClassTree tree) {
abortIfTreeIsNull(typeFactory, tree);
final AnnotatedDeclaredType type = (AnnotatedDeclaredType) classVisitor.visit(tree, typeFactory);
abortIfTypeIsExecutable(typeFactory, tree, type);
return type;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromTypeTreeVisitor method visitTypeParameter.
@Override
public AnnotatedTypeMirror visitTypeParameter(TypeParameterTree node, AnnotatedTypeFactory f) {
List<AnnotatedTypeMirror> bounds = new ArrayList<>(node.getBounds().size());
for (Tree t : node.getBounds()) {
AnnotatedTypeMirror bound;
if (visitedBounds.containsKey(t) && f == visitedBounds.get(t).atypeFactory) {
bound = visitedBounds.get(t);
} else {
visitedBounds.put(t, f.type(t));
bound = visit(t, f);
visitedBounds.remove(t);
}
bounds.add(bound);
}
AnnotatedTypeVariable result = (AnnotatedTypeVariable) f.type(node);
List<? extends AnnotationMirror> annotations = TreeUtils.annotationsFromTree(node);
result.getLowerBound().addAnnotations(annotations);
switch(bounds.size()) {
case 0:
break;
case 1:
result.setUpperBound(bounds.get(0));
break;
default:
AnnotatedIntersectionType upperBound = (AnnotatedIntersectionType) result.getUpperBound();
List<AnnotatedDeclaredType> superBounds = new ArrayList<>(bounds.size());
for (AnnotatedTypeMirror b : bounds) {
superBounds.add((AnnotatedDeclaredType) b);
}
upperBound.setDirectSuperTypes(superBounds);
}
return result;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromTypeTreeVisitor method visitParameterizedType.
@Override
public AnnotatedTypeMirror visitParameterizedType(ParameterizedTypeTree node, AnnotatedTypeFactory f) {
List<AnnotatedTypeMirror> args = new ArrayList<>(node.getTypeArguments().size());
for (Tree t : node.getTypeArguments()) {
args.add(visit(t, f));
}
// use creator?
AnnotatedTypeMirror result = f.type(node);
AnnotatedTypeMirror atype = visit(node.getType(), f);
result.addAnnotations(atype.getAnnotations());
if (result instanceof AnnotatedDeclaredType) {
assert result instanceof AnnotatedDeclaredType : node + " --> " + result;
((AnnotatedDeclaredType) result).setTypeArguments(args);
}
return result;
}
Aggregations