001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */ 002 package org.extendj.ast; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.Set; 007 import java.util.Collections; 008 import java.util.Collection; 009 import java.util.ArrayList; 010 import beaver.*; 011 import java.util.*; 012 import java.io.ByteArrayOutputStream; 013 import java.io.PrintStream; 014 import java.lang.reflect.InvocationTargetException; 015 import java.lang.reflect.Method; 016 import org.jastadd.util.*; 017 import java.util.zip.*; 018 import java.io.*; 019 import org.jastadd.util.PrettyPrintable; 020 import org.jastadd.util.PrettyPrinter; 021 import java.io.FileNotFoundException; 022 import java.io.BufferedInputStream; 023 import java.io.DataInputStream; 024 /** 025 * @ast node 026 * @production List : {@link ASTNode}; 027 028 */ 029 public class List<T extends ASTNode> extends ASTNode<T> implements Cloneable { 030 /** Default list pretty printing prints all list elements. 031 * @aspect PrettyPrintUtil 032 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:73 033 */ 034 public void prettyPrint(PrettyPrinter out) { 035 for (int i = 0; i < getNumChild(); ++i) { 036 getChild(i).prettyPrint(out); 037 } 038 } 039 /** 040 * @aspect LookupParTypeDecl 041 * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:1165 042 */ 043 public List substitute(Parameterization parTypeDecl) { 044 List list = new List(); 045 for (int i = 0; i < getNumChild(); i++) { 046 ASTNode node = getChild(i); 047 if (node instanceof Access) { 048 Access a = (Access) node; 049 list.add(a.type().substitute(parTypeDecl)); 050 } else if (node instanceof VariableArityParameterDeclaration) { 051 VariableArityParameterDeclaration p = (VariableArityParameterDeclaration) node; 052 list.add( 053 new VariableArityParameterDeclarationSubstituted( 054 (Modifiers) p.getModifiers().treeCopyNoTransform(), 055 // use the type acces since VariableArity adds to the dimension 056 p.getTypeAccess().type().substituteParameterType(parTypeDecl), 057 p.getID(), 058 p 059 ) 060 ); 061 } else if (node instanceof ParameterDeclaration) { 062 ParameterDeclaration p = (ParameterDeclaration) node; 063 list.add( 064 new ParameterDeclarationSubstituted( 065 (Modifiers) p.getModifiers().treeCopyNoTransform(), 066 p.type().substituteParameterType(parTypeDecl), 067 p.getID(), 068 p 069 ) 070 ); 071 } else { 072 throw new Error("Can only substitute lists of access nodes but node number " 073 + i + " is of type " + node.getClass().getName()); 074 } 075 } 076 return list; 077 } 078 /** 079 * @declaredat ASTNode:1 080 */ 081 public List() { 082 super(); 083 } 084 /** 085 * Initializes the child array to the correct size. 086 * Initializes List and Opt nta children. 087 * @apilevel internal 088 * @ast method 089 * @declaredat ASTNode:10 090 */ 091 public void init$Children() { 092 } 093 /** 094 * @declaredat ASTNode:12 095 */ 096 public List(T... initialChildren) { 097 children = new ASTNode[initialChildren.length]; 098 for (int i = 0; i < children.length; ++i) { 099 addChild(initialChildren[i]); 100 } 101 } 102 /** 103 * @declaredat ASTNode:19 104 */ 105 private boolean list$touched = true; 106 /** 107 * @declaredat ASTNode:21 108 */ 109 public List<T> add(T node) { 110 addChild(node); 111 return this; 112 } 113 /** 114 * @declaredat ASTNode:26 115 */ 116 public List<T> addAll(java.util.Collection<? extends T> c) { 117 for (T node : c) { 118 addChild(node); 119 } 120 return this; 121 } 122 /** 123 * @declaredat ASTNode:33 124 */ 125 public void insertChild(ASTNode node, int i) { 126 127 list$touched = true; 128 129 super.insertChild(node, i); 130 } 131 /** 132 * @declaredat ASTNode:40 133 */ 134 public void addChild(T node) { 135 136 list$touched = true; 137 138 super.addChild(node); 139 } 140 /** 141 * @apilevel low-level 142 * @declaredat ASTNode:50 143 */ 144 public void removeChild(int i) { 145 146 list$touched = true; 147 148 super.removeChild(i); 149 } 150 /** 151 * @declaredat ASTNode:57 152 */ 153 public int getNumChild() { 154 155 if (list$touched) { 156 for (int i = 0; i < getNumChildNoTransform(); i++) { 157 getChild(i); 158 } 159 list$touched = false; 160 } 161 162 return getNumChildNoTransform(); 163 } 164 /** 165 * @apilevel internal 166 * @declaredat ASTNode:71 167 */ 168 public boolean mayHaveRewrite() { 169 return true; 170 } 171 /** 172 * @apilevel internal 173 * @declaredat ASTNode:77 174 */ 175 public void flushAttrCache() { 176 super.flushAttrCache(); 177 } 178 /** 179 * @apilevel internal 180 * @declaredat ASTNode:83 181 */ 182 public void flushCollectionCache() { 183 super.flushCollectionCache(); 184 } 185 /** 186 * @apilevel internal 187 * @declaredat ASTNode:89 188 */ 189 public void flushRewriteCache() { 190 super.flushRewriteCache(); 191 } 192 /** 193 * @apilevel internal 194 * @declaredat ASTNode:95 195 */ 196 public List<T> clone() throws CloneNotSupportedException { 197 List node = (List) super.clone(); 198 return node; 199 } 200 /** 201 * @apilevel internal 202 * @declaredat ASTNode:102 203 */ 204 public List<T> copy() { 205 try { 206 List node = (List) clone(); 207 node.parent = null; 208 if (children != null) { 209 node.children = (ASTNode[]) children.clone(); 210 } 211 return node; 212 } catch (CloneNotSupportedException e) { 213 throw new Error("Error: clone not supported for " + getClass().getName()); 214 } 215 } 216 /** 217 * Create a deep copy of the AST subtree at this node. 218 * The copy is dangling, i.e. has no parent. 219 * @return dangling copy of the subtree at this node 220 * @apilevel low-level 221 * @deprecated Please use treeCopy or treeCopyNoTransform instead 222 * @declaredat ASTNode:121 223 */ 224 @Deprecated 225 public List<T> fullCopy() { 226 return treeCopyNoTransform(); 227 } 228 /** 229 * Create a deep copy of the AST subtree at this node. 230 * The copy is dangling, i.e. has no parent. 231 * @return dangling copy of the subtree at this node 232 * @apilevel low-level 233 * @declaredat ASTNode:131 234 */ 235 public List<T> treeCopyNoTransform() { 236 List tree = (List) copy(); 237 if (children != null) { 238 for (int i = 0; i < children.length; ++i) { 239 ASTNode child = (ASTNode) children[i]; 240 if (child != null) { 241 child = child.treeCopyNoTransform(); 242 tree.setChild(child, i); 243 } 244 } 245 } 246 return tree; 247 } 248 /** 249 * Create a deep copy of the AST subtree at this node. 250 * The subtree of this node is traversed to trigger rewrites before copy. 251 * The copy is dangling, i.e. has no parent. 252 * @return dangling copy of the subtree at this node 253 * @apilevel low-level 254 * @declaredat ASTNode:151 255 */ 256 public List<T> treeCopy() { 257 doFullTraversal(); 258 return treeCopyNoTransform(); 259 } 260 /** 261 * @apilevel internal 262 * @declaredat ASTNode:158 263 */ 264 protected boolean is$Equal(ASTNode node) { 265 return super.is$Equal(node); 266 } 267 /** 268 * @apilevel internal 269 */ 270 public ASTNode rewriteTo() { 271 if (list$touched) { 272 for(int i = 0 ; i < getNumChildNoTransform(); i++) { 273 getChild(i); 274 } 275 list$touched = false; 276 return this; 277 } 278 return super.rewriteTo(); 279 } 280 }