use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2 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.TypeVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
/*
* @see org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor#endVisit(org.eclipse.jdt.core.dom.Type)
*/
@Override
public void endVisit(Type node) {
if (node.isParameterizedType()) {
// retain already parameterized types
ImmutableTypeVariable2 typeVariable = fTCModel.makeImmutableTypeVariable(node.resolveBinding(), /*no boxing*/
null);
setConstraintVariable(node, typeVariable);
} else {
TypeVariable2 typeVariable = fTCModel.makeTypeVariable(node);
setConstraintVariable(node, typeVariable);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(ArrayCreation node) {
ArrayType arrayType = node.getType();
TypeVariable2 arrayTypeCv = (TypeVariable2) getConstraintVariable(arrayType);
if (arrayTypeCv == null)
return;
setConstraintVariable(node, arrayTypeCv);
//TODO: constraints for array initializer?
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(CastExpression node) {
// if (! (expressionCv instanceof CollectionElementVariable2))
// return; //TODO: returns too early when dealing with nested collections.
Type type = node.getType();
ITypeBinding typeBinding = type.resolveBinding();
if (typeBinding.isPrimitive()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(typeBinding, node);
setConstraintVariable(node, boxed);
// avoid removing numeric conversions
return;
}
ConstraintVariable2 typeCv = getConstraintVariable(type);
if (typeCv == null)
return;
//TODO: can this be loosened when we remove casts?
setConstraintVariable(node, typeCv);
Expression expression = node.getExpression();
ConstraintVariable2 expressionCv = getConstraintVariable(expression);
//Avoid removing casts that have not been made obsolete by this refactoring:
if (expressionCv == null)
return;
if (expressionCv instanceof ImmutableTypeVariable2)
return;
if (!(expressionCv instanceof TypeVariable2 || expressionCv instanceof IndependentTypeVariable2 || expressionCv instanceof CollectionElementVariable2) && fTCModel.getElementVariables(expressionCv).size() == 0 && fTCModel.getArrayElementVariable(expressionCv) == null)
return;
fTCModel.createAssignmentElementConstraints(typeCv, expressionCv);
if (expression instanceof MethodInvocation) {
MethodInvocation invoc = (MethodInvocation) expression;
if (!isSpecialCloneInvocation(invoc.resolveMethodBinding(), invoc.getExpression())) {
fTCModel.makeCastVariable(node, expressionCv);
}
} else {
fTCModel.makeCastVariable(node, expressionCv);
}
boolean eitherIsIntf = typeBinding.isInterface() || expression.resolveTypeBinding().isInterface();
if (eitherIsIntf)
return;
//TODO: preserve up- and down-castedness!
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2 in project che by eclipse.
the class InferTypeArgumentsRefactoring method rewriteTypeVariable.
private static ParameterizedType rewriteTypeVariable(TypeVariable2 typeCv, CompilationUnitRewrite rewrite, InferTypeArgumentsTCModel tCModel, boolean leaveUnconstraindRaw, SimpleType[] types) {
ASTNode node = typeCv.getRange().getNode(rewrite.getRoot());
if (node instanceof Name && node.getParent() instanceof Type) {
Type originalType = (Type) node.getParent();
if (types != null && !has(types, originalType))
return null;
// Must rewrite all type arguments in one batch. Do the rewrite when the first one is encountered; skip the others.
Object rewritten = originalType.getProperty(REWRITTEN);
if (rewritten == REWRITTEN)
return null;
originalType.setProperty(REWRITTEN, REWRITTEN);
ArrayList<CollectionElementVariable2> typeArgumentCvs = getTypeArgumentCvs(typeCv, tCModel);
Type[] typeArguments = getTypeArguments(originalType, typeArgumentCvs, rewrite, tCModel, leaveUnconstraindRaw);
if (typeArguments == null)
return null;
Type movingType = (Type) rewrite.getASTRewrite().createMoveTarget(originalType);
ParameterizedType newType = rewrite.getAST().newParameterizedType(movingType);
for (int i = 0; i < typeArguments.length; i++) {
newType.typeArguments().add(typeArguments[i]);
}
rewrite.getASTRewrite().replace(originalType, newType, rewrite.createGroupDescription(RefactoringCoreMessages.InferTypeArgumentsRefactoring_addTypeArguments));
return newType;
} else {
//TODO: other node types?
return null;
}
}
Aggregations