Search in sources :

Example 1 with TypeVariable2

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;
}
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 2 with TypeVariable2

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);
    }
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) 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) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)

Example 3 with TypeVariable2

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?
}
Also used : ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) 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) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)

Example 4 with TypeVariable2

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!
}
Also used : 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) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) 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) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) 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) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Example 5 with TypeVariable2

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;
    }
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Name(org.eclipse.jdt.core.dom.Name)

Aggregations

ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)4 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)4 ParameterTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2)4 ParameterizedTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2)4 ReturnTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)4 TypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2)4 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)3 ArrayType (org.eclipse.jdt.core.dom.ArrayType)2 Type (org.eclipse.jdt.core.dom.Type)2 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 CastExpression (org.eclipse.jdt.core.dom.CastExpression)1 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)1 Expression (org.eclipse.jdt.core.dom.Expression)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)1 Name (org.eclipse.jdt.core.dom.Name)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)1