Example usage for org.eclipse.jdt.core.dom PostfixExpression getParent

List of usage examples for org.eclipse.jdt.core.dom PostfixExpression getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom PostfixExpression getParent.

Prototype

public final ASTNode getParent() 

Source Link

Document

Returns this node's parent node, or null if this is the root node.

Usage

From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java

License:Open Source License

public boolean visit(PostfixExpression node) {
    Expression left = node.getOperand();
    IVariableBinding varBinding = null;// w  ww  .j a  v  a 2 s .c o  m
    if (left instanceof Name) {
        Name leftName = (Name) left;
        IBinding nameBinding = leftName.resolveBinding();
        if (nameBinding instanceof IVariableBinding) {
            varBinding = (IVariableBinding) nameBinding;
        }
    } else if (left instanceof FieldAccess) {
        FieldAccess leftAccess = (FieldAccess) left;
        varBinding = leftAccess.resolveFieldBinding();
    }
    ITypeBinding typeBinding = left.resolveTypeBinding();
    ITypeBinding declaring = null;
    String qName = null;
    if (varBinding != null && (varBinding.getModifiers() & Modifier.STATIC) != 0
            && (declaring = varBinding.getDeclaringClass()) != null
            && !(qName = declaring.getQualifiedName()).startsWith("org.eclipse.swt.internal.xhtml.")
            && !qName.startsWith("net.sf.j2s.html.")) {
        boolean directStaticAccess = left instanceof SimpleName
                || (left instanceof QualifiedName
                        && ((QualifiedName) left).getQualifier() instanceof SimpleName)
                || (left instanceof FieldAccess
                        && ((FieldAccess) left).getExpression() instanceof ThisExpression);
        ASTNode parent = node.getParent();
        boolean staticCharType = typeBinding.isPrimitive() && "char".equals(typeBinding.getName());
        boolean needParenthesis = (supportsObjectStaticFields || !directStaticAccess
                || (typeBinding != null && staticCharType))
                && !(parent instanceof Statement || parent instanceof ParenthesizedExpression);
        if (needParenthesis) {
            buffer.append("(");
        }
        if (left instanceof QualifiedName) {
            QualifiedName leftName = (QualifiedName) left;
            if (!(leftName.getQualifier() instanceof SimpleName)) {
                leftName.getQualifier().accept(this);
                buffer.append(", ");
            }
        } else if (left instanceof FieldAccess) {
            FieldAccess leftAccess = (FieldAccess) left;
            if (!(leftAccess.getExpression() instanceof ThisExpression)) {
                leftAccess.getExpression().accept(this);
                buffer.append(", ");
            }
        }
        if ((supportsObjectStaticFields || staticCharType) && !(parent instanceof Statement)) {
            buffer.append("$t$ = ");
        }
        String op = node.getOperator().toString();
        if (staticCharType) {
            if (!(parent instanceof Statement)) {
                buffer.append(assureQualifiedName(
                        shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
                buffer.append('.');
                if (left instanceof QualifiedName) {
                    QualifiedName leftName = (QualifiedName) left;
                    leftName.getName().accept(this);
                } else if (left instanceof FieldAccess) {
                    FieldAccess leftAccess = (FieldAccess) left;
                    leftAccess.getName().accept(this);
                } else {
                    Name leftName = (Name) left;
                    leftName.accept(this);
                }
                buffer.append(", ");
            }
            buffer.append(assureQualifiedName(
                    shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
            buffer.append('.');
            if (left instanceof QualifiedName) {
                QualifiedName leftName = (QualifiedName) left;
                leftName.getName().accept(this);
            } else if (left instanceof FieldAccess) {
                FieldAccess leftAccess = (FieldAccess) left;
                leftAccess.getName().accept(this);
            } else {
                Name leftName = (Name) left;
                leftName.accept(this);
            }
            buffer.append(" = String.fromCharCode (");
            buffer.append(assureQualifiedName(
                    shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
            buffer.append('.');
            if (left instanceof QualifiedName) {
                QualifiedName leftName = (QualifiedName) left;
                leftName.getName().accept(this);
            } else if (left instanceof FieldAccess) {
                FieldAccess leftAccess = (FieldAccess) left;
                leftAccess.getName().accept(this);
            } else {
                Name leftName = (Name) left;
                leftName.accept(this);
            }
            if ("++".equals(op)) {
                buffer.append(".charCodeAt (0) + 1)");
            } else {
                buffer.append(".charCodeAt (0) - 1)");
            }
        } else {
            buffer.append(assureQualifiedName(
                    shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
            buffer.append('.');
            if (left instanceof QualifiedName) {
                QualifiedName leftName = (QualifiedName) left;
                leftName.getName().accept(this);
            } else if (left instanceof FieldAccess) {
                FieldAccess leftAccess = (FieldAccess) left;
                leftAccess.getName().accept(this);
            } else {
                Name leftName = (Name) left;
                leftName.accept(this);
            }
            //buffer.append(' ');
            buffer.append(op);
        }

        if (supportsObjectStaticFields) {
            buffer.append(", ");
            buffer.append(assureQualifiedName(
                    shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
            buffer.append(".prototype.");
            if (left instanceof QualifiedName) {
                QualifiedName leftName = (QualifiedName) left;
                leftName.getName().accept(this);
            } else if (left instanceof FieldAccess) {
                FieldAccess leftAccess = (FieldAccess) left;
                leftAccess.getName().accept(this);
            } else {
                Name leftName = (Name) left;
                leftName.accept(this);
            }
            buffer.append(" = ");
            buffer.append(assureQualifiedName(
                    shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName())));
            buffer.append('.');
            if (left instanceof QualifiedName) {
                QualifiedName leftName = (QualifiedName) left;
                leftName.getName().accept(this);
            } else if (left instanceof FieldAccess) {
                FieldAccess leftAccess = (FieldAccess) left;
                leftAccess.getName().accept(this);
            } else {
                Name leftName = (Name) left;
                leftName.accept(this);
            }
        }
        if ((supportsObjectStaticFields || staticCharType) && !(parent instanceof Statement)) {
            buffer.append(", $t$");
        }
        if (needParenthesis) {
            buffer.append(")");
        }
        return false;
    }
    if (typeBinding != null && typeBinding.isPrimitive()) {
        if ("char".equals(typeBinding.getName())) {
            ASTNode parent = node.getParent();
            if (!(parent instanceof Statement)) {
                if (!(parent instanceof ParenthesizedExpression)) {
                    buffer.append("(");
                }
                buffer.append("$c$ = ");
                left.accept(this);
                buffer.append(", ");
            }
            left.accept(this);
            buffer.append(" = String.fromCharCode (");
            left.accept(this);
            String op = node.getOperator().toString();
            if ("++".equals(op)) {
                buffer.append(".charCodeAt (0) + 1)");
            } else {
                buffer.append(".charCodeAt (0) - 1)");
            }
            if (!(parent instanceof Statement)) {
                buffer.append(", $c$");
                if (!(parent instanceof ParenthesizedExpression)) {
                    buffer.append(")");
                }
            }
            return false;
        }
    }
    boxingNode(left);
    return false;
    //return super.visit(node);
}

From source file:org.autorefactor.refactoring.ASTSemanticMatcher.java

License:Open Source License

@Override
public boolean match(final PostfixExpression node, final Object other) {
    if (node.getParent() instanceof Statement) {
        if (other instanceof Assignment) {
            return match0(node, (Assignment) other);
        } else if (other instanceof PrefixExpression) {
            return match0((PrefixExpression) other, node);
        }/*  w  ww . j a va2s . co m*/
    }

    return super.match(node, other);
}