Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fd5e4140fb61
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7236f72463ee
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 30, 2017

  1. Copy the full SHA
    f63572e View commit details
  2. Make ListNode iterable.

    headius committed Aug 30, 2017
    Copy the full SHA
    7236f72 View commit details
Showing with 21 additions and 2 deletions.
  1. +1 −1 core/src/main/java/org/jruby/RubyKernel.java
  2. +20 −1 core/src/main/java/org/jruby/ast/ListNode.java
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -917,7 +917,7 @@ private static void maybeRaiseJavaException(final Ruby runtime,
if (ex.getCause() == null && cause instanceof ConcreteJavaProxy) {
// allow raise java.lang.RuntimeException.new, cause: myCurrentException()
maybeThrowable = ((ConcreteJavaProxy) cause).getObject();
if (maybeThrowable instanceof Throwable && ex != maybeThrowable) {
if (maybeThrowable instanceof Throwable && ex != maybeThrowable && ex.getCause() == null) {
ex.initCause((Throwable) maybeThrowable);
}
}
21 changes: 20 additions & 1 deletion core/src/main/java/org/jruby/ast/ListNode.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
package org.jruby.ast;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
@@ -40,7 +41,7 @@
* In particular, f_arg production rule uses this to capture arg information for
* the editor projects who want position info saved.
*/
public class ListNode extends Node {
public class ListNode extends Node implements Iterable<Node> {
private static final Node[] EMPTY = new Node[0];
private static final int INITIAL_SIZE = 4;
private Node[] list;
@@ -174,4 +175,22 @@ public <T> T accept(NodeVisitor<T> visitor) {
public Node get(int idx) {
return list[idx];
}

@Override
public Iterator<Node> iterator() {
return new Iterator<Node>() {
int i = 0;

@Override
public boolean hasNext() {
return i < list.length;
}

@Override
public Node next() {
if (i >= list.length) throw new IndexOutOfBoundsException(i);
return list[i++];
}
};
}
}