Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.Expression


        node.getName().accept(this);
        _output("(");

        for (Iterator it = node.arguments().iterator(); it.hasNext();) {
            Expression e = (Expression) it.next();
            e.accept(this);

            if (it.hasNext()) {
                _output(", ");
            }
        }
View Full Code Here


        }

        _output("super(");

        for (Iterator it = node.arguments().iterator(); it.hasNext();) {
            Expression e = (Expression) it.next();
            e.accept(this);

            if (it.hasNext()) {
                _output(", ");
            }
        }
View Full Code Here

        node.getName().accept(this);
        _output("(");

        for (Iterator it = node.arguments().iterator(); it.hasNext();) {
            Expression e = (Expression) it.next();
            e.accept(this);

            if (it.hasNext()) {
                _output(", ");
            }
        }
View Full Code Here

     *
     *  @param node The assignment to be refactored.
     *  @param state The current state of the type analyzer.
     */
    public void handle(Assignment node, TypeAnalyzerState state) {
        Expression newExpression = _handleAlias(node.getRightHandSide(), state);

        if (newExpression == null) {
            _handleAssignment(node, state);
        }
    }
View Full Code Here

     */
    public void handle(ClassInstanceCreation node, TypeAnalyzerState state) {
        Iterator arguments = node.arguments().iterator();

        while (arguments.hasNext()) {
            Expression argument = (Expression) arguments.next();
            _handleAlias(argument, state);
        }
    }
View Full Code Here

     */
    public void handle(MethodInvocation node, TypeAnalyzerState state) {
        Iterator arguments = node.arguments().iterator();

        while (arguments.hasNext()) {
            Expression argument = (Expression) arguments.next();
            _handleAlias(argument, state);
        }
    }
