KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > reflect > ArrayNew


1 package gnu.kawa.reflect;
2 import gnu.bytecode.*;
3 import gnu.mapping.*;
4 import gnu.expr.*;
5 import java.io.*;
6
7 public class ArrayNew extends Procedure1 implements Inlineable, Externalizable
8 {
9   Type element_type;
10
11   public ArrayNew (Type element_type)
12   {
13     this.element_type = element_type;
14   }
15
16   public Object JavaDoc apply1 (Object JavaDoc count)
17   {
18     return java.lang.reflect.Array.newInstance(element_type.getReflectClass(),
19                            ((Number JavaDoc) count).intValue());
20   }
21
22   public void compile (ApplyExp exp, Compilation comp, Target target)
23   {
24     exp.getArgs()[0].compile(comp, Type.int_type);
25     CodeAttr code = comp.getCode();
26     code.emitNewArray(element_type);
27     target.compileFromStack(comp, ArrayType.make(element_type));
28   }
29
30   public gnu.bytecode.Type getReturnType (Expression[] args)
31   {
32     return ArrayType.make(element_type);
33   }
34
35   public void writeExternal(ObjectOutput out) throws IOException
36   {
37     out.writeObject(element_type);
38   }
39
40   public void readExternal(ObjectInput in)
41     throws IOException, ClassNotFoundException JavaDoc
42   {
43     element_type = (Type) in.readObject();
44   }
45 }
46
Popular Tags