/* * @see ASTVisitor#visit(ArrayAccess) */ public boolean visit(ArrayAccess node) { node.getArray().accept(this); this.fBuffer.append("["); // $NON-NLS-1$ node.getIndex().accept(this); this.fBuffer.append("]"); // $NON-NLS-1$ return false; }
/* (non-Javadoc) * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayAccess) */ public boolean visit(ArrayAccess node) { PTArrayAccess aa = InstantiationFactory.eINSTANCE.createPTArrayAccess(); List indexes = aa.getIndexes(); Expression arrayExp = node; while (arrayExp.getNodeType() == ASTNode.ARRAY_ACCESS) { // Visit the index to get the index expression. ArrayAccess array = (ArrayAccess) arrayExp; indexes.add( 0, perform( array .getIndex())); // We're trying to create the final expression from inside out, the // indexes are created in reverse order. arrayExp = array.getArray(); } aa.setArray(perform(arrayExp)); // Final arrayExp is the true expression. expression = aa; // Set the return expression for this visit. return false; }
private void collectSideEffects(Expression expr, List<Expression> sideEffectExprs) { // local variable, parameter, enum constant, etc. // OR method starting with is*(), get*() // except atomic long, atomic integer, etc. switch (expr.getNodeType()) { case METHOD_INVOCATION: MethodInvocation mi = (MethodInvocation) expr; methodHasSideEffects(mi.resolveMethodBinding(), mi, sideEffectExprs); collectSideEffects(mi.getExpression(), sideEffectExprs); collectSideEffects(arguments(mi), sideEffectExprs); break; case SUPER_METHOD_INVOCATION: SuperMethodInvocation smi = (SuperMethodInvocation) expr; methodHasSideEffects(smi.resolveMethodBinding(), smi, sideEffectExprs); collectSideEffects(arguments(smi), sideEffectExprs); break; case CLASS_INSTANCE_CREATION: ClassInstanceCreation cic = (ClassInstanceCreation) expr; methodHasSideEffects(cic.resolveConstructorBinding(), cic, sideEffectExprs); collectSideEffects(cic.getExpression(), sideEffectExprs); collectSideEffects(arguments(cic), sideEffectExprs); break; case ARRAY_ACCESS: ArrayAccess aa = (ArrayAccess) expr; collectSideEffects(aa.getArray(), sideEffectExprs); collectSideEffects(aa.getIndex(), sideEffectExprs); break; case ARRAY_CREATION: ArrayCreation ac = (ArrayCreation) expr; collectSideEffects(ac.getInitializer(), sideEffectExprs); collectSideEffects(ac.dimensions(), sideEffectExprs); break; case ARRAY_INITIALIZER: ArrayInitializer ai = (ArrayInitializer) expr; collectSideEffects(expressions(ai), sideEffectExprs); break; case ASSIGNMENT: Assignment as = (Assignment) expr; collectSideEffects(as.getLeftHandSide(), sideEffectExprs); collectSideEffects(as.getRightHandSide(), sideEffectExprs); break; case CONDITIONAL_EXPRESSION: ConditionalExpression ce = (ConditionalExpression) expr; collectSideEffects(ce.getExpression(), sideEffectExprs); collectSideEffects(ce.getThenExpression(), sideEffectExprs); collectSideEffects(ce.getElseExpression(), sideEffectExprs); break; case FIELD_ACCESS: FieldAccess fa = (FieldAccess) expr; collectSideEffects(fa.getExpression(), sideEffectExprs); collectSideEffects(fa.getName(), sideEffectExprs); break; case SUPER_FIELD_ACCESS: SuperFieldAccess sfa = (SuperFieldAccess) expr; collectSideEffects(sfa.getQualifier(), sideEffectExprs); collectSideEffects(sfa.getName(), sideEffectExprs); break; case THIS_EXPRESSION: collectSideEffects(((ThisExpression) expr).getQualifier(), sideEffectExprs); break; case VARIABLE_DECLARATION_EXPRESSION: collectSideEffects((VariableDeclarationExpression) expr, sideEffectExprs); break; case INFIX_EXPRESSION: InfixExpression ie = (InfixExpression) expr; collectSideEffects(ie.getLeftOperand(), sideEffectExprs); collectSideEffects(ie.getRightOperand(), sideEffectExprs); collectSideEffects(extendedOperands(ie), sideEffectExprs); break; case CAST_EXPRESSION: collectSideEffects(((CastExpression) expr).getExpression(), sideEffectExprs); break; case INSTANCEOF_EXPRESSION: collectSideEffects(((InstanceofExpression) expr).getLeftOperand(), sideEffectExprs); break; case PARENTHESIZED_EXPRESSION: collectSideEffects(((ParenthesizedExpression) expr).getExpression(), sideEffectExprs); break; case POSTFIX_EXPRESSION: sideEffectExprs.add(expr); break; case PREFIX_EXPRESSION: PrefixExpression pe = (PrefixExpression) expr; PrefixExpression.Operator op = pe.getOperator(); if (PrefixExpression.Operator.INCREMENT.equals(op) | PrefixExpression.Operator.DECREMENT.equals(op)) { sideEffectExprs.add(pe); } else { collectSideEffects(pe.getOperand(), sideEffectExprs); } break; default: // literals // names } }