View Full Code Here

            recordInvocation.arguments().add(arrayCreation);
        }

        // If there are indices, add them ("index0", "index1", ...) after the
        // field.
        Expression field = ast.newSimpleName(fieldName);

        if (indices > 0) {
            for (int i = 0; i < indices; i++) {
                ArrayAccess arrayAccess = ast.newArrayAccess();
                arrayAccess.setArray(field);
                arrayAccess.setIndex(ast.newSimpleName("index" + i));
                field = arrayAccess;
            }
        }

        // Set the field as the next argument.
        recordInvocation.arguments().add(field);

        // Get current timestamp from the checkpoint object.
        MethodInvocation timestampGetter = ast.newMethodInvocation();
        timestampGetter.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
        timestampGetter.setName(ast.newSimpleName("getTimestamp"));

        // Set the timestamp as the next argument.
        recordInvocation.arguments().add(timestampGetter);

        // The statement of the method call.
        ExpressionStatement recordStatement = ast
                .newExpressionStatement(recordInvocation);
        thenBranch.statements().add(recordStatement);

        ifStatement.setThenStatement(thenBranch);
        block.statements().add(ifStatement);

        // Finally, assign the new value to the field.
        Assignment assignment = ast.newAssignment();
        assignment
                .setLeftHandSide((Expression) ASTNode.copySubtree(ast, field));
        assignment.setRightHandSide(ast.newSimpleName("newValue"));
        assignment.setOperator(Assignment.Operator.ASSIGN);

        // Set the checkpoint object of the new value, if necessary.
        Class c;

        try {
            c = fieldType.toClass(state.getClassLoader());
        } catch (ClassNotFoundException e) {
            throw new ASTClassNotFoundException(fieldType.getName());
        }

        if (hasMethod(c, _getSetCheckpointMethodName(false),
                new Class[] { Checkpoint.class })
                || state.getCrossAnalyzedTypes().contains(c.getName())) {
            block.statements().add(_createSetCheckpointInvocation(ast));
        } else {
            addToLists(_fixSetCheckpoint, c.getName(), block);
        }

        // Return the result of the assignment.
        if (special && _assignOperators.containsKey(fieldType.getName())) {
            String[] operators = _assignOperators.get(fieldType.getName());

            SwitchStatement switchStatement = ast.newSwitchStatement();
            switchStatement.setExpression(ast.newSimpleName("operator"));

            boolean isPostfix = true;

            for (int i = 0; i < operators.length; i++) {
                String operator = operators[i];

                SwitchCase switchCase = ast.newSwitchCase();
                switchCase.setExpression(ast.newNumberLiteral(Integer
                        .toString(i)));
                switchStatement.statements().add(switchCase);

                ReturnStatement returnStatement = ast.newReturnStatement();

                if (operator.equals("=")) {
                    Assignment newAssignment = (Assignment) ASTNode
                            .copySubtree(ast, assignment);
                    returnStatement.setExpression(newAssignment);
                } else if (operator.equals("++") || operator.equals("--")) {
                    Expression expression;

                    if (isPostfix) {
                        PostfixExpression postfix = ast.newPostfixExpression();
                        postfix.setOperand((Expression) ASTNode.copySubtree(
                                ast, assignment.getLeftHandSide()));
View Full Code Here

            backup.arguments().add(arrayCreation);
        }

        //If there are indices, add them ("index0", "index1", ...) after the
        // field.
        Expression field = ast.newSimpleName(fieldName);

        if (indices > 0) {
            for (int i = 0; i < indices; i++) {
                ArrayAccess arrayAccess = ast.newArrayAccess();
                arrayAccess.setArray(field);
View Full Code Here

                                    .getName()))) {
                        body.statements().add(
                                ast.newExpressionStatement(restoreMethodCall));
                    }
                } else {
                    Expression rightHandSide;

                    if (fieldType.isPrimitive()) {
                        rightHandSide = restoreMethodCall;
                    } else {
                        CastExpression castExpression = ast.newCastExpression();
View Full Code Here

        String ownerName = owner.getName();
        Type type = Type.getType(node);
        String typeName = type.getName();

        Expression array = node;
        Type arrayType = type;

        // Check if we need to refactor the argument.
        boolean needRefactor = type.isArray();

        if (node instanceof ArrayAccess) {
            ArrayAccess arrayAccess = (ArrayAccess) node;

            while (arrayAccess.getArray() instanceof ArrayAccess) {
                arrayAccess = (ArrayAccess) arrayAccess.getArray();
                arrayType = arrayType.addOneDimension();
            }

            array = arrayAccess.getArray();
            arrayType = arrayType.addOneDimension();

            if (array instanceof MethodInvocation) {
                needRefactor = false;
            }
        }

        if (needRefactor) {
            // Refactor the expression.
            AST ast = node.getAST();
            //CompilationUnit root = (CompilationUnit) node.getRoot();
            //String typeClassName = getClassName(typeName, state, root);

            int nIndices = 0;

            Expression nodeIterator = node;

            while (nodeIterator instanceof ParenthesizedExpression) {
                nodeIterator = ((ParenthesizedExpression) nodeIterator)
                        .getExpression();
            }

            List indices = new LinkedList();

            while (nodeIterator instanceof ArrayAccess) {
                nIndices++;

                ArrayAccess arrayAccess = (ArrayAccess) nodeIterator;
                indices
                        .add(0, ASTNode
                                .copySubtree(ast, arrayAccess.getIndex()));
                nodeIterator = arrayAccess.getArray();

                while (nodeIterator instanceof ParenthesizedExpression) {
                    nodeIterator = ((ParenthesizedExpression) nodeIterator)
                            .getExpression();
                }
            }

            Expression newObject = null;
            SimpleName name;

            if (nodeIterator instanceof FieldAccess) {
                Expression object = ((FieldAccess) nodeIterator)
                        .getExpression();
                name = ((FieldAccess) nodeIterator).getName();
                newObject = (Expression) ASTNode.copySubtree(ast, object);
            } else if (nodeIterator instanceof QualifiedName) {
                Name object = ((QualifiedName) nodeIterator).getQualifier();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.