Prefer to cast Iterables instead of the things they can iterate over
This commit is contained in:
parent
544a71ae72
commit
66e2e76205
|
@ -253,8 +253,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
|
||||
List<CAstEntity> declEntities = new ArrayList<>();
|
||||
|
||||
for (Iterator<CAstEntity> iter = cu.types().iterator(); iter.hasNext();) {
|
||||
AbstractTypeDeclaration decl = (AbstractTypeDeclaration) iter.next();
|
||||
for (AbstractTypeDeclaration decl : (Iterable<AbstractTypeDeclaration>) cu.types()) {
|
||||
// can be of type AnnotationTypeDeclaration, EnumDeclaration, TypeDeclaration
|
||||
declEntities.add(visit(decl, new RootContext()));
|
||||
}
|
||||
|
@ -440,8 +439,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
} else if (decl instanceof FieldDeclaration) {
|
||||
FieldDeclaration fd = (FieldDeclaration) decl;
|
||||
|
||||
for (Object f : fd.fragments()) {
|
||||
VariableDeclarationFragment frag = (VariableDeclarationFragment) f;
|
||||
for (VariableDeclarationFragment frag : (Iterable<VariableDeclarationFragment>) fd.fragments()) {
|
||||
if (frag.getInitializer() != null) {
|
||||
boolean isStatic = ((fd.getModifiers() & Modifier.STATIC) != 0);
|
||||
(isStatic ? staticInits : inits).add(frag);
|
||||
|
@ -462,8 +460,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
if (decl instanceof FieldDeclaration) {
|
||||
FieldDeclaration fieldDecl = (FieldDeclaration) decl;
|
||||
Collection<CAstQualifier> quals = JDT2CAstUtils.mapModifiersToQualifiers(fieldDecl.getModifiers(), false, false);
|
||||
for (Object f : fieldDecl.fragments()) {
|
||||
VariableDeclarationFragment fieldFrag = (VariableDeclarationFragment) f;
|
||||
for (VariableDeclarationFragment fieldFrag : (Iterable<VariableDeclarationFragment>) fieldDecl.fragments()) {
|
||||
IVariableBinding fieldBinding = fieldFrag.resolveBinding();
|
||||
memberEntities.add(new FieldEntity(fieldFrag.getName().getIdentifier(), fieldBinding.getType(), quals,
|
||||
makePosition(fieldFrag.getStartPosition(), fieldFrag.getStartPosition() + fieldFrag.getLength()),
|
||||
|
@ -750,8 +747,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
|
||||
ArrayList<CAstNode> arguments = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (Object o : overriding.parameters()) {
|
||||
SingleVariableDeclaration svd = (SingleVariableDeclaration) o;
|
||||
for (SingleVariableDeclaration svd : (Iterable<SingleVariableDeclaration>) overriding.parameters()) {
|
||||
CAstNode varNode = makeNode(context, fFactory, null, CAstNode.VAR, fFactory.makeConstant(svd.getName().getIdentifier()));
|
||||
ITypeBinding fromType = JDT2CAstUtils.getErasedType(paramTypes[i], ast);
|
||||
ITypeBinding toType = JDT2CAstUtils.getErasedType(overridingBinding.getParameterTypes()[i], ast);
|
||||
|
@ -940,16 +936,16 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
|
||||
if (parameterTypes == null) {
|
||||
fParameterTypes = new ArrayList<>(fDecl.parameters().size());
|
||||
for (Object p : fDecl.parameters()) {
|
||||
fParameterNames[i++] = ((SingleVariableDeclaration) p).getName().getIdentifier();
|
||||
fParameterTypes.add(fTypeDict.getCAstTypeFor(((SingleVariableDeclaration) p).resolveBinding().getType()));
|
||||
for (SingleVariableDeclaration p : (Iterable<SingleVariableDeclaration>) fDecl.parameters()) {
|
||||
fParameterNames[i++] = p.getName().getIdentifier();
|
||||
fParameterTypes.add(fTypeDict.getCAstTypeFor(p.resolveBinding().getType()));
|
||||
}
|
||||
} else {
|
||||
// currently this is only used in making a default constructor with arguments (anonymous classes).
|
||||
// this is because we cannot synthesize bindings.
|
||||
fParameterTypes = parameterTypes;
|
||||
for (Object p : fDecl.parameters()) {
|
||||
fParameterNames[i++] = ((SingleVariableDeclaration) p).getName().getIdentifier();
|
||||
for (SingleVariableDeclaration p : (Iterable<SingleVariableDeclaration>) fDecl.parameters()) {
|
||||
fParameterNames[i++] = p.getName().getIdentifier();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1086,9 +1082,9 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
if (fExceptionTypes == null) {
|
||||
fExceptionTypes = new LinkedHashSet<>();
|
||||
if (fDecl != null)
|
||||
for (Object exception : fDecl.thrownExceptionTypes())
|
||||
for (SimpleType exception : (Iterable<SimpleType>) fDecl.thrownExceptionTypes())
|
||||
|
||||
fExceptionTypes.add(fTypeDict.getCAstTypeFor(((SimpleType) exception).resolveBinding()));
|
||||
fExceptionTypes.add(fTypeDict.getCAstTypeFor(exception.resolveBinding()));
|
||||
}
|
||||
return fExceptionTypes;
|
||||
}
|
||||
|
@ -1262,8 +1258,8 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
*/
|
||||
private ArrayList<CAstNode> createBlock(Block n, WalkContext context) {
|
||||
ArrayList<CAstNode> stmtNodes = new ArrayList<>();
|
||||
for (Object s : n.statements())
|
||||
visitNodeOrNodes((ASTNode) s, context, stmtNodes);
|
||||
for (ASTNode s : (Iterable<ASTNode>) n.statements())
|
||||
visitNodeOrNodes(s, context, stmtNodes);
|
||||
return stmtNodes;
|
||||
}
|
||||
|
||||
|
@ -1309,8 +1305,8 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
private ArrayList<CAstNode> visit(VariableDeclarationStatement n, WalkContext context) {
|
||||
ArrayList<CAstNode> result = new ArrayList<>();
|
||||
|
||||
for (Object o : n.fragments())
|
||||
result.add(visit((VariableDeclarationFragment) o, context));
|
||||
for (VariableDeclarationFragment o : (Iterable<VariableDeclarationFragment>) n.fragments())
|
||||
result.add(visit(o, context));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1323,11 +1319,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
|
||||
eltNodes[idx++] = makeNode(context, fFactory, n, CAstNode.NEW, fFactory.makeConstant(newTypeRef), fFactory.makeConstant(n
|
||||
.expressions().size()));
|
||||
for (Iterator<CAstEntity> iter = n.expressions().iterator(); iter.hasNext(); idx++) {
|
||||
Expression element = (Expression) iter.next();
|
||||
for (Expression element : (Iterable<Expression>) n.expressions()) {
|
||||
eltNodes[idx] = visitNode(element, context);
|
||||
if (eltNodes[idx] == null)
|
||||
assert eltNodes[idx] != null : element.toString();
|
||||
++idx;
|
||||
}
|
||||
|
||||
return makeNode(context, fFactory, n, CAstNode.ARRAY_LITERAL, eltNodes);
|
||||
|
@ -2019,8 +2015,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
// keep on adding operands on the right side
|
||||
|
||||
leftLength = n.getRightOperand().getStartPosition() + n.getRightOperand().getLength() - leftStartPosition;
|
||||
for (Object o : n.extendedOperands()) {
|
||||
Expression operand = (Expression) o;
|
||||
for (Expression operand : (Iterable<Expression>) n.extendedOperands()) {
|
||||
result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, result, operand, context);
|
||||
|
||||
if (leftType.isPrimitive() && operand.resolveTypeBinding().isPrimitive())
|
||||
|
@ -2634,8 +2629,8 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
for (int i = 0; i < n.initializers().size(); i++) {
|
||||
ASTNode init = (ASTNode) n.initializers().get(i);
|
||||
if (init instanceof VariableDeclarationExpression) {
|
||||
for (Object o : ((VariableDeclarationExpression) init).fragments())
|
||||
inits.add(visitNode((ASTNode) o, context));
|
||||
for (ASTNode o : (Iterable<ASTNode>) ((VariableDeclarationExpression) init).fragments())
|
||||
inits.add(visitNode(o, context));
|
||||
} else
|
||||
inits.add(visitNode(init, context));
|
||||
}
|
||||
|
@ -3125,8 +3120,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
TryCatchContext(WalkContext parent, TryStatement tryNode) {
|
||||
super(parent);
|
||||
|
||||
for (Iterator<CatchClause> catchIter = tryNode.catchClauses().iterator(); catchIter.hasNext();) {
|
||||
CatchClause c = catchIter.next();
|
||||
for (CatchClause c : (Iterable<CatchClause>) tryNode.catchClauses()) {
|
||||
Pair<ITypeBinding, Object> p = Pair.make(c.getException().resolveBinding().getType(), (Object) c);
|
||||
|
||||
fCatchNodes.add(p);
|
||||
|
|
Loading…
Reference in New Issue