package sds.classfile.attributes;

import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author inagaki
 */
public class LineNumberTable extends AttributeInfo {
	/**
	 * array of line number table.
	 */
	LNTable[] lineNumberTable;

	/**
	 * 
	 * @param nameIndex
	 * @param length 
	 */
	public LineNumberTable(int nameIndex, int length) {
		super(AttributeType.LineNumberTable, nameIndex, length);
	}

	/**
	 * 
	 * @return 
	 */
	public LNTable[] getLineNumberTable() {
		return lineNumberTable;
	}

	@Override
	public void read(RandomAccessFile raf) throws IOException {
		this.lineNumberTable = new LNTable[raf.readShort()];
		for(int i = 0; i < lineNumberTable.length; i++) {
			lineNumberTable[i] = new LNTable(raf);
		}
	}

	/**
	 * 
	 */
	public class LNTable {
		/**
		 * start number of opcode.
		 */
		int startPc;
		/**
		 * line number in source file.
		 */
		int lineNumber;

		/**
		 * 
		 * @param startPc
		 * @param lineNumber 
		 */
		LNTable(RandomAccessFile raf) throws IOException {
			this.startPc = raf.readShort();
			this.lineNumber = raf.readShort();
		}

		public int getStartPc() {
			return startPc;
		}

		public int getLineNumber() {
			return lineNumber;
		}
	}
}

@@ -735,16 +735,177 @@
 e(raf);%0A
+%09%09%09if(i == lineNumberTable.length-1) %7B%0A%09%09%09%09lineNumberTable%5Bi%5D.endPc = 0;%0A%09%09%09%7D else if(i %3E 0) %7B%0A%09%09%09%09lineNumberTable%5Bi-1%5D.endPc = lineNumberTable%5Bi%5D.startPc;%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A
@@ -1001,24 +1001,55 @@
 rtPc;%0A%09%09/**%0A
+%09%09 * %0A%09%09 */%0A%09%09int endPc;%0A%09%09/**%0A
 %09%09 * line nu
@@ -1391,18 +1391,66 @@
 eNumber;%0A%09%09%7D
+%0A%0A%09%09public int getEndPc() %7B%0A%09%09%09return endPc;%0A%09%09%7D
 %0A%09%7D%0A%7D%0A

add 'endPc'.