use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 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.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(FieldAccess node) {
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
return;
}
ConstraintVariable2 nameCv = getConstraintVariable(node.getName());
setConstraintVariable(node, nameCv);
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisitFieldVariableDeclaration.
private void endVisitFieldVariableDeclaration(Type type, List<VariableDeclarationFragment> list) {
ConstraintVariable2 typeCv = getConstraintVariable(type);
if (typeCv == null)
return;
for (Iterator<VariableDeclarationFragment> iter = list.iterator(); iter.hasNext(); ) {
VariableDeclarationFragment fragment = iter.next();
ConstraintVariable2 fragmentCv = getConstraintVariable(fragment);
fTCModel.createElementEqualsConstraints(typeCv, fragmentCv);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method addConstraintsForOverriding.
private void addConstraintsForOverriding(IMethodBinding methodBinding, ConstraintVariable2 returnTypeCv, ConstraintVariable2[] parameterTypeCvs) {
boolean hasParameterElementCvs = false;
for (int i = 0; i < parameterTypeCvs.length; i++) if (parameterTypeCvs[i] != null)
hasParameterElementCvs = true;
if (returnTypeCv == null && !hasParameterElementCvs)
return;
ITypeBinding[] allSuperTypes = Bindings.getAllSuperTypes(methodBinding.getDeclaringClass());
for (int i = 0; i < allSuperTypes.length; i++) {
ITypeBinding superType = allSuperTypes[i];
IMethodBinding superMethod = Bindings.findOverriddenMethodInType(superType, methodBinding);
if (superMethod == null)
continue;
for (int p = 0; p < parameterTypeCvs.length; p++) {
if (parameterTypeCvs[p] == null)
continue;
ParameterTypeVariable2 parameterTypeCv = fTCModel.makeParameterTypeVariable(superMethod, p);
fTCModel.createElementEqualsConstraints(parameterTypeCv, parameterTypeCvs[p]);
}
if (returnTypeCv != null) {
ReturnTypeVariable2 superMethodReturnTypeCv = fTCModel.makeReturnTypeVariable(superMethod);
fTCModel.createElementEqualsConstraints(superMethodReturnTypeCv, returnTypeCv);
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.
the class ParametricStructureComputer method initializeContainerStructure.
//TODO hard-wired to collections
private void initializeContainerStructure() {
if (DEBUG_INITIALIZATION)
//$NON-NLS-1$
System.out.println(" *** Seeding container structure ***");
for (int i = 0; i < fAllConstraintVariables.length; i++) {
ConstraintVariable2 v = fAllConstraintVariables[i];
TType varType = declaredTypeOf(v);
if (varType != null) {
// List<String> to a binary method taking a raw List.
if (isParametricType(varType) && !isUnmodifiableFieldOrMethod(v)) {
//$NON-NLS-1$
if (DEBUG_INITIALIZATION)
System.out.println("Entity has container structure: " + v);
setStructureAndPush(v, newParametricType(varType));
} else if (!mightBeParametric(varType)) {
//$NON-NLS-1$
if (DEBUG_INITIALIZATION)
System.out.println("Entity DOES NOT have container structure: " + v);
setStructureAndPush(v, ParametricStructure.NONE);
}
// else we're not sure yet whether this has container structure
} else {
// TType exprType= v.getType(); // TODO: always null!
//
// if (isArrayAccess(v)) {
// if (DEBUG_INITIALIZATION) System.out.println("Entity DOES NOT have container structure: " + v);
// setStructureAndPush(v, NO_STRUCTURE); // definitely not container structure, Java 1.5 says no generics inside arrays
// } else if (isParametricType(exprType)) {
// if (DEBUG_INITIALIZATION) System.out.println("Entity has container structure: " + v);
// setStructureAndPush(v, newParametricType(exprType));
// } else if (exprType != null && !mightBeParametric(exprType)) {
// // Not a supertype of any container type - can't have container structure
// if (DEBUG_INITIALIZATION) System.out.println("Entity DOES NOT have container structure: " + v);
// setStructureAndPush(v, NO_STRUCTURE);
// }
// TODO Markus: the following just updates the set of child element variables of the parent variable of 'v'.
// You already maintain this information automatically, so the code below is not needed...
// if (v instanceof CollectionElementVariable2) {
// CollectionElementVariable2 ev= (CollectionElementVariable2) v;
// int idx= ev.getDeclarationTypeVariableIndex(); //TODO : INDEX IS -1 IF THE TYPE VARIABLE COMES FROM A SUPERTYPE!!!
//
// Collection/*<ConstraintVariable2>*/ vars= fTCModel.getElementVariables(ev).values();
//
// if (vars == null) vars= new ConstraintVariable2[ev.getNumContainerTypeParams()];
// vars[idx]= ev;
// fVariableElementEnv.setElementVariables(ev.getParentConstraintVariable(), vars);
// }
// else we're not sure yet whether this has container structure
}
}
// Every variable v in fAllVariables is now in one of 3 states:
// - elemStructure(v) == some parametric type: definitely container structure, but we may not know the sub-structure yet
// - elemStructure(v) == some AbstractTypeParameter: definitely not container structure
// - elemStructure(v) == null: we know nothing yet about its structure
}
Aggregations