1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net
.multiphasicapps
.classfile
;
12 import cc
.squirreljme
.runtime
.cldc
.debug
.Debugging
;
13 import cc
.squirreljme
.runtime
.cldc
.util
.UnmodifiableIterator
;
14 import java
.io
.DataInputStream
;
15 import java
.io
.IOException
;
16 import java
.util
.Arrays
;
17 import java
.util
.Iterator
;
20 * Represents a local variable table.
24 public final class LocalVariableTable
25 implements Iterable
<LocalVariableInfo
>
27 /** The entries within the table. */
28 private final LocalVariableInfo
[] _entries
;
31 * Initializes the local variable table.
33 * @param __vars the variables to use.
34 * @throws NullPointerException On null arguments.
37 public LocalVariableTable(LocalVariableInfo
... __vars
)
38 throws NullPointerException
41 throw new NullPointerException("NARG");
43 __vars
= __vars
.clone();
44 for (LocalVariableInfo var
: __vars
)
46 throw new NullPointerException("NARG");
48 this._entries
= __vars
;
56 public boolean equals(Object __o
)
60 if (!(__o
instanceof LocalVariableTable
))
63 LocalVariableTable that
= (LocalVariableTable
)__o
;
64 return Arrays
.equals(this._entries
, that
._entries
);
74 return Arrays
.asList(this._entries
).hashCode();
82 public Iterator
<LocalVariableInfo
> iterator()
84 return UnmodifiableIterator
.of(this._entries
);
88 * Returns the number of entries within.
90 * @return The size of the table.
95 return this._entries
.length
;
103 public String
toString()
105 return Arrays
.asList(this._entries
).toString();
109 * Parses the local variable tables.
111 * @param __pool The pool used.
112 * @param __attrs The attributes to read from.
113 * @return The resultant local variable table.
114 * @throws IOException On read errors.
115 * @throws NullPointerException On null arguments.
118 public static LocalVariableTable
parse(Pool __pool
,
119 AttributeTable __attrs
)
120 throws IOException
, NullPointerException
122 if (__pool
== null || __attrs
== null)
123 throw new NullPointerException("NARG");
125 // Get the table if it exists
126 Attribute attr
= __attrs
.get("LocalVariableTable");
128 return new LocalVariableTable();
131 try (DataInputStream in
= attr
.open())
134 int count
= in
.readUnsignedShort();
136 // Setup and load each one
137 LocalVariableInfo
[] result
= new LocalVariableInfo
[count
];
138 for (int i
= 0; i
< count
; i
++)
139 result
[i
] = new LocalVariableInfo(
140 in
.readUnsignedShort(),
141 in
.readUnsignedShort(),
142 new FieldName(__pool
.require(UTFConstantEntry
.class,
143 in
.readUnsignedShort()).toString()),
144 new FieldDescriptor(__pool
.require(UTFConstantEntry
.class,
145 in
.readUnsignedShort()).toString()),
146 in
.readUnsignedShort());
148 return new LocalVariableTable(result
);