KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > functions > GetModuleClass


1 package gnu.kawa.functions;
2 import gnu.bytecode.*;
3 import gnu.mapping.*;
4 import gnu.expr.*;
5
6 /** Special procedure to get the Class of the current module.
7  * Since "current module" is defined by lexical scope,
8  * this isn't a first-class procedure - it has to be inlined.
9  */

10
11 public class GetModuleClass extends Procedure0
12   implements Inlineable
13 {
14   public static final GetModuleClass getModuleClass
15     = new GetModuleClass();
16
17   public Object JavaDoc apply0 ()
18   {
19     throw new Error JavaDoc("get-module-class must be inlined");
20   }
21
22   public void compile (ApplyExp exp, Compilation comp, Target target)
23   {
24     comp.loadClassRef(comp.mainClass);
25     target.compileFromStack(comp, ClassType.make("java.lang.Class"));
26   }
27
28   public gnu.bytecode.Type getReturnType (Expression[] args)
29   {
30     return ClassType.make("java.lang.Class");
31   }
32
33   private static String JavaDoc CLASS_RESOURCE_NAME = "$class_resource_URI$";
34
35   /** Return an expression that evaluates to a module-relative URI.
36    * This has the Kawa-specific URI scheme "class-resource:" and an
37    * assocatied ClassLoader (using a WekaHashMap). It used to reference
38    * resources located using the compiled class's ClassLoader. */

39   public static Expression getModuleClassURI (Compilation comp)
40   {
41     Declaration decl = comp.mainLambda.lookup(CLASS_RESOURCE_NAME);
42     if (decl == null)
43       {
44         comp.mustCompileHere();
45         decl = new Declaration(CLASS_RESOURCE_NAME);
46         decl.setFlag(Declaration.IS_CONSTANT|Declaration.STATIC_SPECIFIED);
47         Method maker = ClassType.make("gnu.text.URI_utils")
48           .getDeclaredMethod("makeClassResourceURI", 1);
49         Expression clas
50           = new ApplyExp(gnu.kawa.functions.GetModuleClass.getModuleClass,
51                          Expression.noExpressions);
52         decl.setValue(new ApplyExp(maker, new Expression[] { clas }));
53         comp.mainLambda.add(null, decl);
54       }
55     return new ReferenceExp(decl);
56   }
57 }
58
Popular Tags