Search in sources :

Example 66 with Expression

use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
	 */
@Override
public ITypeConstraint[] create(ClassInstanceCreation instanceCreation) {
    List<Expression> arguments = instanceCreation.arguments();
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
    IMethodBinding methodBinding = instanceCreation.resolveConstructorBinding();
    result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
    if (instanceCreation.getAnonymousClassDeclaration() == null) {
        ConstraintVariable constructorVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(instanceCreation, getContext());
        ConstraintVariable typeVar = fConstraintVariableFactory.makeRawBindingVariable(instanceCreation.resolveTypeBinding());
        result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(constructorVar, typeVar)));
    }
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Example 67 with Expression

use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
	 */
@Override
public ITypeConstraint[] create(SuperConstructorInvocation invocation) {
    List<Expression> arguments = invocation.arguments();
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
    IMethodBinding methodBinding = invocation.resolveConstructorBinding();
    result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Example 68 with Expression

use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.CastExpression)
	 */
@Override
public ITypeConstraint[] create(CastExpression castExpression) {
    Expression expression = castExpression.getExpression();
    Type type = castExpression.getType();
    ITypeConstraint[] definesConstraint = fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext()), fConstraintVariableFactory.makeTypeVariable(castExpression.getType()));
    if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) {
        ConstraintVariable expressionVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
        ConstraintVariable castExpressionVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext());
        ITypeConstraint[] c2 = createOrOrSubtypeConstraint(expressionVariable, castExpressionVariable);
        if (definesConstraint.length == 0) {
            return c2;
        } else {
            ITypeConstraint c1 = definesConstraint[0];
            Collection<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>();
            constraints.add(c1);
            constraints.addAll(Arrays.asList(c2));
            return constraints.toArray(new ITypeConstraint[constraints.size()]);
        }
    } else
        return definesConstraint;
}
Also used : Type(org.eclipse.jdt.core.dom.Type) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Example 69 with Expression

use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.

the class RemoveDeclarationCorrectionProposal method removeVariableReferences.

/**
	 * Remove the field or variable declaration including the initializer.
	 * @param rewrite the ast rewrite
	 * @param reference the reference
	 */
private void removeVariableReferences(ASTRewrite rewrite, SimpleName reference) {
    ASTNode parent = reference.getParent();
    while (parent instanceof QualifiedName) {
        parent = parent.getParent();
    }
    if (parent instanceof FieldAccess) {
        parent = parent.getParent();
    }
    int nameParentType = parent.getNodeType();
    if (nameParentType == ASTNode.ASSIGNMENT) {
        Assignment assignment = (Assignment) parent;
        Expression rightHand = assignment.getRightHandSide();
        ASTNode assignParent = assignment.getParent();
        if (assignParent.getNodeType() == ASTNode.EXPRESSION_STATEMENT && rightHand.getNodeType() != ASTNode.ASSIGNMENT) {
            removeVariableWithInitializer(rewrite, rightHand, assignParent);
        } else {
            rewrite.replace(assignment, rewrite.createCopyTarget(rightHand), null);
        }
    } else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
        rewrite.remove(parent, null);
    } else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
        VariableDeclarationFragment frag = (VariableDeclarationFragment) parent;
        ASTNode varDecl = frag.getParent();
        List<VariableDeclarationFragment> fragments;
        if (varDecl instanceof VariableDeclarationExpression) {
            fragments = ((VariableDeclarationExpression) varDecl).fragments();
        } else if (varDecl instanceof FieldDeclaration) {
            fragments = ((FieldDeclaration) varDecl).fragments();
        } else {
            fragments = ((VariableDeclarationStatement) varDecl).fragments();
        }
        if (fragments.size() == 1) {
            rewrite.remove(varDecl, null);
        } else {
            // don't try to preserve
            rewrite.remove(frag, null);
        }
    }
}
Also used : Assignment(org.eclipse.jdt.core.dom.Assignment) PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ASTNode(org.eclipse.jdt.core.dom.ASTNode) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 70 with Expression

use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.

the class InlineTempRefactoring method getInitializerSource.

private Expression getInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
    Expression copy = getModifiedInitializerSource(rewrite, reference);
    if (NecessaryParenthesesChecker.needsParentheses(copy, reference.getParent(), reference.getLocationInParent())) {
        ParenthesizedExpression parentExpr = rewrite.getAST().newParenthesizedExpression();
        parentExpr.setExpression(copy);
        return parentExpr;
    }
    return copy;
}
Also used : ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) 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)

Aggregations

Expression (org.eclipse.jdt.core.dom.Expression)552 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)263 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)213 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)187 CastExpression (org.eclipse.jdt.core.dom.CastExpression)185 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)135 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)126 ASTNode (org.eclipse.jdt.core.dom.ASTNode)125 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)122 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)121 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)112 AST (org.eclipse.jdt.core.dom.AST)101 PostfixExpression (org.eclipse.jdt.core.dom.PostfixExpression)95 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)88 SimpleName (org.eclipse.jdt.core.dom.SimpleName)83 InstanceofExpression (org.eclipse.jdt.core.dom.InstanceofExpression)76 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)73 Type (org.eclipse.jdt.core.dom.Type)70 ArrayList (java.util.ArrayList)69 Block (org.eclipse.jdt.core.dom.Block)63