KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.compiler.base.cst.*;
29
30 /**
31   * @grammar import name(.*)?
32   * @property Name typeName
33   * @property boolean star
34   */

35
36 public class Import extends ASTObject {
37
38     public void checkSpec() {
39         if (!getStar()) {
40             getType();
41         } else {
42             //!!! validate that the package exists
43
}
44     }
45
46     public boolean capturesId(String JavaDoc id) {
47         return typeName.getId().equals(id);
48     }
49
50     public Scope makeTypeNameScope() {
51         return new Scope(getCompiler(), null) {
52                 public Type findType(String JavaDoc name, ASTObject fromWhere) {
53                     return this.getTypeManager().findType(null, name);
54                 }
55                 public Expr bindUnqualifiedName(String JavaDoc name, ASTObject fromWhere) {
56                     return null;
57                 }
58             };
59     }
60
61     private Type myType = null;
62     public Type getType() {
63         if (myType == null) {
64             myType = typeName.resolveType(makeTypeNameScope());
65
66             if (myType == null) {
67                 showError("type not found");
68             } else if (getOptions().strict) {
69                 if (myType.getPackageName() == null) {
70                     showError("import from default package not allowed");
71                 }
72             }
73         }
74
75         return myType;
76     }
77
78     public String JavaDoc getName() {
79         return typeName.toString();
80     }
81
82     public void unparse(CodeWriter writer) {
83         writer.writeKeyword("import");
84         writer.requiredSpace();
85         writer.write(typeName.toString());
86         if (star) writer.write(".*");
87         writer.closeStmt();
88         writer.newLine();
89     }
90
91     //BEGIN: Generated from @child and @property
92
protected Name typeName;
93     public Name getTypeName() { return typeName; }
94     public void setTypeName(Name _typeName) { typeName = _typeName; }
95
96     protected boolean star;
97     public boolean getStar() { return star; }
98     public void setStar(boolean _star) { star = _star; }
99
100     public Import(SourceLocation location, Name _typeName, boolean _star) {
101         super(location);
102         setTypeName(_typeName);
103         setStar(_star);
104     }
105     protected Import(SourceLocation source) {
106         super(source);
107     }
108
109     public ASTObject copyWalk(CopyWalker walker) {
110         Import ret = new Import(getSourceLocation());
111         ret.preCopy(walker, this);
112         ret.typeName = typeName;
113         ret.star = star;
114         return ret;
115     }
116
117
118     public String JavaDoc getDefaultDisplayName() {
119         return "Import(typeName: "+typeName+", "+"star: "+star+")";
120     }
121
122     //END: Generated from @child and @property
123
}
124
Popular Tags