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