Remove exported everywhere.
[SquirrelJME.git] / modules / tool-classfile / src / main / java / net / multiphasicapps / classfile / LocalVariableTable.java
blob671a0b4d66c872c951b7eaf994a651d0b6403c21
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;
19 /**
20 * Represents a local variable table.
22 * @since 2022/09/21
24 public final class LocalVariableTable
25 implements Iterable<LocalVariableInfo>
27 /** The entries within the table. */
28 private final LocalVariableInfo[] _entries;
30 /**
31 * Initializes the local variable table.
33 * @param __vars the variables to use.
34 * @throws NullPointerException On null arguments.
35 * @since 2022/09/23
37 public LocalVariableTable(LocalVariableInfo... __vars)
38 throws NullPointerException
40 if (__vars == null)
41 throw new NullPointerException("NARG");
43 __vars = __vars.clone();
44 for (LocalVariableInfo var : __vars)
45 if (var == null)
46 throw new NullPointerException("NARG");
48 this._entries = __vars;
51 /**
52 * {@inheritDoc}
53 * @since 2022/09/23
55 @Override
56 public boolean equals(Object __o)
58 if (this == __o)
59 return true;
60 if (!(__o instanceof LocalVariableTable))
61 return false;
63 LocalVariableTable that = (LocalVariableTable)__o;
64 return Arrays.equals(this._entries, that._entries);
67 /**
68 * {@inheritDoc}
69 * @since 2022/09/23
71 @Override
72 public int hashCode()
74 return Arrays.asList(this._entries).hashCode();
77 /**
78 * {@inheritDoc}
79 * @since 2022/09/23
81 @Override
82 public Iterator<LocalVariableInfo> iterator()
84 return UnmodifiableIterator.of(this._entries);
87 /**
88 * Returns the number of entries within.
90 * @return The size of the table.
91 * @since 2022/09/23
93 public int size()
95 return this._entries.length;
98 /**
99 * {@inheritDoc}
100 * @since 2022/09/23
102 @Override
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.
116 * @since 2022/09/21
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");
127 if (attr == null)
128 return new LocalVariableTable();
130 // Parse data
131 try (DataInputStream in = attr.open())
133 // How many?
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);