use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 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.ConstraintVariable2 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.ConstraintVariable2 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.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeTypeVariable.
public TypeVariable2 makeTypeVariable(Type type) {
ICompilationUnit cu = RefactoringASTParser.getCompilationUnit(type);
TType ttype = getBoxedType(type.resolveBinding(), /*no boxing*/
null);
if (ttype == null)
return null;
CompilationUnitRange range = new CompilationUnitRange(cu, type);
TypeVariable2 typeVariable = new TypeVariable2(ttype, range);
TypeVariable2 storedCv = (TypeVariable2) storedCv(typeVariable);
if (storedCv == typeVariable) {
fCuScopedConstraintVariables.add(storedCv);
if (isAGenericType(ttype))
makeElementVariables(storedCv, ttype);
makeArrayElementVariable(storedCv);
if (fStoreToString)
storedCv.setData(ConstraintVariable2.TO_STRING, type.toString());
}
return storedCv;
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsTCModel method makeReturnTypeVariable.
public ReturnTypeVariable2 makeReturnTypeVariable(IMethodBinding methodBinding) {
if (methodBinding == null)
return null;
TType returnType = getBoxedType(methodBinding.getReturnType(), /*no boxing*/
null);
if (returnType == null)
return null;
ReturnTypeVariable2 cv = new ReturnTypeVariable2(returnType, methodBinding);
ReturnTypeVariable2 storedCv = (ReturnTypeVariable2) storedCv(cv);
if (cv == storedCv) {
makeElementVariables(storedCv, returnType);
makeArrayElementVariable(storedCv);
if (fStoreToString)
//$NON-NLS-1$ //$NON-NLS-2$
storedCv.setData(ConstraintVariable2.TO_STRING, "[ReturnType(" + Bindings.asString(methodBinding) + ")]");
}
return storedCv;
}
Aggregations