下面列出了怎么用org.eclipse.jdt.core.dom.ParenthesizedExpression的API类实例代码及写法,或者点击链接到github查看源代码。
private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression originalNode, boolean removeParentheses, Operator operator) {
if (existing == null && removeParentheses) {
while (originalNode instanceof ParenthesizedExpression) {
originalNode = ((ParenthesizedExpression) originalNode).getExpression();
}
}
Expression newRight = (Expression) rewrite.createMoveTarget(originalNode);
if (originalNode instanceof InfixExpression) {
((InfixExpression) newRight).setOperator(((InfixExpression) originalNode).getOperator());
}
if (existing == null) {
return newRight;
}
AST ast = rewrite.getAST();
InfixExpression infix = ast.newInfixExpression();
infix.setOperator(operator);
infix.setLeftOperand(existing);
infix.setRightOperand(newRight);
return infix;
}
/**
* Creates the new <CODE>InfixExpression</CODE> <CODE>(x & 1) == 1</CODE>.
*/
@Override
protected InfixExpression createCorrectOddnessCheck(ASTRewrite rewrite, Expression numberExpression) {
Assert.isNotNull(rewrite);
Assert.isNotNull(numberExpression);
final AST ast = rewrite.getAST();
InfixExpression andOddnessCheck = ast.newInfixExpression();
ParenthesizedExpression parenthesizedExpression = ast.newParenthesizedExpression();
InfixExpression andExpression = ast.newInfixExpression();
andExpression.setLeftOperand((Expression) rewrite.createMoveTarget(numberExpression));
andExpression.setOperator(AND);
andExpression.setRightOperand(ast.newNumberLiteral("1"));
parenthesizedExpression.setExpression(andExpression);
andOddnessCheck.setLeftOperand(parenthesizedExpression);
andOddnessCheck.setOperator(EQUALS);
andOddnessCheck.setRightOperand(ast.newNumberLiteral("1"));
return andOddnessCheck;
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent= selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
else
return null;
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
public static IBinding resolveBinding(Expression expression){
if (expression instanceof Name)
return ((Name)expression).resolveBinding();
if (expression instanceof ParenthesizedExpression)
return resolveBinding(((ParenthesizedExpression)expression).getExpression());
else if (expression instanceof Assignment)
return resolveBinding(((Assignment)expression).getLeftHandSide());//TODO ???
else if (expression instanceof MethodInvocation)
return ((MethodInvocation)expression).resolveMethodBinding();
else if (expression instanceof SuperMethodInvocation)
return ((SuperMethodInvocation)expression).resolveMethodBinding();
else if (expression instanceof FieldAccess)
return ((FieldAccess)expression).resolveFieldBinding();
else if (expression instanceof SuperFieldAccess)
return ((SuperFieldAccess)expression).resolveFieldBinding();
else if (expression instanceof ConditionalExpression)
return resolveBinding(((ConditionalExpression)expression).getThenExpression());
return null;
}
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
ASTNode groupNode= getGroupRoot();
List<Expression> allOperands= findGroupMembersInOrderFor(getGroupRoot());
if (allOperands.size() == fOperands.size()) {
if (replacement instanceof Name && groupNode.getParent() instanceof ParenthesizedExpression) {
// replace including the parenthesized expression around it
rewrite.replace(groupNode.getParent(), replacement, textEditGroup);
} else {
rewrite.replace(groupNode, replacement, textEditGroup);
}
return;
}
rewrite.replace(fOperands.get(0), replacement, textEditGroup);
int first= allOperands.indexOf(fOperands.get(0));
int after= first + fOperands.size();
for (int i= first + 1; i < after; i++) {
rewrite.remove(allOperands.get(i), textEditGroup);
}
}
protected boolean isTypeHolder(Object o) {
if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)
|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
|| o.getClass().equals(ArrayCreation.class)
|| o.getClass().equals(ClassInstanceCreation.class)
|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
return true;
return false;
}
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
TextEditGroup group= createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite);
ASTRewrite rewrite= cuRewrite.getASTRewrite();
CastExpression cast= fCast;
Expression expression= cast.getExpression();
if (expression instanceof ParenthesizedExpression) {
Expression childExpression= ((ParenthesizedExpression) expression).getExpression();
if (NecessaryParenthesesChecker.needsParentheses(childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
expression= childExpression;
}
}
replaceCast(cast, expression, rewrite, group);
}
public static UnusedCodeFix createRemoveUnusedCastFix(CompilationUnit compilationUnit, IProblemLocation problem) {
if (problem.getProblemId() != IProblem.UnnecessaryCast)
return null;
ASTNode selectedNode= problem.getCoveringNode(compilationUnit);
ASTNode curr= selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr= ((ParenthesizedExpression) curr).getExpression();
}
if (!(curr instanceof CastExpression))
return null;
return new UnusedCodeFix(FixMessages.UnusedCodeFix_RemoveCast_description, compilationUnit, new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression)curr)});
}
private static void replaceCast(CastExpression castExpression, Expression replacement, ASTRewrite rewrite, TextEditGroup group) {
boolean castEnclosedInNecessaryParentheses= castExpression.getParent() instanceof ParenthesizedExpression
&& NecessaryParenthesesChecker.needsParentheses(castExpression, castExpression.getParent().getParent(), castExpression.getParent().getLocationInParent());
ASTNode toReplace= castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
ASTNode move;
if (NecessaryParenthesesChecker.needsParentheses(replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
if (replacement.getParent() instanceof ParenthesizedExpression) {
move= rewrite.createMoveTarget(replacement.getParent());
} else if (castEnclosedInNecessaryParentheses) {
toReplace= castExpression;
move= rewrite.createMoveTarget(replacement);
} else {
ParenthesizedExpression parentheses= replacement.getAST().newParenthesizedExpression();
parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
move= parentheses;
}
} else {
move= rewrite.createMoveTarget(replacement);
}
rewrite.replace(toReplace, move, group);
}
/**
* {@inheritDoc}
*/
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
TextEditGroup group= createTextEditGroup(FixMessages.ExpressionsFix_addParanoiacParentheses_description, cuRewrite);
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
for (int i= 0; i < fExpressions.length; i++) {
// add parenthesis around expression
Expression expression= fExpressions[i];
ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression();
parenthesizedExpression.setExpression((Expression) rewrite.createCopyTarget(expression));
rewrite.replace(expression, parenthesizedExpression, group);
}
}
private static boolean getRemoveExtraParenthesesProposals(IInvocationContext context, ASTNode covering, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
ArrayList<ASTNode> nodes;
if (context.getSelectionLength() == 0 && covering instanceof ParenthesizedExpression) {
nodes= new ArrayList<ASTNode>();
nodes.add(covering);
} else {
nodes= coveredNodes;
}
if (nodes.isEmpty())
return false;
IProposableFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), nodes.toArray(new ASTNode[nodes.size()]));
if (fix == null)
return false;
if (resultingCollections == null)
return true;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE);
Map<String, String> options= new Hashtable<String, String>();
options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE);
options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE);
FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.REMOVE_EXTRA_PARENTHESES, image, context);
resultingCollections.add(proposal);
return true;
}
private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression originalNode, boolean removeParentheses, Operator operator) {
if (existing == null && removeParentheses) {
while (originalNode instanceof ParenthesizedExpression) {
originalNode= ((ParenthesizedExpression)originalNode).getExpression();
}
}
Expression newRight= (Expression)rewrite.createMoveTarget(originalNode);
if (originalNode instanceof InfixExpression) {
((InfixExpression)newRight).setOperator(((InfixExpression)originalNode).getOperator());
}
if (existing == null) {
return newRight;
}
AST ast= rewrite.getAST();
InfixExpression infix= ast.newInfixExpression();
infix.setOperator(operator);
infix.setLeftOperand(existing);
infix.setRightOperand(newRight);
return infix;
}
public ParenthesizedExpression wrap(Expression e) {
ParenthesizedExpression p = ast.newParenthesizedExpression();
p.setExpression(e);
Object o = e.getProperty(TYPEBIND_PROP);
if(o != null) p.setProperty(TYPEBIND_PROP, o);
return p;
}
public Expression trimWrap(Expression expr) {
Expression e = expr;
while(e instanceof ParenthesizedExpression) {
e = ((ParenthesizedExpression)e).getExpression();
}
return e;
}
private ParenthesiszedExpr visit(ParenthesizedExpression node) {
int startLine = _cunit.getLineNumber(node.getStartPosition());
int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
ParenthesiszedExpr parenthesiszedExpr = new ParenthesiszedExpr(startLine, endLine, node);
Expr expression = (Expr) process(node.getExpression());
expression.setParent(parenthesiszedExpr);
parenthesiszedExpr.setExpr(expression);
parenthesiszedExpr.setType(expression.getType());
return parenthesiszedExpr;
}
private boolean isExpressionStatementWithConditionalExpression(PDGNode node) {
Statement statement = node.getASTStatement();
if(statement instanceof ExpressionStatement) {
ExpressionExtractor expressionExtractor = new ExpressionExtractor();
List<Expression> conditionalExpressions = expressionExtractor.getConditionalExpressions(statement);
if(conditionalExpressions.size() == 1) {
ConditionalExpression conditional = (ConditionalExpression)conditionalExpressions.get(0);
ASTNode parent = conditional.getParent();
ASTNode grandParent = parent.getParent();
if(grandParent != null && grandParent.equals(statement)) {
return true;
}
if(parent instanceof ParenthesizedExpression) {
if(grandParent != null) {
if(grandParent.getParent() != null && grandParent.getParent().equals(statement)) {
return true;
}
}
}
}
}
else if (statement instanceof ReturnStatement) {
ReturnStatement returnStatement = (ReturnStatement)statement;
if (returnStatement.getExpression() instanceof ConditionalExpression) {
return true;
}
}
return false;
}
@Override
public Expression createCopyTarget(ASTRewrite rewrite, boolean removeSurroundingParenthesis) {
Expression node = getAssociatedExpression();
if (removeSurroundingParenthesis && node instanceof ParenthesizedExpression) {
node = ((ParenthesizedExpression) node).getExpression();
}
return (Expression) rewrite.createCopyTarget(node);
}
@Override
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
if (replacement instanceof Name && fNode.getParent() instanceof ParenthesizedExpression) {
// replace including the parenthesized expression around it
rewrite.replace(fNode.getParent(), replacement, textEditGroup);
} else {
rewrite.replace(fNode, replacement, textEditGroup);
}
}
@Override
public void endVisit(ParenthesizedExpression node) {
if (skipNode(node)) {
return;
}
assignFlowInfo(node, node.getExpression());
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent = selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
} else {
return null;
}
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
}
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
}
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent = selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
} else {
return null;
}
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
}
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
}
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
int numberOf = getNumberOfDuplicates();
if (numberOf == 0 || !fReplaceDuplicates) {
return;
}
String label = null;
if (numberOf == 1) {
label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single, BasicElementLabels.getJavaElementName(fMethodName));
} else {
label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi, BasicElementLabels.getJavaElementName(fMethodName));
}
TextEditGroup description = new TextEditGroup(label);
result.addTextEditGroup(description);
for (Match duplicate : fDuplicates) {
if (!duplicate.isInvalidNode()) {
if (isDestinationReachable(duplicate.getEnclosingMethod())) {
ASTNode[] callNodes = createCallNodes(duplicate, modifiers);
ASTNode[] duplicateNodes = duplicate.getNodes();
for (int i = 0; i < duplicateNodes.length; i++) {
ASTNode parent = duplicateNodes[i].getParent();
if (parent instanceof ParenthesizedExpression) {
duplicateNodes[i] = parent;
}
}
new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
}
}
}
}
private IBinding resolveBinding(Expression expression) {
if (expression instanceof SimpleName) {
return ((SimpleName) expression).resolveBinding();
} else if (expression instanceof QualifiedName) {
return ((QualifiedName) expression).resolveBinding();
} else if (expression instanceof FieldAccess) {
return ((FieldAccess) expression).getName().resolveBinding();
} else if (expression instanceof ParenthesizedExpression) {
return resolveBinding(((ParenthesizedExpression) expression).getExpression());
}
return null;
}
private Expression getReceiver(Expression expression) {
int type = expression.getNodeType();
switch (type) {
case ASTNode.SIMPLE_NAME:
return null;
case ASTNode.QUALIFIED_NAME:
return ((QualifiedName) expression).getQualifier();
case ASTNode.FIELD_ACCESS:
return ((FieldAccess) expression).getExpression();
case ASTNode.PARENTHESIZED_EXPRESSION:
return getReceiver(((ParenthesizedExpression) expression).getExpression());
}
return null;
}
private static Expression getInversedNotExpression(ASTRewrite rewrite, Expression expression, AST ast) {
PrefixExpression prefixExpression = ast.newPrefixExpression();
prefixExpression.setOperator(PrefixExpression.Operator.NOT);
ParenthesizedExpression parenthesizedExpression = getParenthesizedExpression(ast, (Expression) rewrite.createCopyTarget(expression));
prefixExpression.setOperand(parenthesizedExpression);
return prefixExpression;
}
public static Expression unparenthesize(Expression expression)
{
if (expression instanceof ParenthesizedExpression)
{
ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression)expression;
Expression innerExpression = parenthesizedExpression.getExpression();
return unparenthesize(innerExpression);
}
return expression;
}
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
AST ast= rewrite.getAST();
ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);
if (fCastType != null) {
return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
}
ASTNode node= fNodeToCast;
ASTNode parent= node.getParent();
if (parent instanceof CastExpression) {
node= parent;
parent= parent.getParent();
}
while (parent instanceof ParenthesizedExpression) {
node= parent;
parent= parent.getParent();
}
if (parent instanceof MethodInvocation) {
MethodInvocation invocation= (MethodInvocation) node.getParent();
if (invocation.getExpression() == node) {
IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
if (bindings.length > 0) {
ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());
Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
return newTypeNode;
}
}
}
Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
return newCastType;
}
private Expression createLeftOperand(ASTRewrite rewrite, Expression leftOperand) {
Expression leftExp = (Expression) rewrite.createMoveTarget(leftOperand);
if (leftOperand instanceof Name || leftOperand instanceof ParenthesizedExpression) {
return leftExp;
}
final AST ast = rewrite.getAST();
ParenthesizedExpression parExp = ast.newParenthesizedExpression();
parExp.setExpression(leftExp);
return parExp;
}
protected static boolean isRemainderExp(Expression remainderExp) {
while (remainderExp instanceof ParenthesizedExpression) {
remainderExp = ((ParenthesizedExpression) remainderExp).getExpression();
}
if (remainderExp instanceof InfixExpression) {
InfixExpression exp = ((InfixExpression) remainderExp);
return REMAINDER.equals(exp.getOperator()) && isNumber(exp.getRightOperand(), 2);
}
return false;
}