Search in sources :

Example 6 with ConstraintVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(ParenthesizedExpression node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }
    ConstraintVariable2 expressionCv = getConstraintVariable(node.getExpression());
    setConstraintVariable(node, expressionCv);
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 7 with ConstraintVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(ClassInstanceCreation node) {
    Expression receiver = node.getExpression();
    Type createdType = node.getType();
    ConstraintVariable2 typeCv;
    if (node.getAnonymousClassDeclaration() == null) {
        typeCv = getConstraintVariable(createdType);
    } else {
        typeCv = fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
        setConstraintVariable(createdType, typeCv);
    }
    setConstraintVariable(node, typeCv);
    IMethodBinding methodBinding = node.resolveConstructorBinding();
    Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
    List<Expression> arguments = node.arguments();
    doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) GenericType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType) ParameterizedType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType) WildcardType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.WildcardType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Example 8 with ConstraintVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(MethodDeclaration node) {
    IMethodBinding methodBinding = node.resolveBinding();
    if (methodBinding == null)
        //TODO: emit error?
        return;
    int parameterCount = node.parameters().size();
    ConstraintVariable2[] parameterTypeCvs = new ConstraintVariable2[parameterCount];
    for (int i = 0; i < parameterCount; i++) {
        SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) node.parameters().get(i);
        //parameterTypeVariable currently not used, but need to register in order to store source range
        ConstraintVariable2 parameterTypeCv = fTCModel.makeDeclaredParameterTypeVariable(methodBinding, i, fCU);
        parameterTypeCvs[i] = parameterTypeCv;
        if (parameterTypeCv == null)
            continue;
        //creating equals constraint between parameterTypeVariable's elements and the Type's elements
        ConstraintVariable2 typeCv = getConstraintVariable(paramDecl.getType());
        fTCModel.createElementEqualsConstraints(parameterTypeCv, typeCv);
        //TODO: should avoid having a VariableVariable as well as a ParameterVariable for a parameter
        ConstraintVariable2 nameCv = getConstraintVariable(paramDecl.getName());
        fTCModel.createElementEqualsConstraints(parameterTypeCv, nameCv);
    }
    ConstraintVariable2 returnTypeCv = null;
    if (!methodBinding.isConstructor()) {
        //TODO: should only create return type variable if type is generic?
        ConstraintVariable2 returnTypeBindingCv = fTCModel.makeDeclaredReturnTypeVariable(methodBinding, fCU);
        if (returnTypeBindingCv != null) {
            returnTypeCv = getConstraintVariable(node.getReturnType2());
            fTCModel.createElementEqualsConstraints(returnTypeBindingCv, returnTypeCv);
        }
    }
    if (MethodChecks.isVirtual(methodBinding)) {
        //TODO: RippleMethod constraints for corner cases: see testCuRippleMethods3, bug 41989
        addConstraintsForOverriding(methodBinding, returnTypeCv, parameterTypeCvs);
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 9 with ConstraintVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 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;
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) TypeSetEnvironment(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSetEnvironment) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) HashSet(java.util.HashSet)

Example 10 with ConstraintVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2 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();
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Aggregations

ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)32 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)20 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)16 ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)11 CastExpression (org.eclipse.jdt.core.dom.CastExpression)9 Expression (org.eclipse.jdt.core.dom.Expression)9 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)9 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)8 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)8 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)8 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)7 GenericType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType)7 ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)7 TypeEquivalenceSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)7 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)5 ParameterizedType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType)5 ITypeConstraint2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)5 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)5 ParameterTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2)5 ReturnTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)5