use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType in project che by eclipse.
the class InferTypeArgumentsTCModel method makeSupertypeElementVariables.
private void makeSupertypeElementVariables(ConstraintVariable2 expressionCv, TType supertype) {
if (supertype.isParameterizedType() || supertype.isRawType()) {
TType[] typeArguments = null;
if (supertype.isParameterizedType()) {
typeArguments = ((ParameterizedType) supertype).getTypeArguments();
}
TypeVariable[] typeParameters = ((GenericType) supertype.getTypeDeclaration()).getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
TypeVariable typeParameter = typeParameters[i];
TType referenceTypeArgument;
if (typeArguments == null) {
// raw type
referenceTypeArgument = typeParameter.getErasure();
} else {
referenceTypeArgument = typeArguments[i];
}
if (referenceTypeArgument.isTypeVariable()) {
CollectionElementVariable2 referenceTypeArgumentCv = getElementVariable(expressionCv, (TypeVariable) referenceTypeArgument);
if (referenceTypeArgumentCv != null) {
setElementVariable(expressionCv, referenceTypeArgumentCv, typeParameter);
continue;
}
}
makeElementVariable(expressionCv, typeParameter, CollectionElementVariable2.NOT_DECLARED_TYPE_VARIABLE_INDEX);
}
}
makeElementVariablesFromSupertypes(expressionCv, supertype);
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType in project che by eclipse.
the class InferTypeArgumentsTCModel method makeElementVariables.
public void makeElementVariables(ConstraintVariable2 expressionCv, TType type) {
if (isAGenericType(type)) {
GenericType genericType = (GenericType) type.getTypeDeclaration();
TType[] typeParameters = genericType.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
TypeVariable typeVariable = (TypeVariable) typeParameters[i];
makeElementVariable(expressionCv, typeVariable, i);
if (typeVariable.getBounds().length != 0) {
//TODO: create subtype constraints for bounds
}
}
}
makeElementVariablesFromSupertypes(expressionCv, type.getTypeDeclaration());
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType in project che by eclipse.
the class InferTypeArgumentsTCModel method makeFixedElementVariables.
public void makeFixedElementVariables(ConstraintVariable2 expressionCv, TType type) {
if (isAGenericType(type)) {
GenericType genericType = (GenericType) type.getTypeDeclaration();
TType[] typeParameters = genericType.getTypeParameters();
TType[] typeArguments = null;
if (type.isParameterizedType())
typeArguments = ((ParameterizedType) type).getTypeArguments();
for (int i = 0; i < typeParameters.length; i++) {
TypeVariable typeVariable = (TypeVariable) typeParameters[i];
CollectionElementVariable2 elementCv = makeElementVariable(expressionCv, typeVariable, i);
TType referenceTypeArgument;
if (typeArguments == null) {
// do not consider
continue;
} else {
referenceTypeArgument = typeArguments[i];
}
createEqualsConstraint(elementCv, makeImmutableTypeVariable(referenceTypeArgument));
// if (typeVariable.getBounds().length != 0) {
// //TODO: create subtype constraints for bounds
// }
}
}
makeFixedElementVariablesFromSupertypes(expressionCv, type.getTypeDeclaration());
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType 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.typeconstraints.types.GenericType in project che by eclipse.
the class InferTypeArgumentsTCModel method makeFixedSupertypeElementVariables.
private void makeFixedSupertypeElementVariables(ConstraintVariable2 expressionCv, TType supertype) {
if (supertype.isParameterizedType() || supertype.isRawType()) {
TType[] typeArguments = null;
if (supertype.isParameterizedType())
typeArguments = ((ParameterizedType) supertype).getTypeArguments();
TypeVariable[] typeParameters = ((GenericType) supertype.getTypeDeclaration()).getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
TypeVariable typeParameter = typeParameters[i];
TType referenceTypeArgument;
if (typeArguments == null) {
// do not consider
continue;
} else {
referenceTypeArgument = typeArguments[i];
}
if (referenceTypeArgument.isTypeVariable()) {
CollectionElementVariable2 referenceTypeArgumentCv = getElementVariable(expressionCv, (TypeVariable) referenceTypeArgument);
setElementVariable(expressionCv, referenceTypeArgumentCv, typeParameter);
} else {
CollectionElementVariable2 elementCv = makeElementVariable(expressionCv, typeParameter, CollectionElementVariable2.NOT_DECLARED_TYPE_VARIABLE_INDEX);
createEqualsConstraint(elementCv, makeImmutableTypeVariable(referenceTypeArgument));
}
}
}
makeFixedElementVariablesFromSupertypes(expressionCv, supertype);
}
Aggregations