use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.
the class GenericAnnotatedTypeFactory method constructorFromUse.
@Override
public Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> constructorFromUse(NewClassTree tree) {
Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> mfuPair = super.constructorFromUse(tree);
AnnotatedExecutableType method = mfuPair.first;
if (dependentTypesHelper != null) {
dependentTypesHelper.viewpointAdaptConstructor(tree, method);
}
poly.annotate(tree, method);
return mfuPair;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType 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.AnnotatedExecutableType in project checker-framework by typetools.
the class TypeFromMemberVisitor method visitMethod.
@Override
public AnnotatedTypeMirror visitMethod(MethodTree node, AnnotatedTypeFactory f) {
ExecutableElement elt = TreeUtils.elementFromDeclaration(node);
AnnotatedExecutableType result = (AnnotatedExecutableType) f.toAnnotatedType(elt.asType(), false);
result.setElement(elt);
ElementAnnotationApplier.apply(result, elt, f);
return result;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.
the class TypesIntoElements method storeMethod.
private static void storeMethod(ProcessingEnvironment processingEnv, Types types, AnnotatedTypeFactory atypeFactory, MethodTree meth) {
AnnotatedExecutableType mtype = atypeFactory.getAnnotatedType(meth);
MethodSymbol sym = (MethodSymbol) TreeUtils.elementFromDeclaration(meth);
TypeAnnotationPosition tapos;
List<Attribute.TypeCompound> tcs = List.nil();
storeTypeParameters(processingEnv, types, atypeFactory, meth.getTypeParameters(), sym);
{
// return type
JCTree ret = ((JCTree.JCMethodDecl) meth).getReturnType();
if (ret != null) {
tapos = TypeAnnotationUtils.methodReturnTAPosition(ret.pos);
tcs = tcs.appendList(generateTypeCompounds(processingEnv, mtype.getReturnType(), tapos));
}
}
{
// receiver
JCTree recv = ((JCTree.JCMethodDecl) meth).getReceiverParameter();
if (recv != null) {
tapos = TypeAnnotationUtils.methodReceiverTAPosition(recv.pos);
tcs = tcs.appendList(generateTypeCompounds(processingEnv, mtype.getReceiverType(), tapos));
}
}
{
// parameters
int pidx = 0;
java.util.List<AnnotatedTypeMirror> ptypes = mtype.getParameterTypes();
for (JCTree param : ((JCTree.JCMethodDecl) meth).getParameters()) {
tapos = TypeAnnotationUtils.methodParameterTAPosition(pidx, param.pos);
tcs = tcs.appendList(generateTypeCompounds(processingEnv, ptypes.get(pidx), tapos));
++pidx;
}
}
{
// throws clauses
int tidx = 0;
java.util.List<AnnotatedTypeMirror> ttypes = mtype.getThrownTypes();
for (JCTree thr : ((JCTree.JCMethodDecl) meth).getThrows()) {
tapos = TypeAnnotationUtils.methodThrowsTAPosition(tidx, thr.pos);
tcs = tcs.appendList(generateTypeCompounds(processingEnv, ttypes.get(tidx), tapos));
++tidx;
}
}
addUniqueTypeCompounds(types, sym, tcs);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.
the class LockAnnotatedTypeFactory method methodFromUse.
@Override
public Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType) {
Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> mfuPair = super.methodFromUse(tree, methodElt, receiverType);
if (tree.getKind() != Kind.METHOD_INVOCATION) {
return mfuPair;
}
// If a method's formal return type is annotated with @GuardSatisfied(index), look for the
// first instance of @GuardSatisfied(index) in the method definition's receiver type or
// formal parameters, retrieve the corresponding type of the actual parameter / receiver at
// the call site (e.g. @GuardedBy("someLock") and replace the return type at the call site
// with this type.
AnnotatedExecutableType invokedMethod = mfuPair.first;
if (invokedMethod.getElement().getKind() == ElementKind.CONSTRUCTOR) {
return mfuPair;
}
AnnotatedTypeMirror methodDefinitionReturn = invokedMethod.getReturnType();
if (methodDefinitionReturn == null || !methodDefinitionReturn.hasAnnotation(GuardSatisfied.class)) {
return mfuPair;
}
int returnGuardSatisfiedIndex = getGuardSatisfiedIndex(methodDefinitionReturn);
if (returnGuardSatisfiedIndex == -1) {
return mfuPair;
}
if (!ElementUtils.isStatic(invokedMethod.getElement()) && replaceAnnotationInGuardedByHierarchyIfGuardSatisfiedIndexMatches(methodDefinitionReturn, invokedMethod.getReceiverType(), /* the method definition receiver*/
returnGuardSatisfiedIndex, receiverType.getAnnotationInHierarchy(GUARDEDBYUNKNOWN))) {
return mfuPair;
}
List<? extends ExpressionTree> methodInvocationTreeArguments = ((MethodInvocationTree) tree).getArguments();
List<AnnotatedTypeMirror> requiredArgs = AnnotatedTypes.expandVarArgs(this, invokedMethod, methodInvocationTreeArguments);
for (int i = 0; i < requiredArgs.size(); i++) {
if (replaceAnnotationInGuardedByHierarchyIfGuardSatisfiedIndexMatches(methodDefinitionReturn, requiredArgs.get(i), returnGuardSatisfiedIndex, getAnnotatedType(methodInvocationTreeArguments.get(i)).getEffectiveAnnotationInHierarchy(GUARDEDBYUNKNOWN))) {
return mfuPair;
}
}
return mfuPair;
}
Aggregations