Skip to content

Commit

Permalink
Use ASMs new Iterable API for better readability (bazelbuild#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof authored and Godin committed Sep 30, 2019
1 parent 08826cb commit 71df272
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ private Set<String> getTagsWithGotos() throws IOException {
continue;
}
int lineNumber = -1;
for (AbstractInsnNode i = m.instructions
.getFirst(); i != null; i = i.getNext()) {
for (AbstractInsnNode i : m.instructions) {
if (AbstractInsnNode.LINE == i.getType()) {
lineNumber = ((LineNumberNode) i).line;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ public void accept(final MethodNode methodNode,
for (final TryCatchBlockNode n : methodNode.tryCatchBlocks) {
n.accept(methodVisitor);
}
currentNode = methodNode.instructions.getFirst();
while (currentNode != null) {
currentNode.accept(methodVisitor);
currentNode = currentNode.getNext();
for (final AbstractInsnNode i : methodNode.instructions) {
currentNode = i;
i.accept(methodVisitor);
}
methodVisitor.visitEnd();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public void filter(final MethodNode methodNode,
}

private boolean hasLineNumber(final MethodNode methodNode) {
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
if (AbstractInsnNode.LINE == i.getType()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public void filter(final MethodNode methodNode,
}

int line = 0;
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
if (AbstractInsnNode.LINE == i.getType()) {
line = ((LineNumberNode) i).line;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class KotlinLateinitFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
matcher.match(i, output);
for (final AbstractInsnNode node : methodNode.instructions) {
matcher.match(node, output);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public final class KotlinNotNullOperatorFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
matcher.match(i, output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public final class KotlinUnsafeCastOperatorFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
matcher.match(i, output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public final class KotlinWhenFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
matcher.match(i, output);
}
}
Expand Down Expand Up @@ -93,7 +92,7 @@ private static void ignoreDefaultBranch(final AbstractInsnNode switchNode,
labels = ((TableSwitchInsnNode) switchNode).labels;
}
final Set<AbstractInsnNode> newTargets = new HashSet<AbstractInsnNode>();
for (LabelNode label : labels) {
for (final LabelNode label : labels) {
newTargets.add(AbstractMatcher.skipNonOpcodes(label));
}
output.replaceBranches(switchNode, newTargets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public final class KotlinWhenStringFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
matcher.match(i, output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public final class StringSwitchEcjFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
final Matcher matcher = new Matcher();
for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
for (final AbstractInsnNode i : methodNode.instructions) {
matcher.match(i, output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public final class StringSwitchJavacFilter implements IFilter {

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
AbstractInsnNode i = methodNode.instructions.getFirst();
while (i != null) {
for (final AbstractInsnNode i : methodNode.instructions) {
filter(i, output);
i = i.getNext();
}
}

Expand Down

0 comments on commit 71df272

Please sign in to comment.