1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 import org.aspectj.compiler.base.CodeWriter; 29 import java.io.IOException ; 30 31 import java.util.Iterator ; 32 33 37 public class CatchClauses extends ASTObject { 38 39 public void unparse(CodeWriter writer) throws IOException { 40 writer.writeChildren(this); 41 } 42 43 protected int size; 45 public CatchClause[] children; 46 47 public CatchClauses(SourceLocation location, CatchClause[] _children) { 48 super(location); 49 for(int i=0; i<_children.length; i++) { 50 if (_children[i] != null) _children[i].setParent(this); 51 } 52 children = _children; 53 size = _children.length; 54 } 55 56 public CatchClauses(SourceLocation location) { 57 this(location, new CatchClause[] {}); 58 } 59 60 public CatchClauses(SourceLocation location, CatchClause child1) { 61 this(location, new CatchClause[] {child1}); 62 } 63 64 public CatchClauses(SourceLocation location, CatchClause child1, CatchClause child2) { 65 this(location, new CatchClause[] {child1, child2}); 66 } 67 68 public CatchClauses(SourceLocation location, CatchClause child1, CatchClause child2, CatchClause child3) { 69 this(location, new CatchClause[] {child1, child2, child3}); 70 } 71 72 public ASTObject copyWalk(CopyWalker walker) { 73 final int N = size; 74 CatchClause[] copiedChildren = new CatchClause[N]; 75 int newIndex = 0; 76 for(int oldIndex=0; oldIndex<N; oldIndex++) { 77 CatchClause newChild = (CatchClause)walker.process(children[oldIndex]); 78 if (newChild != null) copiedChildren[newIndex++] = newChild; 79 } 80 CatchClauses ret = new CatchClauses(getSourceLocation(),copiedChildren); 81 ret.size = newIndex; 82 ret.setSource(this); 83 return ret; 84 } 85 86 public ASTObject getChildAt(int childIndex) { return get(childIndex); } 87 public void setChildAt(int childIndex, ASTObject child) { set(childIndex, (CatchClause)child); } 88 public String getChildNameAt(int childIndex) { return "clause"+childIndex; } 89 90 public int getChildCount() { return size; } 91 public int size() { return size; } 92 93 public CatchClause get(int index) { 94 if (index >= size) throw new ArrayIndexOutOfBoundsException (); 95 return children[index]; 96 } 97 98 public void set(int index, CatchClause child) { 99 if (index >= size) throw new ArrayIndexOutOfBoundsException (); 100 children[index] = child; 101 child.setParent(this); 102 } 103 104 public void resize(int newSize) { 105 if (newSize > children.length) { 106 CatchClause[] newChildren = new CatchClause[children.length*2 + 1]; 107 System.arraycopy(children, 0, newChildren, 0, children.length); 108 children = newChildren; 109 } 110 size = newSize; 111 } 112 113 public void addAll(CatchClauses collection) { 114 addAll(size, collection); 115 } 116 117 public void addAll(int index, CatchClauses collection) { 118 for(int i=0; i<collection.size(); i++) { 119 add(index+i, collection.get(i)); 120 } 121 } 122 123 public void add(CatchClause child) { 124 add(size, child); 125 } 126 127 public void add(int index, CatchClause child) { 128 if (child == null) return; 129 130 if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException (); 131 132 resize(size+1); 133 134 for(int moveIndex = size-1; moveIndex > index; moveIndex--) { 135 children[moveIndex] = children[moveIndex-1]; 136 } 137 138 children[index] = child; 139 child.setParent(this); 140 } 141 142 public void remove(int index) { 143 if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException (); 144 145 size -= 1; 146 147 for(int moveIndex = index; moveIndex < size; moveIndex++) { 148 children[moveIndex] = children[moveIndex+1]; 149 } 150 } 151 152 public String getDefaultDisplayName() { 153 return "CatchClauses()"; 154 } 155 156 } 158 159 160 | Popular Tags |