use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method pruneCvIfUnused.
private boolean pruneCvIfUnused(ConstraintVariable2 cv) {
if (getUsedIn(cv).size() != 0)
return false;
if (cv.getTypeEquivalenceSet() != null) {
if (cv.getTypeEquivalenceSet().getContributingVariables().length > 0)
return false;
}
ArrayElementVariable2 arrayElementVariable = getArrayElementVariable(cv);
if (arrayElementVariable != null && !pruneCvIfUnused(arrayElementVariable))
return false;
Map<String, CollectionElementVariable2> elementVariables = getElementVariables(cv);
for (Iterator<CollectionElementVariable2> iter = elementVariables.values().iterator(); iter.hasNext(); ) {
CollectionElementVariable2 elementVariable = iter.next();
if (!pruneCvIfUnused(elementVariable))
return false;
}
fConstraintVariables.remove(cv);
return true;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method createEqualsConstraint.
public void createEqualsConstraint(ConstraintVariable2 leftElement, ConstraintVariable2 rightElement) {
if (leftElement == null || rightElement == null)
return;
TypeEquivalenceSet leftSet = leftElement.getTypeEquivalenceSet();
TypeEquivalenceSet rightSet = rightElement.getTypeEquivalenceSet();
if (leftSet == null) {
if (rightSet == null) {
TypeEquivalenceSet set = new TypeEquivalenceSet(leftElement, rightElement);
leftElement.setTypeEquivalenceSet(set);
rightElement.setTypeEquivalenceSet(set);
} else {
rightSet.add(leftElement);
leftElement.setTypeEquivalenceSet(rightSet);
}
} else {
if (rightSet == null) {
leftSet.add(rightElement);
rightElement.setTypeEquivalenceSet(leftSet);
} else if (leftSet == rightSet) {
return;
} else {
ConstraintVariable2[] cvs = rightSet.getContributingVariables();
leftSet.addAll(cvs);
for (int i = 0; i < cvs.length; i++) cvs[i].setTypeEquivalenceSet(leftSet);
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 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.typeconstraints2.ConstraintVariable2 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.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeArrayTypeVariable.
private ArrayTypeVariable2 makeArrayTypeVariable(ArrayType type) {
ArrayTypeVariable2 cv = new ArrayTypeVariable2(type);
ArrayTypeVariable2 storedCv = (ArrayTypeVariable2) storedCv(cv);
if (cv == storedCv) {
fCuScopedConstraintVariables.add(storedCv);
makeArrayElementVariable(storedCv);
if (fStoreToString)
//$NON-NLS-1$ //$NON-NLS-2$
storedCv.setData(ConstraintVariable2.TO_STRING, "ArrayType(" + type.getPrettySignature() + ")");
}
return storedCv;
}
Aggregations