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