KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > QualifiedThisExpr


1 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.*;
28
29 import org.aspectj.compiler.base.bcg.CodeBuilder;
30
31 /**
32  * @grammar typename.this
33  * @child TypeD typeD
34  */

35
36
37 //XXX Why does an AST need this subtype of ThisExpr?
38
public class QualifiedThisExpr extends ThisExpr {
39     public Type discoverType() {
40         return typeD.getType();
41     }
42
43     // INTRO from ASTFixerPass
44
public ASTObject postFixAST(final ASTFixerPass fixer) {
45         //??? This seems like an unavoidable issue with Java's rules for anonymous
46
//??? inners and name binding
47
// if (getType().getId().equals("ANONYMOUS")) {
48
// return null;
49
// }
50
return this;
51     }
52
53
54     public void unparse(CodeWriter writer) {
55         if (getBytecodeType() == getType()) {
56             writer.write("this");
57         } else {
58             writer.write(getType().getId());
59             writer.write(".this");
60         }
61     }
62
63     // ------------------------------
64
// INTRO from MemberClassMunger
65

66     public ASTObject walkMemberMunger(MemberClassMunger w) {
67         final AST ast = getAST();
68         NameType currentType = w.currentType();
69         NameType targetType = (NameType) getTypeD().getType();
70         if (currentType == targetType) {
71             return ast.makeThis(currentType);
72         } else {
73             CodeDec dec = getEnclosingCodeDec();
74             if (dec instanceof ConstructorDec) {
75                 ConstructorDec cdec = (ConstructorDec) dec;
76                 Expr seed = ast.makeVar(cdec.getEnclosingInstanceFormal());
77                 return w.buildExprFromEnclosing(seed, targetType);
78             } else {
79                 Expr seed = ast.makeThis(currentType);
80                 return w.buildExprFromThis(seed, targetType);
81             }
82         }
83     }
84
85     // ------------------------------
86
// bcg
87
protected void cgValue(CodeBuilder cb) {
88         throw new RuntimeException JavaDoc("Invalid expression " + this);
89     }
90
91     //BEGIN: Generated from @child and @property
92
protected TypeD typeD;
93     public TypeD getTypeD() { return typeD; }
94     public void setTypeD(TypeD _typeD) {
95         if (_typeD != null) _typeD.setParent(this);
96         typeD = _typeD;
97     }
98
99     public QualifiedThisExpr(SourceLocation location, TypeD _typeD) {
100         super(location);
101         setTypeD(_typeD);
102     }
103     protected QualifiedThisExpr(SourceLocation source) {
104         super(source);
105     }
106
107     public ASTObject copyWalk(CopyWalker walker) {
108         QualifiedThisExpr ret = new QualifiedThisExpr(getSourceLocation());
109         ret.preCopy(walker, this);
110         if (typeD != null) ret.setTypeD( (TypeD)walker.process(typeD) );
111         return ret;
112     }
113
114     public ASTObject getChildAt(int childIndex) {
115         switch(childIndex) {
116         case 0: return typeD;
117         default: return super.getChildAt(childIndex);
118         }
119     }
120      public String JavaDoc getChildNameAt(int childIndex) {
121         switch(childIndex) {
122         case 0: return "typeD";
123         default: return super.getChildNameAt(childIndex);
124         }
125     }
126      public void setChildAt(int childIndex, ASTObject child) {
127         switch(childIndex) {
128         case 0: setTypeD((TypeD)child); return;
129         default: super.setChildAt(childIndex, child); return;
130         }
131     }
132      public int getChildCount() {
133         return 1;
134     }
135
136     public String JavaDoc getDefaultDisplayName() {
137         return "QualifiedThisExpr()";
138     }
139
140     //END: Generated from @child and @property
141
}
142
Popular Tags