.hasNext();) {
final Expression dimension = (Expression) it.next();
// if coming up from the index.
if (containedIn(dimension, this.name)) {
legal = false;
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_IllegalNodeContext, node);
}
}
if (legal)
this.process(node.getParent());
break;
}
case ASTNode.ARRAY_ACCESS: {
final ArrayAccess access = (ArrayAccess) node;
// if coming up from the index.
if (containedIn(access.getIndex(), this.name))
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_IllegalNodeContext, node);
else
this.process(node.getParent());
break;
}
case ASTNode.ASSIGNMENT: {
final Assignment assignment = (Assignment) node;
if (assignment.getOperator() == Assignment.Operator.ASSIGN) {
this.processExpression(assignment.getLeftHandSide());
this.processExpression(assignment.getRightHandSide());
}
else if (!Util.isSuspiciousAssignmentOperator(assignment
.getOperator()))
throw new DefinitelyNotEnumerizableOperationException(
Messages.ASTNodeProcessor_IllegalAssignmentExpression, assignment
.getOperator(), node);
else
throw new NonEnumerizableASTException(
Messages.ASTNodeProcessor_IllegalAssignmentExpression, node);
break;
}
case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
final VariableDeclarationStatement vds = (VariableDeclarationStatement) node;
for (final Iterator it = vds.fragments().iterator(); it.hasNext();) {
final VariableDeclarationFragment vdf = (VariableDeclarationFragment) it
.next();
final IJavaElement elem = vdf.resolveBinding().getJavaElement();
if (elem.isReadOnly() || vdf.getName().resolveBoxing())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, vdf);
if (vdf.resolveBinding().getType().isEqualTo(
node.getAST().resolveWellKnownType("java.lang.Object"))) //$NON-NLS-1$
throw new NonEnumerizableASTException(
Messages.ASTNodeProcessor_IllegalArrayUpcast, vdf);
this.found.add(elem);
this.processExpression(vdf.getInitializer());
}
break;
}
case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
final VariableDeclarationFragment vdf = (VariableDeclarationFragment) node;
final IJavaElement elem = vdf.resolveBinding().getJavaElement();
if (!this.constFields.contains(elem)) {
if (elem == null || vdf == null || vdf.getName() == null)
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
if (elem.isReadOnly() || vdf.getName().resolveBoxing())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
if (vdf.resolveBinding().getType().isEqualTo(
node.getAST().resolveWellKnownType("java.lang.Object"))) //$NON-NLS-1$
throw new NonEnumerizableASTException(
Messages.ASTNodeProcessor_IllegalArrayUpcast, vdf);
this.found.add(elem);
this.processExpression(vdf.getInitializer());
}
break;
}
case ASTNode.FIELD_DECLARATION: {
final FieldDeclaration fd = (FieldDeclaration) node;
for (final Iterator it = fd.fragments().iterator(); it.hasNext();) {
final VariableDeclarationFragment vdf = (VariableDeclarationFragment) it
.next();
final IJavaElement elem = vdf.resolveBinding().getJavaElement();
if (!this.constFields.contains(elem)) {
if (elem.isReadOnly() || vdf.getName().resolveBoxing())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, vdf);
if (vdf.resolveBinding().getType().isEqualTo(
node.getAST().resolveWellKnownType(
"java.lang.Object"))) //$NON-NLS-1$
throw new NonEnumerizableASTException(
Messages.ASTNodeProcessor_IllegalArrayUpcast, vdf);
this.found.add(elem);
this.processExpression(vdf.getInitializer());
}
}
break;
}
case ASTNode.INFIX_EXPRESSION: {
final InfixExpression iexp = (InfixExpression) node;
final InfixExpression.Operator op = iexp.getOperator();
if (Util.isLegalInfixOperator(op)) {
if (Util.inNeedOfTransformation(op)) {
final ISourceRange range = new SourceRange(iexp
.getStartPosition(), iexp.getLength());
this.legalEncounteredInfixExpressionSourceLocations
.add(range);
}
this.processExpression(iexp.getLeftOperand());
this.processExpression(iexp.getRightOperand());
}
else if (!Util.isSuspiciousInfixOperator(op))
throw new DefinitelyNotEnumerizableOperationException(
Messages.ASTNodeProcessor_IllegalInfixExpression, op, node);
else
throw new NonEnumerizableOperationException(
Messages.ASTNodeProcessor_IllegalInfixExpression, op, node);
break;
}
case ASTNode.SWITCH_STATEMENT: {
final SwitchStatement sw = (SwitchStatement) node;
this.processExpression(sw.getExpression());
for (final Iterator it = sw.statements().iterator(); it.hasNext();) {
final Object obj = it.next();
if (obj instanceof SwitchCase) {
final SwitchCase sc = (SwitchCase) obj;
this.processExpression(sc.getExpression());
}
}
break;
}
case ASTNode.SWITCH_CASE: {
final SwitchCase sc = (SwitchCase) node;
this.processExpression(sc.getExpression());
this.process(sc.getParent());
break;
}
case ASTNode.RETURN_STATEMENT: {
final ReturnStatement rs = (ReturnStatement) node;
// process what is being returned.
this.processExpression(rs.getExpression());
// Get the corresponding method declaration.
final MethodDeclaration methDecl = Util.getMethodDeclaration(rs);
// Get the corresponding method.
final IMethod meth = (IMethod) methDecl.resolveBinding()
.getJavaElement();
// Get the top most method
final IMethod top = Util.getTopMostSourceMethod(meth, this.monitor);
if (top == null)
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else {
// Find the topmost method.
if (top.isReadOnly())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
this.found.add(top);
}
break;
}
case ASTNode.CONDITIONAL_EXPRESSION: {
final ConditionalExpression ce = (ConditionalExpression) node;
this.processExpression(ce);
break;
}
case ASTNode.METHOD_DECLARATION: {
final ASTVisitor visitor = new ASTVisitor() {
public boolean visit(ReturnStatement node) {
try {
ASTNodeProcessor.this.processExpression(node
.getExpression());
} catch (JavaModelException E) {
throw new RuntimeException(E);
}
return true;
}
};
node.accept(visitor);
break;
}
case ASTNode.CLASS_INSTANCE_CREATION: {
final ClassInstanceCreation ctorCall = (ClassInstanceCreation) node;
// if coming up from a argument.
if (containedIn(ctorCall.arguments(), this.name))
// if we don't have the source, no can do.
if (!ctorCall.getType().resolveBinding().isFromSource())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else
// go find the formals.
this.findFormalsForVariable(ctorCall);
break;
}
case ASTNode.CONSTRUCTOR_INVOCATION: {
final ConstructorInvocation ctorCall = (ConstructorInvocation) node;
// if coming up from a argument.
if (containedIn(ctorCall.arguments(), this.name))
// if we don't have the source, no can do.
if (!ctorCall.resolveConstructorBinding().getDeclaringClass()
.isFromSource())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else
// go find the formals.
this.findFormalsForVariable(ctorCall);
break;
}
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: {
final SuperConstructorInvocation ctorCall = (SuperConstructorInvocation) node;
// if coming up from a argument.
if (containedIn(ctorCall.arguments(), this.name))
// if we don't have the source, no can do.
if (!ctorCall.resolveConstructorBinding().getDeclaringClass()
.isFromSource())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else
// go find the formals.
this.findFormalsForVariable(ctorCall);
break;
}
case ASTNode.SUPER_METHOD_INVOCATION: {
final SuperMethodInvocation smi = (SuperMethodInvocation) node;
// if coming up from a argument.
if (containedIn(smi.arguments(), this.name))
// if we don't have the source, no can do.
if (!smi.resolveMethodBinding().getDeclaringClass()
.isFromSource())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else
// go find the formals.
this.findFormalsForVariable(smi);
break;
}
case ASTNode.METHOD_INVOCATION: {
final MethodInvocation mi = (MethodInvocation) node;
// if coming up from a argument.
if (containedIn(mi.arguments(), this.name)) {
// if we don't have the source, no can do.
if (!mi.resolveMethodBinding().getDeclaringClass()
.isFromSource())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
else
// go find the formals.
this.findFormalsForVariable(mi);
} else
this.process(node.getParent());
break;
}
case ASTNode.PARENTHESIZED_EXPRESSION: {
this.process(node.getParent());
break;
}
case ASTNode.SINGLE_VARIABLE_DECLARATION: {
// its a formal parameter.
final SingleVariableDeclaration svd = (SingleVariableDeclaration) node;
// take care of local usage.
final IJavaElement elem = svd.resolveBinding().getJavaElement();
if (elem.isReadOnly() || svd.getName().resolveBoxing())
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_SourceNotPresent, node);
if (svd.resolveBinding().getType().isEqualTo(
node.getAST().resolveWellKnownType("java.lang.Object"))) //$NON-NLS-1$
throw new NonEnumerizableASTException(Messages.ASTNodeProcessor_IllegalArrayUpcast,
svd);
this.found.add(elem);
// take care of remote usage.
// go find variables on the corresponding calls.
this.findVariablesForFormal(svd);
break;
}
case ASTNode.EXPRESSION_STATEMENT: {
// dead expression, it's valid just goes no where.
break;
}
case ASTNode.CAST_EXPRESSION: {
final CastExpression cast = (CastExpression) node;
throw new NonEnumerizableCastExpression(Messages.ASTNodeProcessor_IllegalNodeContext,
node, cast.getExpression().resolveTypeBinding(), cast
.getType().resolveBinding());
}
case ASTNode.ENUM_CONSTANT_DECLARATION:
case ASTNode.IF_STATEMENT:
case ASTNode.BOOLEAN_LITERAL:
case ASTNode.NUMBER_LITERAL:
case ASTNode.CHARACTER_LITERAL:
case ASTNode.POSTFIX_EXPRESSION:
case ASTNode.PREFIX_EXPRESSION: {
throw new DefinitelyNotEnumerizableException(
Messages.ASTNodeProcessor_IllegalNodeContext, node);
}
default: {
throw new NonEnumerizableASTException(Messages.ASTNodeProcessor_IllegalNodeContext, node);