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