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:26
027     * @production ThisAccess : {@link Access} ::= <span class="component">&lt;ID:String&gt;</span>;
028    
029     */
030    public class ThisAccess extends Access implements Cloneable {
031      /**
032       * @aspect Java4PrettyPrint
033       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:136
034       */
035      public void prettyPrint(PrettyPrinter out) {
036        out.print("this");
037      }
038      /**
039       * @aspect TypeHierarchyCheck
040       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:139
041       */
042      public void nameCheck() {
043        // 8.8.5.1
044        // JLSv7 8.8.7.1
045        TypeDecl constructorHostType = enclosingExplicitConstructorHostType();
046        if (constructorHostType != null && (constructorHostType == decl())) {
047          error("this may not be accessed in an explicit constructor invocation");
048        } else if (isQualified()) {
049          // 15.8.4
050          if (inStaticContext()) {
051            error("qualified this may not occur in static context");
052          } else if (!hostType().isInnerTypeOf(decl()) && hostType() != decl()) {
053            errorf("qualified this access must name an enclosing type which %s is not",
054                decl().typeName());
055          }
056        } else if (!isQualified() && inStaticContext()) {
057          // 8.4.3.2
058          error("this access may not be used in a static context");
059        }
060      }
061      /**
062       * @aspect CreateBCode
063       * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:658
064       */
065      public void createBCode(CodeGeneration gen) {
066        emitThis(gen, decl());
067      }
068      /**
069       * @declaredat ASTNode:1
070       */
071      public ThisAccess() {
072        super();
073      }
074      /**
075       * Initializes the child array to the correct size.
076       * Initializes List and Opt nta children.
077       * @apilevel internal
078       * @ast method
079       * @declaredat ASTNode:10
080       */
081      public void init$Children() {
082      }
083      /**
084       * @declaredat ASTNode:12
085       */
086      public ThisAccess(String p0) {
087        setID(p0);
088      }
089      /**
090       * @declaredat ASTNode:15
091       */
092      public ThisAccess(beaver.Symbol p0) {
093        setID(p0);
094      }
095      /**
096       * @apilevel low-level
097       * @declaredat ASTNode:21
098       */
099      protected int numChildren() {
100        return 0;
101      }
102      /**
103       * @apilevel internal
104       * @declaredat ASTNode:27
105       */
106      public boolean mayHaveRewrite() {
107        return false;
108      }
109      /**
110       * @apilevel internal
111       * @declaredat ASTNode:33
112       */
113      public void flushAttrCache() {
114        super.flushAttrCache();
115        decl_reset();
116        type_reset();
117      }
118      /**
119       * @apilevel internal
120       * @declaredat ASTNode:41
121       */
122      public void flushCollectionCache() {
123        super.flushCollectionCache();
124      }
125      /**
126       * @apilevel internal
127       * @declaredat ASTNode:47
128       */
129      public void flushRewriteCache() {
130        super.flushRewriteCache();
131      }
132      /**
133       * @apilevel internal
134       * @declaredat ASTNode:53
135       */
136      public ThisAccess clone() throws CloneNotSupportedException {
137        ThisAccess node = (ThisAccess) super.clone();
138        return node;
139      }
140      /**
141       * @apilevel internal
142       * @declaredat ASTNode:60
143       */
144      public ThisAccess copy() {
145        try {
146          ThisAccess node = (ThisAccess) clone();
147          node.parent = null;
148          if (children != null) {
149            node.children = (ASTNode[]) children.clone();
150          }
151          return node;
152        } catch (CloneNotSupportedException e) {
153          throw new Error("Error: clone not supported for " + getClass().getName());
154        }
155      }
156      /**
157       * Create a deep copy of the AST subtree at this node.
158       * The copy is dangling, i.e. has no parent.
159       * @return dangling copy of the subtree at this node
160       * @apilevel low-level
161       * @deprecated Please use treeCopy or treeCopyNoTransform instead
162       * @declaredat ASTNode:79
163       */
164      @Deprecated
165      public ThisAccess fullCopy() {
166        return treeCopyNoTransform();
167      }
168      /**
169       * Create a deep copy of the AST subtree at this node.
170       * The copy is dangling, i.e. has no parent.
171       * @return dangling copy of the subtree at this node
172       * @apilevel low-level
173       * @declaredat ASTNode:89
174       */
175      public ThisAccess treeCopyNoTransform() {
176        ThisAccess tree = (ThisAccess) copy();
177        if (children != null) {
178          for (int i = 0; i < children.length; ++i) {
179            ASTNode child = (ASTNode) children[i];
180            if (child != null) {
181              child = child.treeCopyNoTransform();
182              tree.setChild(child, i);
183            }
184          }
185        }
186        return tree;
187      }
188      /**
189       * Create a deep copy of the AST subtree at this node.
190       * The subtree of this node is traversed to trigger rewrites before copy.
191       * The copy is dangling, i.e. has no parent.
192       * @return dangling copy of the subtree at this node
193       * @apilevel low-level
194       * @declaredat ASTNode:109
195       */
196      public ThisAccess treeCopy() {
197        doFullTraversal();
198        return treeCopyNoTransform();
199      }
200      /**
201       * @apilevel internal
202       * @declaredat ASTNode:116
203       */
204      protected boolean is$Equal(ASTNode node) {
205        return super.is$Equal(node) && (tokenString_ID == ((ThisAccess)node).tokenString_ID);    
206      }
207      /**
208       * Replaces the lexeme ID.
209       * @param value The new value for the lexeme ID.
210       * @apilevel high-level
211       */
212      public void setID(String value) {
213        tokenString_ID = value;
214      }
215      /**
216       * @apilevel internal
217       */
218      protected String tokenString_ID;
219      /**
220       */
221      public int IDstart;
222      /**
223       */
224      public int IDend;
225      /**
226       * JastAdd-internal setter for lexeme ID using the Beaver parser.
227       * @param symbol Symbol containing the new value for the lexeme ID
228       * @apilevel internal
229       */
230      public void setID(beaver.Symbol symbol) {
231        if (symbol.value != null && !(symbol.value instanceof String))
232        throw new UnsupportedOperationException("setID is only valid for String lexemes");
233        tokenString_ID = (String)symbol.value;
234        IDstart = symbol.getStart();
235        IDend = symbol.getEnd();
236      }
237      /**
238       * Retrieves the value for the lexeme ID.
239       * @return The value for the lexeme ID.
240       * @apilevel high-level
241       */
242      @ASTNodeAnnotation.Token(name="ID")
243      public String getID() {
244        return tokenString_ID != null ? tokenString_ID : "";
245      }
246      /**
247       * @aspect TypeScopePropagation
248       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:323
249       */
250      private TypeDecl refined_TypeScopePropagation_ThisAccess_decl()
251    { return isQualified() ? qualifier().type() : hostType(); }
252      /**
253       * @attribute syn
254       * @aspect TypeScopePropagation
255       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:317
256       */
257      @ASTNodeAnnotation.Attribute
258      public SimpleSet decls() {
259        SimpleSet decls_value = SimpleSet.emptySet;
260    
261        return decls_value;
262      }
263      /**
264       * @apilevel internal
265       */
266      protected boolean decl_computed = false;
267      /**
268       * @apilevel internal
269       */
270      protected TypeDecl decl_value;
271      /**
272       * @apilevel internal
273       */
274      private void decl_reset() {
275        decl_computed = false;
276        decl_value = null;
277      }
278      /**
279       * @return the type which this access references
280       * @attribute syn
281       * @aspect TypeScopePropagation
282       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:323
283       */
284      @ASTNodeAnnotation.Attribute
285      public TypeDecl decl() {
286        ASTNode$State state = state();
287        if (decl_computed) {
288          return decl_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        decl_value = decl_compute();
295        if (isFinal && num == state().boundariesCrossed) {
296          decl_computed = true;
297        } else {
298        }
299        state.INTERMEDIATE_VALUE |= intermediate;
300    
301        return decl_value;
302      }
303      /**
304       * @apilevel internal
305       */
306      private TypeDecl decl_compute() {
307          TypeDecl typeDecl;
308          if (isQualified()) {
309            typeDecl = qualifier().type();
310          } else {
311            typeDecl = hostType();
312            while (typeDecl instanceof LambdaAnonymousDecl) {
313              typeDecl = typeDecl.enclosingType();
314            }
315          }
316      
317          if (typeDecl instanceof ParTypeDecl) {
318            typeDecl = ((ParTypeDecl) typeDecl).genericDecl();
319          }
320          return typeDecl;
321        }
322      /**
323       * @attribute syn
324       * @aspect AccessTypes
325       * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:53
326       */
327      @ASTNodeAnnotation.Attribute
328      public boolean isThisAccess() {
329        boolean isThisAccess_value = true;
330    
331        return isThisAccess_value;
332      }
333      /**
334       * Defines the expected kind of name for the left hand side in a qualified
335       * expression.
336       * @attribute syn
337       * @aspect SyntacticClassification
338       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:58
339       */
340      @ASTNodeAnnotation.Attribute
341      public NameType predNameType() {
342        NameType predNameType_value = NameType.TYPE_NAME;
343    
344        return predNameType_value;
345      }
346      /**
347       * @apilevel internal
348       */
349      protected boolean type_computed = false;
350      /**
351       * @apilevel internal
352       */
353      protected TypeDecl type_value;
354      /**
355       * @apilevel internal
356       */
357      private void type_reset() {
358        type_computed = false;
359        type_value = null;
360      }
361      /**
362       * @attribute syn
363       * @aspect TypeAnalysis
364       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
365       */
366      @ASTNodeAnnotation.Attribute
367      public TypeDecl type() {
368        ASTNode$State state = state();
369        if (type_computed) {
370          return type_value;
371        }
372        boolean intermediate = state.INTERMEDIATE_VALUE;
373        state.INTERMEDIATE_VALUE = false;
374        int num = state.boundariesCrossed;
375        boolean isFinal = this.is$Final();
376        type_value = decl();
377        if (isFinal && num == state().boundariesCrossed) {
378          type_computed = true;
379        } else {
380        }
381        state.INTERMEDIATE_VALUE |= intermediate;
382    
383        return type_value;
384      }
385      /**
386       * @attribute inh
387       * @aspect TypeHierarchyCheck
388       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:163
389       */
390      /**
391       * @attribute inh
392       * @aspect TypeHierarchyCheck
393       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:163
394       */
395      @ASTNodeAnnotation.Attribute
396      public boolean inExplicitConstructorInvocation() {
397        boolean inExplicitConstructorInvocation_value = getParent().Define_inExplicitConstructorInvocation(this, null);
398    
399        return inExplicitConstructorInvocation_value;
400      }
401      /**
402       * @attribute inh
403       * @aspect TypeHierarchyCheck
404       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:174
405       */
406      /**
407       * @attribute inh
408       * @aspect TypeHierarchyCheck
409       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:174
410       */
411      @ASTNodeAnnotation.Attribute
412      public TypeDecl enclosingExplicitConstructorHostType() {
413        TypeDecl enclosingExplicitConstructorHostType_value = getParent().Define_enclosingExplicitConstructorHostType(this, null);
414    
415        return enclosingExplicitConstructorHostType_value;
416      }
417      /**
418       * @apilevel internal
419       */
420      public ASTNode rewriteTo() {
421        return super.rewriteTo();
422      }
423    }