use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2 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.CastVariable2 in project che by eclipse.
the class InferTypeArgumentsRefactoring method rewriteCastVariable.
private static ASTNode rewriteCastVariable(CastVariable2 castCv, CompilationUnitRewrite rewrite, InferTypeArgumentsTCModel tCModel) {
//, List positionGroups) {
ASTNode node = castCv.getRange().getNode(rewrite.getRoot());
ConstraintVariable2 expressionVariable = castCv.getExpressionVariable();
ConstraintVariable2 methodReceiverCv = tCModel.getMethodReceiverCv(expressionVariable);
if (methodReceiverCv != null) {
TType chosenReceiverType = InferTypeArgumentsConstraintsSolver.getChosenType(methodReceiverCv);
if (chosenReceiverType == null)
return null;
else if (!InferTypeArgumentsTCModel.isAGenericType(chosenReceiverType))
return null;
else if (hasUnboundElement(methodReceiverCv, tCModel))
return null;
}
CastExpression castExpression = (CastExpression) node;
Expression expression = castExpression.getExpression();
ASTNode nodeToReplace;
if (castExpression.getParent() instanceof ParenthesizedExpression)
nodeToReplace = castExpression.getParent();
else
nodeToReplace = castExpression;
Expression newExpression = (Expression) rewrite.getASTRewrite().createMoveTarget(expression);
rewrite.getASTRewrite().replace(nodeToReplace, newExpression, rewrite.createGroupDescription(RefactoringCoreMessages.InferTypeArgumentsRefactoring_removeCast));
rewrite.getImportRemover().registerRemovedNode(nodeToReplace);
return newExpression;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeCastVariable.
public CastVariable2 makeCastVariable(CastExpression castExpression, ConstraintVariable2 expressionCv) {
ITypeBinding typeBinding = castExpression.resolveTypeBinding();
ICompilationUnit cu = RefactoringASTParser.getCompilationUnit(castExpression);
CompilationUnitRange range = new CompilationUnitRange(cu, castExpression);
CastVariable2 castCv = new CastVariable2(createTType(typeBinding), range, expressionCv);
fCastVariables.add(castCv);
return castCv;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2 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);
}
}
}
}
Aggregations