1.1 --- a/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java Sat Dec 29 20:10:10 2012 +0100
1.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java Mon Feb 11 12:46:43 2013 +0100
1.3 @@ -30,33 +30,57 @@
1.4 TrapDataIterator(Vector exceptionTable) {
1.5 for (int i=0 ; i < exceptionTable.size(); i++) {
1.6 final TrapData td = (TrapData)exceptionTable.elementAt(i);
1.7 - exStart.put(td.start_pc, td);
1.8 - exStop.put(td.end_pc, td);
1.9 + put(exStart, td.start_pc, td);
1.10 + put(exStop, td.end_pc, td);
1.11 }
1.12 }
1.13 -
1.14 - public boolean advanceTo(int i) {
1.15 +
1.16 + private static void put(Hashtable h, short key, TrapData td) {
1.17 + Short s = Short.valueOf((short)key);
1.18 + Vector v = (Vector) h.get(s);
1.19 + if (v == null) {
1.20 + v = new Vector(1);
1.21 + h.put(s, v);
1.22 + }
1.23 + v.add(td);
1.24 + }
1.25 +
1.26 + private boolean processAll(Hashtable h, Short key, boolean add) {
1.27 boolean change = false;
1.28 - Short s = Short.valueOf((short)i);
1.29 - TrapData e = (TrapData) exStart.get(s);
1.30 - if (e != null) {
1.31 - add(e);
1.32 - change = true;
1.33 - }
1.34 - e = (TrapData) exStop.get(s);
1.35 - if (e != null) {
1.36 - remove(e);
1.37 - change = true;
1.38 + Vector v = (Vector)h.get(key);
1.39 + if (v != null) {
1.40 + int s = v.size();
1.41 + for (int i = 0; i < s; i++) {
1.42 + TrapData td = (TrapData)v.elementAt(i);
1.43 + if (add) {
1.44 + add(td);
1.45 + change = true;
1.46 + } else {
1.47 + remove(td);
1.48 + change = true;
1.49 + }
1.50 + }
1.51 }
1.52 return change;
1.53 }
1.54 +
1.55 + public boolean advanceTo(int i) {
1.56 + Short s = Short.valueOf((short)i);
1.57 + boolean ch1 = processAll(exStart, s, true);
1.58 + boolean ch2 = processAll(exStop, s, false);
1.59 + return ch1 || ch2;
1.60 + }
1.61
1.62 public boolean useTry() {
1.63 return currentCount > 0;
1.64 }
1.65
1.66 public TrapData[] current() {
1.67 - return current;
1.68 + TrapData[] copy = new TrapData[currentCount];
1.69 + for (int i = 0; i < currentCount; i++) {
1.70 + copy[i] = current[i];
1.71 + }
1.72 + return copy;
1.73 }
1.74
1.75 private void add(TrapData e) {
1.76 @@ -71,6 +95,9 @@
1.77 }
1.78
1.79 private void remove(TrapData e) {
1.80 + if (currentCount == 0) {
1.81 + return;
1.82 + }
1.83 int from = 0;
1.84 while (from < currentCount) {
1.85 if (e == current[from++]) {