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 org.aspectj.compiler.base.cst.*; 30 31 import java.util.Iterator ; 32 33 37 public class TypeDs extends ASTObject { 38 public boolean contains(TypeD name) { 39 final int N = size(); 40 for (int i = 0; i < N; i++) { 42 TypeD thisName = get(i); 43 if (thisName.getType().isEquivalent(name.getType())) { 45 return true; 47 } 48 } 49 return false; 50 } 51 52 53 public void unparse(CodeWriter writer) { 54 writer.writeChildrenWithCommas(this); 55 } 56 57 public Iterator iterator() { 58 return new Iterator () { 59 private int i = 0; 60 public boolean hasNext() { return i < size; } 61 public Object next() { return children[i++]; } 62 public void remove() { 63 throw new UnsupportedOperationException (); 64 } 65 }; 66 } 67 68 protected int size; 70 public TypeD[] children; 71 72 public TypeDs(SourceLocation location, TypeD[] _children) { 73 super(location); 74 for(int i=0; i<_children.length; i++) { 75 if (_children[i] != null) _children[i].setParent(this); 76 } 77 children = _children; 78 size = _children.length; 79 } 80 81 public TypeDs(SourceLocation location) { 82 this(location, new TypeD[] {}); 83 } 84 85 public TypeDs(SourceLocation location, TypeD child1) { 86 this(location, new TypeD[] {child1}); 87 } 88 89 public TypeDs(SourceLocation location, TypeD child1, TypeD child2) { 90 this(location, new TypeD[] {child1, child2}); 91 } 92 93 public TypeDs(SourceLocation location, TypeD child1, TypeD child2, TypeD child3) { 94 this(location, new TypeD[] {child1, child2, child3}); 95 } 96 97 public ASTObject copyWalk(CopyWalker walker) { 98 final int N = size; 99 TypeD[] copiedChildren = new TypeD[N]; 100 int newIndex = 0; 101 for(int oldIndex=0; oldIndex<N; oldIndex++) { 102 TypeD newChild = (TypeD)walker.process(children[oldIndex]); 103 if (newChild != null) copiedChildren[newIndex++] = newChild; 104 } 105 TypeDs ret = new TypeDs(getSourceLocation(),copiedChildren); 106 ret.size = newIndex; 107 ret.setSource(this); 108 return ret; 109 } 110 111 public ASTObject getChildAt(int childIndex) { return get(childIndex); } 112 public void setChildAt(int childIndex, ASTObject child) { set(childIndex, (TypeD)child); } 113 public String getChildNameAt(int childIndex) { return "typeD"+childIndex; } 114 115 public int getChildCount() { return size; } 116 public int size() { return size; } 117 118 public TypeD get(int index) { 119 if (index >= size) throw new ArrayIndexOutOfBoundsException (); 120 return children[index]; 121 } 122 123 public void set(int index, TypeD child) { 124 if (index >= size) throw new ArrayIndexOutOfBoundsException (); 125 children[index] = child; 126 child.setParent(this); 127 } 128 129 public void resize(int newSize) { 130 if (newSize > children.length) { 131 TypeD[] newChildren = new TypeD[children.length*2 + 1]; 132 System.arraycopy(children, 0, newChildren, 0, children.length); 133 children = newChildren; 134 } 135 size = newSize; 136 } 137 138 public void addAll(TypeDs collection) { 139 addAll(size, collection); 140 } 141 142 public void addAll(int index, TypeDs collection) { 143 for(int i=0; i<collection.size(); i++) { 144 add(index+i, collection.get(i)); 145 } 146 } 147 148 public void add(TypeD child) { 149 add(size, child); 150 } 151 152 public void add(int index, TypeD child) { 153 if (child == null) return; 154 155 if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException (); 156 157 resize(size+1); 158 159 for(int moveIndex = size-1; moveIndex > index; moveIndex--) { 160 children[moveIndex] = children[moveIndex-1]; 161 } 162 163 children[index] = child; 164 child.setParent(this); 165 } 166 167 public void remove(int index) { 168 if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException (); 169 170 size -= 1; 171 172 for(int moveIndex = index; moveIndex < size; moveIndex++) { 173 children[moveIndex] = children[moveIndex+1]; 174 } 175 } 176 177 public String getDefaultDisplayName() { 178 return "TypeDs()"; 179 } 180 181 } 183 | Popular Tags |