use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method createTypeVariablesEqualityConstraints.
/**
* Create equality constraints between generic type variables of expressionCv and referenceCv.
* For example, the generic interface <code>java.lang.Iterable<E></code> defines a method
* <code>Iterator<E> iterator()</code>. Given
* <ul>
* <li>an expressionCv of a subtype of <code>Iterable</code>,</li>
* <li>a referenceCv of a subtype of <code>Iterator</code>, and</li>
* <li>a reference binding of the Iterable#iterator()'s return type (the parameterized type <code>Iterator<E></code>),</li>
* </ul>
* this method creates an equality constraint between the type variable E in expressionCV and
* the type variable E in referenceCV.
*
* @param expressionCv the type constraint variable of an expression
* @param methodTypeVariables
* @param referenceCv the type constraint variable of a type reference
* @param reference the declared type reference
*/
public void createTypeVariablesEqualityConstraints(ConstraintVariable2 expressionCv, Map<String, IndependentTypeVariable2> methodTypeVariables, ConstraintVariable2 referenceCv, TType reference) {
if (reference.isParameterizedType() || reference.isRawType()) {
TType[] referenceTypeArguments = null;
if (reference.isParameterizedType()) {
referenceTypeArguments = ((ParameterizedType) reference).getTypeArguments();
}
TType[] referenceTypeParameters = ((GenericType) reference.getTypeDeclaration()).getTypeParameters();
for (int i = 0; i < referenceTypeParameters.length; i++) {
TypeVariable referenceTypeParameter = (TypeVariable) referenceTypeParameters[i];
TType referenceTypeArgument;
if (referenceTypeArguments == null)
referenceTypeArgument = referenceTypeParameter.getErasure();
else
referenceTypeArgument = referenceTypeArguments[i];
if (referenceTypeArgument.isTypeVariable()) {
ConstraintVariable2 referenceTypeArgumentCv = getElementTypeCv(referenceTypeArgument, expressionCv, methodTypeVariables);
CollectionElementVariable2 referenceTypeParametersCv = getElementVariable(referenceCv, referenceTypeParameter);
createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
} else if (referenceTypeArgument.isWildcardType()) {
//block it for now (bug 106174)
ConstraintVariable2 referenceTypeArgumentCv = makeImmutableTypeVariable(fTypeEnvironment.VOID);
CollectionElementVariable2 referenceTypeParametersCv = getElementVariable(referenceCv, referenceTypeParameter);
createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
// WildcardType wildcardType= (WildcardType) referenceTypeArgument;
// if (wildcardType.isUnboundWildcardType()) {
// ConstraintVariable2 referenceTypeArgumentCv= makeImmutableTypeVariable(wildcardType);
// CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
// createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
// } else if (wildcardType.isSuperWildcardType() && wildcardType.getBound().isTypeVariable()) {
// ConstraintVariable2 referenceTypeArgumentBoundCv= getElementTypeCv(wildcardType.getBound(), expressionCv, methodTypeVariables);
// CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
// //TODO: need *strict* subtype constraint?
// createSubtypeConstraint(referenceTypeParametersCv, referenceTypeArgumentBoundCv);
// }
// else: TODO
// } else if (referenceTypeArgument.isParameterizedType()) {
// //TODO: nested containers
// ParameterizedType parameterizedType= (ParameterizedType) referenceTypeArgument;
// ParameterizedTypeVariable2 parameterizedTypeCv= makeParameterizedTypeVariable(parameterizedType.getTypeDeclaration());
// CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
// createEqualsConstraint(parameterizedTypeCv, referenceTypeParametersCv);
// createElementEqualsConstraints(parameterizedTypeCv, referenceTypeParametersCv);
} else {
//TODO
}
}
} else if (reference.isArrayType()) {
TType elementType = ((ArrayType) reference).getElementType();
if (elementType.isRawType())
elementType = elementType.getErasure();
ConstraintVariable2 elementTypeCv = getElementTypeCv(elementType, expressionCv, methodTypeVariables);
ArrayElementVariable2 arrayElementTypeCv = getArrayElementVariable(referenceCv);
createEqualsConstraint(elementTypeCv, arrayElementTypeCv);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(MethodInvocation node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
if (methodBinding == null)
return;
Expression receiver;
if (JdtFlags.isStatic(methodBinding))
receiver = null;
else
receiver = node.getExpression();
if (isSpecialCloneInvocation(methodBinding, receiver)) {
ConstraintVariable2 expressionCv = getConstraintVariable(receiver);
// [retVal] =^= [receiver]:
setConstraintVariable(node, expressionCv);
} else if ("getClass".equals(methodBinding.getName()) && methodBinding.getParameterTypes().length == 0) {
//$NON-NLS-1$
//special case: see JLS3 4.3.2
ITypeBinding returnType = node.resolveTypeBinding();
ITypeBinding returnTypeDeclaration = returnType.getTypeDeclaration();
ParameterizedTypeVariable2 expressionCv = fTCModel.makeParameterizedTypeVariable(returnTypeDeclaration);
setConstraintVariable(node, expressionCv);
ConstraintVariable2 classTypeVariable = fTCModel.getElementVariable(expressionCv, returnTypeDeclaration.getTypeParameters()[0]);
//type of expression 'e.getClass()' is 'Class<? extends X>' where X is the static type of e
ITypeBinding capture = returnType.getTypeArguments()[0];
ITypeBinding wildcard = capture.getWildcard();
if (wildcard.getBound() == null)
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619
return;
ImmutableTypeVariable2 wildcardType = fTCModel.makeImmutableTypeVariable(wildcard, /*no boxing*/
null);
fTCModel.createSubtypeConstraint(classTypeVariable, wildcardType);
// ITypeBinding bound= wildcard.getBound();
// ImmutableTypeVariable2 boundType= fTCModel.makeImmutableTypeVariable(bound, node.getAST());
// fTCModel.createSubtypeConstraint(classTypeVariable, boundType);
} else {
Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
doVisitMethodInvocationReturnType(node, methodBinding, receiver, methodTypeVariables);
doVisitMethodInvocationArguments(methodBinding, node.arguments(), receiver, methodTypeVariables, /*no created type*/
null);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeParameterizedTypeVariable.
private ParameterizedTypeVariable2 makeParameterizedTypeVariable(TType type) {
Assert.isTrue(isAGenericType(type));
ParameterizedTypeVariable2 cv = new ParameterizedTypeVariable2(type);
ParameterizedTypeVariable2 storedCv = (ParameterizedTypeVariable2) storedCv(cv);
if (cv == storedCv) {
fCuScopedConstraintVariables.add(storedCv);
makeElementVariables(storedCv, type);
if (fStoreToString)
//$NON-NLS-1$ //$NON-NLS-2$
storedCv.setData(ConstraintVariable2.TO_STRING, "ParameterizedType(" + type.getPrettySignature() + ")");
}
return storedCv;
}
Aggregations