package sds.classfile.attributes.stackmap;

import java.io.IOException;
import sds.classfile.ClassFileStream;

/**
 * This builder class is for {@link StackMapFrame <code>StackMapFrame</code>}.<br>
 * This class is designed singleton.
 * @author inagaki
 */
public class StackMapFrameBuilder {
	private static StackMapFrameBuilder builder = null;

	/**
	 * returns own instance.
	 * @return instance
	 */
	public static StackMapFrameBuilder getInstance() {
		if(builder == null) {
			builder = new StackMapFrameBuilder();
		}
		return builder;
 	}

	/**
	 * returns stack-map-frame.
	 * @param data classfile stream
	 * @return stack-map-frame
	 * @throws IOException
	 * @throws StackMapFrameException 
	 */
	public StackMapFrame build(ClassFileStream data)
	throws IOException, StackMapFrameException {
		int tag = data.readUnsignedByte();
		if(0 <= tag && tag <= 63) {
			return new SameFrame(StackMapFrameType.SameFrame, tag);
		} else if(64 <= tag && tag <= 127) {
			return new SameLocals1StackItemFrame(tag, data);
		} else if(128 <= tag && tag <= 246) {
			throw new StackMapFrameException(" the range of [128-246] is reserved for future use.");
		} else if(tag == 247) {
			return new SameLocals1StackItemFrameExtended(tag, data);
		} else if(248 <= tag && tag <= 250) {
			return new ChopFrame(StackMapFrameType.ChopFrame, tag, data);
		} else if(tag == 251) {
			return new SameFrameExtended(StackMapFrameType.SameFrameExtended, tag, data);
		} else if(252 <= tag && tag <= 254) {
			return new AppendFrame(tag, data);
		} else if(tag == 255) {
			return new FullFrame(tag, data);
		} else {
			throw new StackMapFrameException(tag);
		}
	}
}
@@ -697,16 +697,89 @@
 eption %0A
+%09 * @throws sds.classfile.attributes.stackmap.VerificationTypeException %0A
 %09 */%0A%09pu
@@ -868,16 +868,43 @@
 xception
+, VerificationTypeException
  %7B%0A%09%09int
@@ -1027,22 +1027,19 @@
 ag);%0A%09%09%7D
- else 
+%0A%09%09
 if(64 %3C=
@@ -1115,22 +1115,19 @@
 ta);%0A%09%09%7D
- else 
+%0A%09%09
 if(128 %3C
@@ -1240,30 +1240,27 @@
  use.%22);%0A%09%09%7D
- else 
+%0A%09%09
 if(tag == 24
@@ -1323,30 +1323,27 @@
 , data);%0A%09%09%7D
- else 
+%0A%09%09
 if(248 %3C= ta
@@ -1421,38 +1421,35 @@
  tag, data);%0A%09%09%7D
- else 
+%0A%09%09
 if(tag == 251) %7B
@@ -1533,22 +1533,19 @@
 ta);%0A%09%09%7D
- else 
+%0A%09%09
 if(252 %3C
@@ -1608,22 +1608,19 @@
 ta);%0A%09%09%7D
- else 
+%0A%09%09
 if(tag =
@@ -1671,17 +1671,9 @@
 %0A%09%09%7D
- else %7B%0A%09
+%0A
 %09%09th
@@ -1709,16 +1709,12 @@
 n(tag);%0A
-%09%09%7D%0A
 %09%7D%0A%7D

delete else block, and add exception to throws statement.