KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > cst > Scope


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.cst;
26
27 import org.aspectj.compiler.base.ast.*;
28 import org.aspectj.compiler.base.*;
29 import java.util.*;
30
31 /**
32  * captures the scope of var, meth and type declarations
33  *
34  */

35 public abstract class Scope extends CompilerObject {
36     private Scope parent;
37     
38     public Scope(JavaCompiler compiler, Scope parent) {
39         super(compiler);
40         this.parent = parent;
41     }
42     
43     
44     /**
45      * Returns the parent to be used by ScopeWalker for pushing and popping Scopes
46      */

47     public final Scope getStackParent() { return parent; }
48     
49     public Scope getParent() { return parent; }
50     
51     public void setStackParent(Scope p) { parent = p; }
52     
53     /**
54      * Finds the matching type for an unqualified type name.
55      */

56     public Type findType(String JavaDoc name, ASTObject fromWhere) {
57         return getParent().findType(name, fromWhere);
58     }
59
60     /**
61      * Returns a properly bound Expr for an unqualified name that appears in an
62      * expr position. Will return null if that's not possible.
63      */

64     public Expr bindUnqualifiedName(String JavaDoc name, ASTObject fromWhere) {
65         return getParent().bindUnqualifiedName(name, fromWhere);
66     }
67     
68     /**
69      * According to section 15.12.1 of JLS 2nd edition the rules for looking up an
70      * unqualified method name are that you find the first enclosing type that has
71      * a member with a matching name, and then you use the rules of applicability and
72      * accessibility in that type only to find the actual method.
73      *
74      * This method implements the first step in that process.
75      */

76     public Type findMethodLookupType(String JavaDoc name, ASTObject fromWhere) {
77         return getParent().findMethodLookupType(name, fromWhere);
78     }
79     
80     public String JavaDoc shortToString() { return "scope"; }
81     public String JavaDoc toString() {
82         String JavaDoc ret = this.shortToString();
83         if (getStackParent() != null) ret += "<-" + getStackParent().toString();
84         return ret;
85     }
86 }
87
Popular Tags