package com.ninty.classfile.constantpool;

import java.nio.ByteBuffer;

/**
 * Created by ninty on 2017/7/9.
 */
public class ConstantPoolInfos {

    private ConstantInfo[] cps;

    public ConstantPoolInfos(ByteBuffer bb) {
        int len = bb.getChar();
        cps = new ConstantInfo[len - 1];

        for (int i = 0; i < cps.length; i++) {
            ConstantInfo cp = ConstantInfo.generate(this, bb);
            cps[i] = cp;
            if (cp instanceof ConstantInfo.CPFLong || cp instanceof ConstantInfo.CPDouble) {
                i++;
            }
        }
    }

    public ConstantInfo get(int index) {
        ConstantInfo ci = cps[index];
        if (ci == null) {
            throw new NullPointerException("cannot find constant index:" + index);
        }
        return ci;
    }

    public String getUtf8(int index) {
        return ((ConstantInfo.CPUtf8)get(index)).value;
    }
}


@@ -289,12 +289,8 @@
 %5Blen
- - 1
 %5D;%0A%0A
@@ -314,25 +314,18 @@
 i = 
-0
+1
 ; i %3C 
-cps.length
+len
 ; i+
@@ -562,31 +562,24 @@
 %0A    %7D%0A%0A    
-public 
 ConstantInfo
@@ -775,24 +775,292 @@
  ci;%0A    %7D%0A%0A
+    public String getClassName(int index)%7B%0A        return ((ConstantInfo.CPClass)get(index)).className();%0A    %7D%0A%0A    public String getSuperClassName(int index)%7B%0A        //java.lang.Object has no super class%0A        return index == 0 ? %22%22 : getClassName(index);%0A    %7D%0A%0A
     public S

fix cp length