use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 in project che by eclipse.
the class InferTypeArgumentsRefactoring method hasUnboundElement.
private static boolean hasUnboundElement(ConstraintVariable2 methodReceiverCv, InferTypeArgumentsTCModel tCModel) {
ArrayList<CollectionElementVariable2> typeArgumentCvs = getTypeArgumentCvs(methodReceiverCv, tCModel);
for (Iterator<CollectionElementVariable2> iter = typeArgumentCvs.iterator(); iter.hasNext(); ) {
CollectionElementVariable2 elementCv = iter.next();
TType chosenElementType = InferTypeArgumentsConstraintsSolver.getChosenType(elementCv);
if (chosenElementType == null)
return true;
}
return false;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 in project che by eclipse.
the class InferTypeArgumentsRefactoring method rewriteDeclarations.
private void rewriteDeclarations(InferTypeArgumentsUpdate update, IProgressMonitor pm) throws CoreException {
HashMap<ICompilationUnit, CuUpdate> updates = update.getUpdates();
Set<Entry<ICompilationUnit, CuUpdate>> entrySet = updates.entrySet();
//$NON-NLS-1$
pm.beginTask("", entrySet.size());
pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_creatingChanges);
for (Iterator<Entry<ICompilationUnit, CuUpdate>> iter = entrySet.iterator(); iter.hasNext(); ) {
if (pm.isCanceled())
throw new OperationCanceledException();
Entry<ICompilationUnit, CuUpdate> entry = iter.next();
ICompilationUnit cu = entry.getKey();
pm.worked(1);
pm.subTask(BasicElementLabels.getFileName(cu));
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(cu);
rewrite.setResolveBindings(false);
CuUpdate cuUpdate = entry.getValue();
for (Iterator<CollectionElementVariable2> cvIter = cuUpdate.getDeclarations().iterator(); cvIter.hasNext(); ) {
ConstraintVariable2 cv = cvIter.next();
rewriteConstraintVariable(cv, rewrite, fTCModel, fLeaveUnconstrainedRaw, null);
}
for (Iterator<CastVariable2> castsIter = cuUpdate.getCastsToRemove().iterator(); castsIter.hasNext(); ) {
CastVariable2 castCv = castsIter.next();
rewriteCastVariable(castCv, rewrite, fTCModel);
}
CompilationUnitChange change = rewrite.createChange(true);
if (change != null) {
fChangeManager.manage(cu, change);
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 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.CollectionElementVariable2 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();
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeElementVariable.
private CollectionElementVariable2 makeElementVariable(ConstraintVariable2 expressionCv, TypeVariable typeVariable, int declarationTypeVariableIndex) {
if (expressionCv == null)
return null;
CollectionElementVariable2 storedElementVariable = getElementVariable(expressionCv, typeVariable);
if (storedElementVariable != null)
return storedElementVariable;
CollectionElementVariable2 cv = new CollectionElementVariable2(expressionCv, typeVariable, declarationTypeVariableIndex);
cv = (CollectionElementVariable2) storedCv(cv);
setElementVariable(expressionCv, cv, typeVariable);
return cv;
}
Aggregations