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/Java.ast:10
027     * @production SingleTypeImportDecl : {@link ImportDecl};
028    
029     */
030    public class SingleTypeImportDecl extends ImportDecl implements Cloneable {
031      /**
032       * @aspect NameCheck
033       * @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:43
034       */
035      public void nameCheck() {
036        if (!getAccess().type().typeName().equals(typeName()) && !getAccess().type().isUnknown()) {
037          errorf("Single-type import %s is not the canonical name of type %s",
038              typeName(), getAccess().type().typeName());
039        } else if (allImportedTypes(getAccess().type().name()).size() > 1) {
040          errorf("%s is imported multiple times", getAccess().type().name());
041        }
042      }
043      /**
044       * @aspect Java4PrettyPrint
045       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:255
046       */
047      public void prettyPrint(PrettyPrinter out) {
048        out.print("import ");
049        out.print(getAccess());
050        out.print(";");
051        out.println();
052      }
053      /**
054       * @declaredat ASTNode:1
055       */
056      public SingleTypeImportDecl() {
057        super();
058      }
059      /**
060       * Initializes the child array to the correct size.
061       * Initializes List and Opt nta children.
062       * @apilevel internal
063       * @ast method
064       * @declaredat ASTNode:10
065       */
066      public void init$Children() {
067        children = new ASTNode[1];
068      }
069      /**
070       * @declaredat ASTNode:13
071       */
072      public SingleTypeImportDecl(Access p0) {
073        setChild(p0, 0);
074      }
075      /**
076       * @apilevel low-level
077       * @declaredat ASTNode:19
078       */
079      protected int numChildren() {
080        return 1;
081      }
082      /**
083       * @apilevel internal
084       * @declaredat ASTNode:25
085       */
086      public boolean mayHaveRewrite() {
087        return false;
088      }
089      /**
090       * @apilevel internal
091       * @declaredat ASTNode:31
092       */
093      public void flushAttrCache() {
094        super.flushAttrCache();
095        importedTypes_String_reset();
096        importedTypes_reset();
097      }
098      /**
099       * @apilevel internal
100       * @declaredat ASTNode:39
101       */
102      public void flushCollectionCache() {
103        super.flushCollectionCache();
104      }
105      /**
106       * @apilevel internal
107       * @declaredat ASTNode:45
108       */
109      public void flushRewriteCache() {
110        super.flushRewriteCache();
111      }
112      /**
113       * @apilevel internal
114       * @declaredat ASTNode:51
115       */
116      public SingleTypeImportDecl clone() throws CloneNotSupportedException {
117        SingleTypeImportDecl node = (SingleTypeImportDecl) super.clone();
118        return node;
119      }
120      /**
121       * @apilevel internal
122       * @declaredat ASTNode:58
123       */
124      public SingleTypeImportDecl copy() {
125        try {
126          SingleTypeImportDecl node = (SingleTypeImportDecl) clone();
127          node.parent = null;
128          if (children != null) {
129            node.children = (ASTNode[]) children.clone();
130          }
131          return node;
132        } catch (CloneNotSupportedException e) {
133          throw new Error("Error: clone not supported for " + getClass().getName());
134        }
135      }
136      /**
137       * Create a deep copy of the AST subtree at this node.
138       * The copy is dangling, i.e. has no parent.
139       * @return dangling copy of the subtree at this node
140       * @apilevel low-level
141       * @deprecated Please use treeCopy or treeCopyNoTransform instead
142       * @declaredat ASTNode:77
143       */
144      @Deprecated
145      public SingleTypeImportDecl fullCopy() {
146        return treeCopyNoTransform();
147      }
148      /**
149       * Create a deep copy of the AST subtree at this node.
150       * The copy is dangling, i.e. has no parent.
151       * @return dangling copy of the subtree at this node
152       * @apilevel low-level
153       * @declaredat ASTNode:87
154       */
155      public SingleTypeImportDecl treeCopyNoTransform() {
156        SingleTypeImportDecl tree = (SingleTypeImportDecl) copy();
157        if (children != null) {
158          for (int i = 0; i < children.length; ++i) {
159            ASTNode child = (ASTNode) children[i];
160            if (child != null) {
161              child = child.treeCopyNoTransform();
162              tree.setChild(child, i);
163            }
164          }
165        }
166        return tree;
167      }
168      /**
169       * Create a deep copy of the AST subtree at this node.
170       * The subtree of this node is traversed to trigger rewrites before copy.
171       * The copy is dangling, i.e. has no parent.
172       * @return dangling copy of the subtree at this node
173       * @apilevel low-level
174       * @declaredat ASTNode:107
175       */
176      public SingleTypeImportDecl treeCopy() {
177        doFullTraversal();
178        return treeCopyNoTransform();
179      }
180      /**
181       * @apilevel internal
182       * @declaredat ASTNode:114
183       */
184      protected boolean is$Equal(ASTNode node) {
185        return super.is$Equal(node);    
186      }
187      /**
188       * Replaces the Access child.
189       * @param node The new node to replace the Access child.
190       * @apilevel high-level
191       */
192      public void setAccess(Access node) {
193        setChild(node, 0);
194      }
195      /**
196       * Retrieves the Access child.
197       * @return The current node used as the Access child.
198       * @apilevel high-level
199       */
200      @ASTNodeAnnotation.Child(name="Access")
201      public Access getAccess() {
202        return (Access) getChild(0);
203      }
204      /**
205       * Retrieves the Access child.
206       * <p><em>This method does not invoke AST transformations.</em></p>
207       * @return The current node used as the Access child.
208       * @apilevel low-level
209       */
210      public Access getAccessNoTransform() {
211        return (Access) getChildNoTransform(0);
212      }
213      /**
214       * @apilevel internal
215       */
216      protected java.util.Map importedTypes_String_values;
217      /**
218       * @apilevel internal
219       */
220      private void importedTypes_String_reset() {
221        importedTypes_String_values = null;
222      }
223      /**
224       * @attribute syn
225       * @aspect TypeScopePropagation
226       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:420
227       */
228      @ASTNodeAnnotation.Attribute
229      public SimpleSet importedTypes(String name) {
230        Object _parameters = name;
231        if (importedTypes_String_values == null) importedTypes_String_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
232        ASTNode$State state = state();
233        if (importedTypes_String_values.containsKey(_parameters)) {
234          return (SimpleSet) importedTypes_String_values.get(_parameters);
235        }
236        boolean intermediate = state.INTERMEDIATE_VALUE;
237        state.INTERMEDIATE_VALUE = false;
238        int num = state.boundariesCrossed;
239        boolean isFinal = this.is$Final();
240        SimpleSet importedTypes_String_value = importedTypes_compute(name);
241        if (isFinal && num == state().boundariesCrossed) {
242          importedTypes_String_values.put(_parameters, importedTypes_String_value);
243        } else {
244        }
245        state.INTERMEDIATE_VALUE |= intermediate;
246    
247        return importedTypes_String_value;
248      }
249      /**
250       * @apilevel internal
251       */
252      private SimpleSet importedTypes_compute(String name) {
253          SimpleSet set = SimpleSet.emptySet;
254          TypeDecl type = getAccess().type();
255          if (type.name().equals(name)) {
256            set = set.add(type);
257          }
258          return set;
259        }
260      /**
261       * @apilevel internal
262       */
263      protected boolean importedTypes_computed = false;
264      /**
265       * @apilevel internal
266       */
267      protected SimpleSet importedTypes_value;
268      /**
269       * @apilevel internal
270       */
271      private void importedTypes_reset() {
272        importedTypes_computed = false;
273        importedTypes_value = null;
274      }
275      /**
276       * For a single-import declaration this will return a SimpleSet
277       * containing the TypeDecl for the imported type. For dynamic
278       * import declarations this returns the empty set.
279       * @return TypeDecl of imported type wrapped in SimpleSet
280       * @attribute syn
281       * @aspect TypeScopePropagation
282       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:437
283       */
284      @ASTNodeAnnotation.Attribute
285      public SimpleSet importedTypes() {
286        ASTNode$State state = state();
287        if (importedTypes_computed) {
288          return importedTypes_value;
289        }
290        boolean intermediate = state.INTERMEDIATE_VALUE;
291        state.INTERMEDIATE_VALUE = false;
292        int num = state.boundariesCrossed;
293        boolean isFinal = this.is$Final();
294        importedTypes_value = SimpleSet.emptySet.add(getAccess().type());
295        if (isFinal && num == state().boundariesCrossed) {
296          importedTypes_computed = true;
297        } else {
298        }
299        state.INTERMEDIATE_VALUE |= intermediate;
300    
301        return importedTypes_value;
302      }
303      /**
304       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
305       * @apilevel internal
306       */
307      public NameType Define_nameType(ASTNode caller, ASTNode child) {
308        if (caller == getAccessNoTransform()) {
309          // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:99
310          return NameType.TYPE_NAME;
311        }
312        else {
313          return getParent().Define_nameType(this, caller);
314        }
315      }
316      protected boolean canDefine_nameType(ASTNode caller, ASTNode child) {
317        return true;
318      }
319      /**
320       * @apilevel internal
321       */
322      public ASTNode rewriteTo() {
323        return super.rewriteTo();
324      }
325    }