use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(ParenthesizedExpression node) {
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
return;
}
ConstraintVariable2 expressionCv = getConstraintVariable(node.getExpression());
setConstraintVariable(node, expressionCv);
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(ClassInstanceCreation node) {
Expression receiver = node.getExpression();
Type createdType = node.getType();
ConstraintVariable2 typeCv;
if (node.getAnonymousClassDeclaration() == null) {
typeCv = getConstraintVariable(createdType);
} else {
typeCv = fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
setConstraintVariable(createdType, typeCv);
}
setConstraintVariable(node, typeCv);
IMethodBinding methodBinding = node.resolveConstructorBinding();
Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
List<Expression> arguments = node.arguments();
doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(MethodDeclaration node) {
IMethodBinding methodBinding = node.resolveBinding();
if (methodBinding == null)
//TODO: emit error?
return;
int parameterCount = node.parameters().size();
ConstraintVariable2[] parameterTypeCvs = new ConstraintVariable2[parameterCount];
for (int i = 0; i < parameterCount; i++) {
SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) node.parameters().get(i);
//parameterTypeVariable currently not used, but need to register in order to store source range
ConstraintVariable2 parameterTypeCv = fTCModel.makeDeclaredParameterTypeVariable(methodBinding, i, fCU);
parameterTypeCvs[i] = parameterTypeCv;
if (parameterTypeCv == null)
continue;
//creating equals constraint between parameterTypeVariable's elements and the Type's elements
ConstraintVariable2 typeCv = getConstraintVariable(paramDecl.getType());
fTCModel.createElementEqualsConstraints(parameterTypeCv, typeCv);
//TODO: should avoid having a VariableVariable as well as a ParameterVariable for a parameter
ConstraintVariable2 nameCv = getConstraintVariable(paramDecl.getName());
fTCModel.createElementEqualsConstraints(parameterTypeCv, nameCv);
}
ConstraintVariable2 returnTypeCv = null;
if (!methodBinding.isConstructor()) {
//TODO: should only create return type variable if type is generic?
ConstraintVariable2 returnTypeBindingCv = fTCModel.makeDeclaredReturnTypeVariable(methodBinding, fCU);
if (returnTypeBindingCv != null) {
returnTypeCv = getConstraintVariable(node.getReturnType2());
fTCModel.createElementEqualsConstraints(returnTypeBindingCv, returnTypeCv);
}
}
if (MethodChecks.isVirtual(methodBinding)) {
//TODO: RippleMethod constraints for corner cases: see testCuRippleMethods3, bug 41989
addConstraintsForOverriding(methodBinding, returnTypeCv, parameterTypeCvs);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method solveConstraints.
public InferTypeArgumentsUpdate solveConstraints(IProgressMonitor pm) {
//$NON-NLS-1$
pm.beginTask("", 2);
fUpdate = new InferTypeArgumentsUpdate();
ConstraintVariable2[] allConstraintVariables = fTCModel.getAllConstraintVariables();
if (allConstraintVariables.length == 0)
return fUpdate;
fTypeSetEnvironment = new TypeSetEnvironment(fTCModel.getTypeEnvironment());
ParametricStructureComputer parametricStructureComputer = new ParametricStructureComputer(allConstraintVariables, fTCModel);
Collection<CollectionElementVariable2> newVars = parametricStructureComputer.createElemConstraintVariables();
ArrayList<ConstraintVariable2> newAllConstraintVariables = new ArrayList<ConstraintVariable2>();
newAllConstraintVariables.addAll(Arrays.asList(allConstraintVariables));
newAllConstraintVariables.addAll(newVars);
allConstraintVariables = newAllConstraintVariables.toArray(new ConstraintVariable2[newAllConstraintVariables.size()]);
//loop over all TypeEquivalenceSets and unify the elements from the fElemStructureEnv with the existing TypeEquivalenceSets
HashSet<TypeEquivalenceSet> allTypeEquivalenceSets = new HashSet<TypeEquivalenceSet>();
for (int i = 0; i < allConstraintVariables.length; i++) {
TypeEquivalenceSet typeEquivalenceSet = allConstraintVariables[i].getTypeEquivalenceSet();
if (typeEquivalenceSet != null)
allTypeEquivalenceSets.add(typeEquivalenceSet);
}
for (Iterator<TypeEquivalenceSet> iter = allTypeEquivalenceSets.iterator(); iter.hasNext(); ) {
TypeEquivalenceSet typeEquivalenceSet = iter.next();
ConstraintVariable2[] contributingVariables = typeEquivalenceSet.getContributingVariables();
for (int i = 0; i < contributingVariables.length; i++) {
for (int j = i + 1; j < contributingVariables.length; j++) {
ConstraintVariable2 first = contributingVariables[i];
ConstraintVariable2 second = contributingVariables[j];
// recursively
fTCModel.createElementEqualsConstraints(first, second);
}
}
}
ITypeConstraint2[] allTypeConstraints = fTCModel.getAllTypeConstraints();
for (int i = 0; i < allTypeConstraints.length; i++) {
ITypeConstraint2 typeConstraint = allTypeConstraints[i];
fTCModel.createElementEqualsConstraints(typeConstraint.getLeft(), typeConstraint.getRight());
}
initializeTypeEstimates(allConstraintVariables);
if (pm.isCanceled())
throw new OperationCanceledException();
fWorkList.addAll(Arrays.asList(allConstraintVariables));
runSolver(new SubProgressMonitor(pm, 1));
chooseTypes(allConstraintVariables, new SubProgressMonitor(pm, 1));
findCastsToRemove(fTCModel.getCastVariables());
return fUpdate;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintsSolver method chooseTypes.
private void chooseTypes(ConstraintVariable2[] allConstraintVariables, SubProgressMonitor pm) {
//$NON-NLS-1$
pm.beginTask("", allConstraintVariables.length);
for (int i = 0; i < allConstraintVariables.length; i++) {
ConstraintVariable2 cv = allConstraintVariables[i];
TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
if (set == null)
//TODO: should not happen iff all unused constraint variables got pruned
continue;
//TODO: should calculate only once per EquivalenceRepresentative; can throw away estimate TypeSet afterwards
//TODO: is null for Universe TypeSet
TType type = chooseSingleType((TypeSet) cv.getTypeEstimate());
setChosenType(cv, type);
if (cv instanceof CollectionElementVariable2) {
CollectionElementVariable2 elementCv = (CollectionElementVariable2) cv;
fUpdate.addDeclaration(elementCv);
}
pm.worked(1);
if (pm.isCanceled())
throw new OperationCanceledException();
}
pm.done();
}
Aggregations