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     * @declaredat /home/jesper/git/extendj/java4/grammar/BoundNames.ast:10
027     * @production BytecodeTypeAccess : {@link TypeAccess};
028    
029     */
030    public class BytecodeTypeAccess extends TypeAccess implements Cloneable {
031      /**
032       * @declaredat ASTNode:1
033       */
034      public BytecodeTypeAccess() {
035        super();
036      }
037      /**
038       * Initializes the child array to the correct size.
039       * Initializes List and Opt nta children.
040       * @apilevel internal
041       * @ast method
042       * @declaredat ASTNode:10
043       */
044      public void init$Children() {
045      }
046      /**
047       * @declaredat ASTNode:12
048       */
049      public BytecodeTypeAccess(String p0, String p1) {
050        setPackage(p0);
051        setID(p1);
052      }
053      /**
054       * @declaredat ASTNode:16
055       */
056      public BytecodeTypeAccess(beaver.Symbol p0, beaver.Symbol p1) {
057        setPackage(p0);
058        setID(p1);
059      }
060      /**
061       * @apilevel low-level
062       * @declaredat ASTNode:23
063       */
064      protected int numChildren() {
065        return 0;
066      }
067      /**
068       * @apilevel internal
069       * @declaredat ASTNode:29
070       */
071      public boolean mayHaveRewrite() {
072        return true;
073      }
074      /**
075       * @apilevel internal
076       * @declaredat ASTNode:35
077       */
078      public void flushAttrCache() {
079        super.flushAttrCache();
080      }
081      /**
082       * @apilevel internal
083       * @declaredat ASTNode:41
084       */
085      public void flushCollectionCache() {
086        super.flushCollectionCache();
087      }
088      /**
089       * @apilevel internal
090       * @declaredat ASTNode:47
091       */
092      public void flushRewriteCache() {
093        super.flushRewriteCache();
094      }
095      /**
096       * @apilevel internal
097       * @declaredat ASTNode:53
098       */
099      public BytecodeTypeAccess clone() throws CloneNotSupportedException {
100        BytecodeTypeAccess node = (BytecodeTypeAccess) super.clone();
101        return node;
102      }
103      /**
104       * @apilevel internal
105       * @declaredat ASTNode:60
106       */
107      public BytecodeTypeAccess copy() {
108        try {
109          BytecodeTypeAccess node = (BytecodeTypeAccess) clone();
110          node.parent = null;
111          if (children != null) {
112            node.children = (ASTNode[]) children.clone();
113          }
114          return node;
115        } catch (CloneNotSupportedException e) {
116          throw new Error("Error: clone not supported for " + getClass().getName());
117        }
118      }
119      /**
120       * Create a deep copy of the AST subtree at this node.
121       * The copy is dangling, i.e. has no parent.
122       * @return dangling copy of the subtree at this node
123       * @apilevel low-level
124       * @deprecated Please use treeCopy or treeCopyNoTransform instead
125       * @declaredat ASTNode:79
126       */
127      @Deprecated
128      public BytecodeTypeAccess fullCopy() {
129        return treeCopyNoTransform();
130      }
131      /**
132       * Create a deep copy of the AST subtree at this node.
133       * The copy is dangling, i.e. has no parent.
134       * @return dangling copy of the subtree at this node
135       * @apilevel low-level
136       * @declaredat ASTNode:89
137       */
138      public BytecodeTypeAccess treeCopyNoTransform() {
139        BytecodeTypeAccess tree = (BytecodeTypeAccess) copy();
140        if (children != null) {
141          for (int i = 0; i < children.length; ++i) {
142            ASTNode child = (ASTNode) children[i];
143            if (child != null) {
144              child = child.treeCopyNoTransform();
145              tree.setChild(child, i);
146            }
147          }
148        }
149        return tree;
150      }
151      /**
152       * Create a deep copy of the AST subtree at this node.
153       * The subtree of this node is traversed to trigger rewrites before copy.
154       * The copy is dangling, i.e. has no parent.
155       * @return dangling copy of the subtree at this node
156       * @apilevel low-level
157       * @declaredat ASTNode:109
158       */
159      public BytecodeTypeAccess treeCopy() {
160        doFullTraversal();
161        return treeCopyNoTransform();
162      }
163      /**
164       * @apilevel internal
165       * @declaredat ASTNode:116
166       */
167      protected boolean is$Equal(ASTNode node) {
168        return super.is$Equal(node) && (tokenString_Package == ((BytecodeTypeAccess)node).tokenString_Package) && (tokenString_ID == ((BytecodeTypeAccess)node).tokenString_ID);    
169      }
170      /**
171       * Replaces the lexeme Package.
172       * @param value The new value for the lexeme Package.
173       * @apilevel high-level
174       */
175      public void setPackage(String value) {
176        tokenString_Package = value;
177      }
178      /**
179       * JastAdd-internal setter for lexeme Package using the Beaver parser.
180       * @param symbol Symbol containing the new value for the lexeme Package
181       * @apilevel internal
182       */
183      public void setPackage(beaver.Symbol symbol) {
184        if (symbol.value != null && !(symbol.value instanceof String))
185        throw new UnsupportedOperationException("setPackage is only valid for String lexemes");
186        tokenString_Package = (String)symbol.value;
187        Packagestart = symbol.getStart();
188        Packageend = symbol.getEnd();
189      }
190      /**
191       * Retrieves the value for the lexeme Package.
192       * @return The value for the lexeme Package.
193       * @apilevel high-level
194       */
195      @ASTNodeAnnotation.Token(name="Package")
196      public String getPackage() {
197        return tokenString_Package != null ? tokenString_Package : "";
198      }
199      /**
200       * Replaces the lexeme ID.
201       * @param value The new value for the lexeme ID.
202       * @apilevel high-level
203       */
204      public void setID(String value) {
205        tokenString_ID = value;
206      }
207      /**
208       * JastAdd-internal setter for lexeme ID using the Beaver parser.
209       * @param symbol Symbol containing the new value for the lexeme ID
210       * @apilevel internal
211       */
212      public void setID(beaver.Symbol symbol) {
213        if (symbol.value != null && !(symbol.value instanceof String))
214        throw new UnsupportedOperationException("setID is only valid for String lexemes");
215        tokenString_ID = (String)symbol.value;
216        IDstart = symbol.getStart();
217        IDend = symbol.getEnd();
218      }
219      /**
220       * Retrieves the value for the lexeme ID.
221       * @return The value for the lexeme ID.
222       * @apilevel high-level
223       */
224      @ASTNodeAnnotation.Token(name="ID")
225      public String getID() {
226        return tokenString_ID != null ? tokenString_ID : "";
227      }
228      /**
229       * @apilevel internal
230       */
231      public ASTNode rewriteTo() {
232        // Declared at /home/jesper/git/extendj/java4/frontend/BoundNames.jrag:115
233        return rewriteRule0();
234      }
235      /**
236       * @declaredat /home/jesper/git/extendj/java4/frontend/BoundNames.jrag:115
237       * @apilevel internal
238       */
239      private Access rewriteRule0() {
240    {
241          if (name().indexOf("$") == -1) {
242            return new TypeAccess(packageName(), name());
243          } else {
244            String[] names = name().split("\\$");
245            Access a = null; // the resulting access
246            String newName = null; // the subname to try
247            TypeDecl type = null; // qualifying type if one
248            for (int i = 0; i < names.length; i++) {
249              newName = newName == null ? names[i] : (newName + "$" + names[i]);
250              SimpleSet set;
251              if (type != null) {
252                set = type.memberTypes(newName);
253              } else if (packageName().equals("")) {
254                set = lookupType(newName);
255              } else {
256                set = lookupType(packageName(), newName).asSet();
257              }
258              if (!set.isEmpty()) {
259                a = a == null ? (Access) new TypeAccess(packageName(), newName) : (Access) a.qualifiesAccess(new TypeAccess(newName));
260                type = (TypeDecl) set.iterator().next();
261                newName = null; // reset subname
262              }
263            }
264            if (a == null) {
265              a = new TypeAccess(packageName(), name());
266            }
267            return a;
268          }
269        }  }
270    }