KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
30 import org.aspectj.compiler.base.cst.*;
31
32 /**
33  * @grammar ...
34  */

35 public abstract class TypeD extends ASTObject {
36     public abstract Type getType();
37
38     public String JavaDoc getString() {
39         return getType().getString();
40     }
41
42     public String JavaDoc toShortString() {
43         return getType().toShortString();
44     }
45
46     public void checkSpec() {
47         //showWarning("lex: " + toShortString());
48

49         //!!! a lot of caution here to avoid breaking things
50
if (fromSource() &&
51             getType() != null &&
52             !getType().isAnyType() &&
53             !getType().isMissing() &&
54             getType().getTypeDec() != null &&
55             !getType().getTypeDec().isAccessible(this)) {
56             showError("can't access " + getType().getTypeDec().toShortString());
57         }
58     }
59
60     //XXX want this to go away
61
public boolean isEquivalent(TypeD other) {
62         return getType().isEquivalent(other.getType());
63     }
64
65     private static final int UNQUALIFIED = 1;
66     private static final int FULLY_QUALIFIED = 0;
67     private static final int NULL_TRICK = 2;
68
69     private int unparseRule; // = FULLY_QUALIFIED;
70
private boolean checkedQualification = false;
71
72     void makePublic(TypeDec typeDec) {
73         //XXX
74
if (typeDec == null) return;
75
76         typeDec.getModifiers().setPublic(true);
77         if (typeDec.getEnclosingTypeDec() != null) {
78             makePublic(typeDec.getEnclosingTypeDec());
79         }
80     }
81
82
83     void makeAccessible(Type type, ASTObject fromWhere) {
84         //TypeDec fromTypeDec = fromWhere.getBytecodeTypeDec();
85
//getCompiler().showMessage(" isAccessible? " + type + " from " + fromTypeDec);
86
//if (fromTypeDec == null || type.getTypeDec() == null) return;
87

88         if (type.isAccessible(fromWhere, true)) return ;
89
90         getCompiler().showMessage(" fixing access to type: " + type.toShortString());
91
92         makePublic(type.getTypeDec());
93     }
94
95
96     //INTRO from NameHygienePass
97
public ASTObject postScope(ScopeWalker walker) {
98         if (!(walker instanceof NameHygienePass)) return this;
99
100         NameHygienePass pass = (NameHygienePass)walker;
101
102         //System.out.println("postHygeniene on " + this);
103

104         if (checkedQualification) {
105             //showError("already checked qualification");
106
//System.out.println("already checked qualification: " + getType());
107
unparseRule = FULLY_QUALIFIED;
108             return this;
109         }
110         checkedQualification = true;
111         makeAccessible(getType(), this);
112         if (getType().getTypeDec() != null && getType().getTypeDec().hasGlobalName()) {
113             Type checkType = getType().getOutermostType();
114
115             if (pass.canUseUnqualifiedName(checkType, this)) {
116                 unparseRule = UNQUALIFIED;
117             } else if (pass.mustUseNullTrick(checkType, this)) {
118                 unparseRule = NULL_TRICK;
119             } else {
120                 unparseRule = FULLY_QUALIFIED;
121             }
122         } else {
123             unparseRule = FULLY_QUALIFIED;
124         }
125         //System.out.println("--------->" + unparseRule);
126
return this;
127     }
128
129
130     public void unparse(CodeWriter writer) {
131         unparse(writer, false);
132     }
133
134     public void unparse(CodeWriter writer, boolean inExprPosition) {
135
136         Type type = getType();
137         int realUnparseRule = unparseRule;
138         if (!writer.isOnlySignatures()) {
139             if (!checkedQualification) {
140                 //showWarning("didn't check qualification: " + unparseRule + " type: " + getType());
141
//writer.write("/*!!!*/");
142
}
143         }
144
145         if (!inExprPosition && realUnparseRule == NULL_TRICK) {
146             realUnparseRule = FULLY_QUALIFIED;
147         }
148
149         switch (realUnparseRule) {
150             case UNQUALIFIED:
151                 writer.write(getType().getExtendedId().replace('$', '.'));
152                 break;
153             case FULLY_QUALIFIED:
154                 writer.write(getType().getString());
155                 break;
156             case NULL_TRICK:
157                 // this pattern is the only way that I know to trick Java into treating
158
// this as a type name
159
writer.write("((");
160                 writer.write(getType().getString());
161                 writer.write(")null)");
162                 break;
163         }
164     }
165     /*
166     private void writeTypeName(CodeWriter writer, String name, boolean inExprPosition) {
167         if (!inExprPosition) {
168             writer.write(name);
169             return;
170         }
171
172         String prefix = name;
173         int dot = prefix.indexOf('.');
174         if (dot != -1) prefix = prefix.substring(0, dot);
175
176         if (getContext().findVarDec(prefix, this) != null) {
177             // this pattern is the only way that I know to trick Java into treating
178             // this as a type name
179             writer.write("((");
180             writer.write(name);
181             writer.write(")null)");
182         } else {
183             writer.write(name);
184             return;
185         }
186     }
187     */

188
189     //BEGIN: Generated from @child and @property
190

191     public TypeD(SourceLocation location) {
192         super(location);
193
194     }
195
196
197     public String JavaDoc getDefaultDisplayName() {
198         return "TypeD()";
199     }
200
201     //END: Generated from @child and @property
202
}
203
Popular Tags