package com.github.jvmgo.classfile.constantpool;

import com.github.jvmgo.Main;
import com.github.jvmgo.classfile.ClassReader;

public interface ConstantInfo {

    int CONST_TAG_CLASS = 7;
    int CONST_TAG_FIELD_REF = 9;
    int CONST_TAG_METHOD_REF = 10;
    int CONST_TAG_INTERFACE_MTTHOD_REF = 11;
    int CONST_TAG_STRING = 8;
    int CONST_TAG_INTEGER = 3;
    int CONST_TAG_FLOAT = 4;
    int CONST_TAG_LONG = 5;
    int CONST_TAG_DOUBLE = 6;
    int CONST_TAG_NAME_AND_TYPE = 12;
    int CONST_TAG_UTF8 = 1;
    int CONST_TAG_METHOD_HANDLE = 15;
    int CONST_TAG_METHOD_TYPE = 16;
    int CONST_TAG_INVOKE_DYNAMIC = 18;


    String getValue();


    //Factory method
    static ConstantInfo createConstantInfo(int tag, ClassReader reader, ConstantPool constPool) {

        ConstantInfo constantInfo = null;

        switch (tag) {

            //数字
            case CONST_TAG_INTEGER:
                constantInfo = new ConstantIntegerInfo(reader);
                break;
            case CONST_TAG_FLOAT:
                constantInfo = new ConstantFloatInfo(reader);
                break;
            case CONST_TAG_LONG:
                constantInfo = new ConstantLongInfo(reader);
                break;
            case CONST_TAG_DOUBLE:
                constantInfo = new ConstantDoubleInfo(reader);
                break;

            case CONST_TAG_UTF8:
                constantInfo = new ConstUft8Info(reader);
                break;

            //以下3个引用UTF8
            case CONST_TAG_STRING:
                constantInfo = new ConstStringInfo(constPool, reader);
                break;
            case CONST_TAG_CLASS:
                constantInfo = new ConstClassInfo(constPool, reader);
                break;
            case CONST_TAG_NAME_AND_TYPE:
                constantInfo = new ConstantNameAndTypeInfo(constPool, reader);
                break;

            //以下3个引用CLASS+NAME_AND_TYPE
            case CONST_TAG_FIELD_REF:
                constantInfo = new ConstantMemberrefInfo(constPool, reader);
                break;
            case CONST_TAG_METHOD_REF:
                constantInfo = new ConstantMemberrefInfo(constPool, reader);
                break;
            case CONST_TAG_INTERFACE_MTTHOD_REF:
                constantInfo = new ConstantMemberrefInfo(constPool, reader);
                break;

            //是Java SE 7才添加到class文件中的，目的是支持新增的invokedynamic指令
            case CONST_TAG_METHOD_HANDLE:
                constantInfo = null;
                break;
            case CONST_TAG_METHOD_TYPE:
                constantInfo = null;
                break;
            case CONST_TAG_INVOKE_DYNAMIC:
                constantInfo = null;
                break;

            default:
                Main.panic("java.lang.ClassFormatError: constant poll tag!");
                break;
        }

        return constantInfo;
    }

}

@@ -47,38 +47,8 @@
 l;%0A%0A
-import com.github.jvmgo.Main;%0A
 impo
@@ -743,52 +743,8 @@
 ) %7B%0A
-%0A        ConstantInfo constantInfo = null;%0A%0A
     
@@ -762,17 +762,16 @@
 (tag) %7B%0A
-%0A
         
@@ -827,38 +827,30 @@
             
-constantInfo =
+return
  new Constan
@@ -871,39 +871,16 @@
 eader);%0A
-                break;%0A
         
@@ -917,38 +917,30 @@
             
-constantInfo =
+return
  new Constan
@@ -959,39 +959,16 @@
 eader);%0A
-                break;%0A
         
@@ -1004,38 +1004,30 @@
             
-constantInfo =
+return
  new Constan
@@ -1045,39 +1045,16 @@
 eader);%0A
-                break;%0A
         
@@ -1092,38 +1092,30 @@
             
-constantInfo =
+return
  new Constan
@@ -1134,39 +1134,16 @@
 reader);
-%0A                break;
 %0A%0A      
@@ -1181,38 +1181,30 @@
             
-constantInfo =
+return
  new ConstUf
@@ -1218,39 +1218,16 @@
 reader);
-%0A                break;
 %0A%0A      
@@ -1292,38 +1292,30 @@
             
-constantInfo =
+return
  new ConstSt
@@ -1343,39 +1343,16 @@
 eader);%0A
-                break;%0A
         
@@ -1389,38 +1389,30 @@
             
-constantInfo =
+return
  new ConstCl
@@ -1439,39 +1439,16 @@
 eader);%0A
-                break;%0A
         
@@ -1493,38 +1493,30 @@
             
-constantInfo =
+return
  new Constan
@@ -1551,39 +1551,16 @@
 reader);
-%0A                break;
 %0A%0A      
@@ -1643,38 +1643,30 @@
             
-constantInfo =
+return
  new Constan
@@ -1700,39 +1700,16 @@
 eader);%0A
-                break;%0A
         
@@ -1751,38 +1751,30 @@
             
-constantInfo =
+return
  new Constan
@@ -1808,39 +1808,16 @@
 eader);%0A
-                break;%0A
         
@@ -1873,30 +1873,22 @@
         
-constantInfo =
+return
  new Con
@@ -1925,39 +1925,16 @@
 reader);
-%0A                break;
 %0A%0A      
@@ -2051,50 +2051,19 @@
     
-constantInfo = null;%0A                break
+return null
 ;%0A  
@@ -2120,50 +2120,19 @@
     
-constantInfo = null;%0A                break
+return null
 ;%0A  
@@ -2192,50 +2192,19 @@
     
-constantInfo = null;%0A                break
+return null
 ;%0A%0A 
@@ -2243,30 +2243,18 @@
     
-Main.panic(%22java.lang.
+throw new 
 Clas
@@ -2269,10 +2269,10 @@
 rror
-: 
+(%22
 cons
@@ -2278,17 +2278,17 @@
 stant po
-l
+o
 l tag!%22)
@@ -2301,62 +2301,9 @@
     
-        break;%0A        %7D%0A%0A        return constantInfo;
+%7D
 %0A   

simplify ConstantInfo