KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* -*- Mode: Java; 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.super
33  * @child TypeD typeD
34  */

35
36 public class QualifiedSuperExpr extends SuperExpr {
37
38     public NameType getThisType() {
39         return (NameType) typeD.getType();
40     }
41
42     public void unparse(CodeWriter writer) {
43         writer.write(typeD.getType().getId());
44         writer.write(".super");
45     }
46
47     // ------------------------------
48
// INTRO from MemberClassMunger
49

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