Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2236,8 +2236,7 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void p) {
List<AnnotatedTypeMirror> typeargs = mType.typeArgs;

List<AnnotatedTypeParameterBounds> paramBounds =
CollectionsPlume.mapList(
AnnotatedTypeVariable::getBounds, invokedMethod.getTypeVariables());
atypeFactory.methodTypeVariablesFromUse(tree, invokedMethod);

ExecutableElement method = invokedMethod.getElement();
CharSequence methodName = ElementUtils.getSimpleDescription(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,26 @@ public List<AnnotatedTypeParameterBounds> typeVariablesFromUse(
return res;
}

/**
* Returns the method type parameter bounds adapted to the viewpoint of a method invocation.
*
* @param tree a method invocation
* @param invokedMethod the type of the invoked method
* @return the adapted method type parameter bounds
*/
public List<AnnotatedTypeParameterBounds> methodTypeVariablesFromUse(
MethodInvocationTree tree, AnnotatedExecutableType invokedMethod) {
List<AnnotatedTypeParameterBounds> bounds =
CollectionsPlume.mapList(
AnnotatedTypeVariable::getBounds, invokedMethod.getTypeVariables());

AnnotatedTypeMirror receiverType = getReceiverType(tree);
if (viewpointAdapter != null && receiverType != null) {
viewpointAdapter.viewpointAdaptTypeParameterBounds(receiverType, bounds);
}
Comment thread
aosen-xiong marked this conversation as resolved.
Outdated
return bounds;
}

/**
* Creates and returns an AnnotatedNullType qualified with {@code annotations}.
*
Expand Down
72 changes: 72 additions & 0 deletions framework/tests/viewpointtest/MethodTypeVariableBounds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import viewpointtest.quals.*;

public class MethodTypeVariableBounds {
static class Methods {
<T extends @ReceiverDependentQual Object> void noArg() {}

<T extends @ReceiverDependentQual Object> void withArg(T t) {}
}

void topReceiver(
@Top Methods methods,
@Top Object top,
@A Object a,
@B Object b,
@Bottom Object bottom) {
// @Top viewpoint-adapts @ReceiverDependentQual to @Lost, so only @Bottom is within the
// adapted method type parameter bound.
// :: error: (type.argument.type.incompatible)
methods.noArg();

// :: error: (type.argument.type.incompatible)
methods.<@Top Object>withArg(top);

// :: error: (type.argument.type.incompatible)
methods.<@A Object>withArg(a);

// :: error: (type.argument.type.incompatible)
methods.<@B Object>withArg(b);

methods.<@Bottom Object>withArg(bottom);

// :: error: (type.arguments.not.inferred)
methods.withArg(top);

// :: error: (type.arguments.not.inferred)
methods.withArg(a);

// :: error: (type.arguments.not.inferred)
methods.withArg(b);

methods.withArg(bottom);
}

void aReceiver(
@A Methods methods, @Top Object top, @A Object a, @B Object b, @Bottom Object bottom) {
// @A viewpoint-adapts @ReceiverDependentQual to @A, so @A and @Bottom are within the
// adapted method type parameter bound.
// :: error: (type.argument.type.incompatible)
methods.noArg();

// :: error: (type.argument.type.incompatible)
methods.<@Top Object>withArg(top);

methods.<@A Object>withArg(a);

// :: error: (type.argument.type.incompatible)
methods.<@B Object>withArg(b);

methods.<@Bottom Object>withArg(bottom);

// :: error: (type.arguments.not.inferred)
methods.withArg(top);

// :: error: (type.arguments.not.inferred)
methods.withArg(a);
Comment thread
aosen-xiong marked this conversation as resolved.

// :: error: (type.arguments.not.inferred)
methods.withArg(b);

methods.withArg(bottom);
}
}
Loading