Search in sources :

Example 1 with TType

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

Example 2 with TType

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType 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;
}
Also used : ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) CastExpression(org.eclipse.jdt.core.dom.CastExpression)

Example 3 with TType

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType 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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnitRange(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.CompilationUnitRange) ArrayTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayTypeVariable2) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) TypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2) ParameterizedTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)

Example 4 with TType

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

Example 5 with TType

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType 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

TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)41 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)8 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)8 ArrayType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ArrayType)6 GenericType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType)5 TypeVariable (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable)5 ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)4 CastExpression (org.eclipse.jdt.core.dom.CastExpression)3 Expression (org.eclipse.jdt.core.dom.Expression)3 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)3 ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)3 ParameterTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2)3 ReturnTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)3 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)2 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)2 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)2 ParameterizedType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType)2 ArrayTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayTypeVariable2)2 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)2