KickJava   Java API By Example, From Geeks To Geeks.

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


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.FlowCheckerPass;
28 import org.aspectj.compiler.base.JavaCompiler;
29 import org.aspectj.compiler.base.CodeWriter;
30
31 import org.aspectj.compiler.base.bcg.CodeBuilder;
32 import org.aspectj.compiler.base.bcg.Label;
33
34 /**
35  * @grammar typeD;
36  * @child TypeD typeD
37  */

38 public class TypeExpr extends Expr {
39     public Type discoverType() { return typeD.getType(); }
40
41     public void unparse(CodeWriter writer) {
42         //System.out.println("typeD: " + typeD);
43
typeD.unparse(writer, true);
44     }
45
46     public Expr makeReference() {
47         return (Expr)this.copy();
48     }
49
50     // ------------------------------
51
// Intro: from SpecChecker
52

53     // this is very similar to the test in TypeExpr
54
public void checkSpec() {
55         super.checkSpec();
56         // make sure the type is accessible from here
57
if (fromSource() && getType() != null &&
58             getType().getTypeDec() != null &&
59             !getType().getTypeDec().isAccessible(this)) {
60             showError("can't access " + getType().getTypeDec().toShortString());
61             return;
62         }
63
64         // we are only allowed in a limited number of places.
65
ASTObject self = this;
66         ASTObject parent = getParent();
67
68         // the check for the reverse pointer may not actually be necessary
69
while (true) {
70             if (parent instanceof Expr) {
71                 if (parent instanceof CallExpr) {
72                     if ((((CallExpr)parent).getExpr() == self)
73                         && ((CallExpr)parent).getMethod().isStatic()) return;
74                 } else if (parent instanceof FieldAccessExpr) {
75                     if ((((FieldAccessExpr)parent).getExpr() == self)
76                         && ((FieldAccessExpr)parent).getField().isStatic()) return;
77                 } else if (parent instanceof ParenExpr) {
78                     self = parent;
79                     parent = parent.getParent();
80                     continue;
81                 }
82             }
83             break;
84         }
85         showError("bad identifier");
86     }
87
88     // ------------------------------
89
// bcg
90

91     protected void cgValue(CodeBuilder cb) {}
92     protected void cgEffect(CodeBuilder cb) {}
93
94     //BEGIN: Generated from @child and @property
95
protected TypeD typeD;
96     public TypeD getTypeD() { return typeD; }
97     public void setTypeD(TypeD _typeD) {
98         if (_typeD != null) _typeD.setParent(this);
99         typeD = _typeD;
100     }
101
102     public TypeExpr(SourceLocation location, TypeD _typeD) {
103         super(location);
104         setTypeD(_typeD);
105     }
106     protected TypeExpr(SourceLocation source) {
107         super(source);
108     }
109
110     public ASTObject copyWalk(CopyWalker walker) {
111         TypeExpr ret = new TypeExpr(getSourceLocation());
112         ret.preCopy(walker, this);
113         if (typeD != null) ret.setTypeD( (TypeD)walker.process(typeD) );
114         return ret;
115     }
116
117     public ASTObject getChildAt(int childIndex) {
118         switch(childIndex) {
119         case 0: return typeD;
120         default: return super.getChildAt(childIndex);
121         }
122     }
123      public String JavaDoc getChildNameAt(int childIndex) {
124         switch(childIndex) {
125         case 0: return "typeD";
126         default: return super.getChildNameAt(childIndex);
127         }
128     }
129      public void setChildAt(int childIndex, ASTObject child) {
130         switch(childIndex) {
131         case 0: setTypeD((TypeD)child); return;
132         default: super.setChildAt(childIndex, child); return;
133         }
134     }
135      public int getChildCount() {
136         return 1;
137     }
138
139     public String JavaDoc getDefaultDisplayName() {
140         return "TypeExpr()";
141     }
142
143     //END: Generated from @child and @property
144
}
145
Popular Tags