use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(SimpleName node) {
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
return;
}
IBinding binding = node.resolveBinding();
if (binding instanceof IVariableBinding) {
//TODO: code is similar to handling of method return value
IVariableBinding variableBinding = (IVariableBinding) binding;
ITypeBinding declaredVariableType = variableBinding.getVariableDeclaration().getType();
if (declaredVariableType.isTypeVariable()) {
Expression receiver = getSimpleNameReceiver(node);
if (receiver != null) {
ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
// the type variable must come from the receiver!
Assert.isNotNull(receiverCv);
ConstraintVariable2 elementCv = fTCModel.getElementVariable(receiverCv, declaredVariableType);
// [retVal] =^= Elem[receiver]:
setConstraintVariable(node, elementCv);
return;
}
} else if (declaredVariableType.isParameterizedType()) {
Expression receiver = getSimpleNameReceiver(node);
if (receiver != null) {
ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
if (receiverCv != null) {
// ITypeBinding genericVariableType= declaredVariableType.getTypeDeclaration();
ConstraintVariable2 returnTypeCv = fTCModel.makeParameterizedTypeVariable(declaredVariableType);
setConstraintVariable(node, returnTypeCv);
// Elem[retVal] =^= Elem[receiver]
TType declaredVariableTType = fTCModel.createTType(declaredVariableType);
fTCModel.createTypeVariablesEqualityConstraints(receiverCv, Collections.<String, IndependentTypeVariable2>emptyMap(), returnTypeCv, declaredVariableTType);
return;
}
}
} else {
//TODO: array...
//logUnexpectedNode(node, null);
}
// default:
VariableVariable2 cv = fTCModel.makeVariableVariable(variableBinding);
setConstraintVariable(node, cv);
}
// TODO else?
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method processConstraints.
/**
* Given a list of <code>ITypeConstraint2</code>s that all refer to a
* given <code>ConstraintVariable2</code> (whose type bound has presumably
* just changed), process each <code>ITypeConstraint</code>, propagating
* the type bound across the constraint as needed.
*
* @param usedIn the <code>List</code> of <code>ITypeConstraint2</code>s
* to process
*/
private void processConstraints(List<ITypeConstraint2> usedIn) {
Iterator<ITypeConstraint2> iter = usedIn.iterator();
while (iter.hasNext()) {
ITypeConstraint2 tc = iter.next();
maintainSimpleConstraint(tc);
//TODO: prune tcs which cannot cause further changes
// Maybe these should be pruned after a special first loop over all ConstraintVariables,
// Since this can only happen once for every CV in the work list.
// if (isConstantConstraint(stc))
// fTypeConstraintFactory.removeUsedIn(stc, changedCv);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method findCastsToRemove.
private void findCastsToRemove(CastVariable2[] castVariables) {
for (int i = 0; i < castVariables.length; i++) {
CastVariable2 castCv = castVariables[i];
ConstraintVariable2 expressionVariable = castCv.getExpressionVariable();
TType chosenType = InferTypeArgumentsConstraintsSolver.getChosenType(expressionVariable);
TType castType = castCv.getType();
TType expressionType = expressionVariable.getType();
if (chosenType != null && TTypes.canAssignTo(chosenType, castType)) {
if (chosenType.equals(expressionType))
// The type has not changed. Don't remove the cast, since it could be
continue;
// there to get access to default-visible members or to
// unify types of conditional expressions.
fUpdate.addCastToRemove(castCv);
} else if (expressionVariable instanceof ArrayTypeVariable2 && castType.isArrayType()) {
// bug 97258
ArrayElementVariable2 arrayElementCv = fTCModel.getArrayElementVariable(expressionVariable);
if (arrayElementCv == null)
continue;
TType chosenArrayElementType = InferTypeArgumentsConstraintsSolver.getChosenType(arrayElementCv);
if (chosenArrayElementType != null && TTypes.canAssignTo(chosenArrayElementType, ((ArrayType) castType).getComponentType())) {
if (expressionType instanceof ArrayType && chosenArrayElementType.equals(((ArrayType) expressionType).getComponentType()))
// The type has not changed. Don't remove the cast, since it could be
continue;
// there to unify types of conditional expressions.
fUpdate.addCastToRemove(castCv);
}
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method initializeTypeEstimates.
private void initializeTypeEstimates(ConstraintVariable2[] allConstraintVariables) {
for (int i = 0; i < allConstraintVariables.length; i++) {
ConstraintVariable2 cv = allConstraintVariables[i];
//TODO: not necessary for types that are not used in a TypeConstraint but only as type in CollectionElementVariable
//TODO: handle nested element variables; see ParametricStructureComputer.createAndInitVars()
TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
if (set == null) {
set = new TypeEquivalenceSet(cv);
set.setTypeEstimate(createInitialEstimate(cv));
cv.setTypeEquivalenceSet(set);
} else {
TypeSet typeEstimate = (TypeSet) cv.getTypeEstimate();
if (typeEstimate == null) {
ConstraintVariable2[] cvs = set.getContributingVariables();
typeEstimate = fTypeSetEnvironment.getUniverseTypeSet();
for (//TODO: optimize: just try to find an immutable CV; if not found, use Universe
int j = 0; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
j < cvs.length; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
j++) typeEstimate = typeEstimate.intersectedWith(createInitialEstimate(cvs[j]));
set.setTypeEstimate(typeEstimate);
}
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method getChosenType.
public static TType getChosenType(ConstraintVariable2 cv) {
TType type = (TType) cv.getData(CHOSEN_TYPE);
if (type != null)
return type;
TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
if (set == null) {
//TODO: should not have to set this here. Clean up when caching chosen type
return null;
// // no representative == no restriction
// set= new TypeEquivalenceSet(cv);
// set.setTypeEstimate(TypeUniverseSet.create());
// cv.setTypeEquivalenceSet(set);
}
return cv.getTypeEstimate().chooseSingleType();
}
Aggregations