KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > CompilerObject


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;
26
27 import org.aspectj.compiler.base.ast.*;
28
29 /**
30  * To allow multiple compilers or for purposes of changing
31  * compiler mode (like change of classpath or incremental/non-incremental
32  * modes) we need to avoid usage of static fields in our classes,
33  * because the only other way (usage of custom ClassLoader) may
34  * conflict with different environment that uses AJ compiler
35  * (like IDE that have it's own ClassLoader and security policy).
36  *
37  * So, each object, that needs access to 'global' data - like
38  * compiler instance itself, compilation environment, type system
39  * and so on needs a reference to root object. The root object is
40  * the instance of compiler, that refers others instances of main
41  * objects - World, TypeManager and Options.
42  *
43  * This class - is an abstract superclass of each non-root object
44  * in our compiler, and it grants access to main objects and 'global'
45  * data through the compiler instance.
46  *
47  * Note: CompilerObject class is declared to be abstract to disable
48  * creation of instances of this class (even if it does not countaince
49  * abstract methods). Also, it's methods are declared to be 'final'
50  * to allow JIT compiler to inline them.
51  */

52
53 public abstract class CompilerObject {
54     /** The root of our 'global' data - the JavaCompiler instance */
55     private final JavaCompiler compiler;
56
57     /** The constructor of CompilerObject - requires compiler instance */
58     public CompilerObject(JavaCompiler compiler) {
59         this.compiler = compiler;
60     }
61
62     /** This method returns the compiler itself */
63     public final JavaCompiler getCompiler() {
64         return compiler;
65     }
66
67     /** This method returns World object - the root of
68      * misceleneous global data
69      */

70     public final World getWorld() {
71         return compiler.getWorld();
72     }
73
74     /** This method returns TypeManager object - the root
75      * of all defined and loaded types. It also includes
76      * set of primitive and core types, and is responsible
77      * for types creation and managment.
78      */

79     public final TypeManager getTypeManager() {
80         return compiler.getTypeManager();
81     }
82
83     /** This method returns current compiler settings (options) */
84     public final Options getOptions() {
85         return compiler.getOptions();
86     }
87     
88     private SourceLocation mySource;
89     
90     /** Convenience method for AST factory **/
91     public AST getAST() {
92         //XXX should be abstract
93
if (mySource == null) mySource = new DummySourceLocation(compiler);
94         return new AST(new SyntheticSourceLocation(this));
95     }
96 }
97
98
Popular Tags