KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
31
32 /**
33   */

34 public class ScopeWalker extends Walker {
35     public static void bindNames(ASTObject node, Scope topScope) {
36         new ScopeWalker(node.getCompiler(), topScope).process(node);
37     }
38
39     public Scope scope;
40
41     public ScopeWalker(JavaCompiler compiler) {
42         super(compiler);
43     }
44
45     public ScopeWalker(JavaCompiler compiler, Scope initialScope) {
46         this(compiler);
47         scope = initialScope;
48     }
49
50     public void enterCU(CompilationUnit cu) {
51         scope = new CUScope(getCompiler(), null, cu);
52     }
53 // //System.err.println("hygiene entered: " + cu);
54
// scope = new CUScope(getCompiler(), null, cu) {
55
// protected Type handleAmbiguousImport(String id, Type type1, Type type2, ASTObject showWhere) {
56
// return this.getTypeManager().TYPE_NOT_FOUND;
57
// }
58
// };
59
// }
60

61     public Scope getScope() { return scope; }
62
63     public void pushBlockScope() {
64         pushScope(new BlockScope(getCompiler(), null));
65     }
66
67     public void pushScope(Scope newScope) {
68         if (newScope.getStackParent() != null) {
69             throw new IllegalArgumentException JavaDoc("can't push a scope that already has a parent");
70         }
71         newScope.setStackParent(scope);
72         scope = newScope;
73     }
74
75     public void popScope() {
76         scope = scope.getStackParent();
77     }
78
79     /** enter a { */
80     public void pushBlock() {
81         if (scope instanceof BlockScope) ((BlockScope)scope).pushBlock();
82     }
83
84     /** exit a } */
85     public void popBlock() {
86         if (scope instanceof BlockScope) ((BlockScope)scope).popBlock();
87     }
88
89     public void addVarDec(VarDec varDec) {
90         if (scope instanceof BlockScope) ((BlockScope)scope).addVarDec(varDec);
91     }
92
93     public void addTypeDec(TypeDec typeDec) {
94         if (typeDec.getId().equals("ANONYMOUS")) return;
95
96         if (scope instanceof BlockScope) ((BlockScope)scope).addTypeDec(typeDec);
97     }
98
99     public void addMethodDec(MethodDec methodDec) { }
100
101     public ASTObject process(ASTObject object) {
102         //System.out.println("process " + object + " in " + scope);
103
object.preScope(this);
104         object.walkScope(this);
105         ASTObject ret = object.postScope(this);
106         //System.out.println("done with " + object + " in " + scope);
107
return ret;
108     }
109
110     private boolean walkBodies = true;
111     public boolean walkBodies() { return walkBodies; }
112     public void setWalkBodies(boolean b) { walkBodies = b; }
113
114     public boolean walkSignatures() { return true; }
115
116     public boolean useJavaScopes() { return false; }
117 }
118
Popular Tags