List of usage examples for org.eclipse.jdt.core.dom ParenthesizedExpression getParent
public final ASTNode getParent()
null if this is the root node. From source file:org.autorefactor.refactoring.rules.SimplifyExpressionRefactoring.java
License:Open Source License
private Expression getExpressionWithoutParentheses(ParenthesizedExpression node) { final ASTNode parent = node.getParent(); final Expression innerExpr = node.getExpression(); if (innerExpr instanceof ParenthesizedExpression) { return getExpressionWithoutParentheses((ParenthesizedExpression) innerExpr); }//from ww w.j ava 2 s . c om if (parent instanceof InfixExpression) { final InfixExpression parentInfixExpr = (InfixExpression) parent; if (innerExpr instanceof InfixExpression) { final Operator innerOp = ((InfixExpression) innerExpr).getOperator(); if (innerOp == parentInfixExpr.getOperator() && OperatorEnum.isAssociative(innerOp) // Leave String concatenations with mixed type // to other if statements in this method. && equalNotNull(innerExpr.resolveTypeBinding(), parentInfixExpr.resolveTypeBinding())) { return innerExpr; } } } if (isHardToRead(innerExpr, parent)) { return node; } if (isUselessParenthesesInStatement(parent, node)) { return innerExpr; } final int compareTo = OperatorEnum.compareTo(innerExpr, parent); if (compareTo < 0) { return node; } else if (compareTo > 0) { return innerExpr; } if ( // TODO JNR can we revert the condition in the InfixExpression? // parentheses are sometimes needed to explicit code, // some like it like that innerExpr instanceof InfixExpression // TODO JNR add additional code to check if the cast is really required // or if it can be removed. || innerExpr instanceof CastExpression) { return node; } return innerExpr; }