/* * Fernflower - The Analytical Java Decompiler * http://www.reversed-java.com * * (C) 2008 - 2010, Stiver * * This software is NEITHER public domain NOR free software * as per GNU License. See license.txt for more details. * * This software is distributed WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. */ package org.jetbrains.java.decompiler.struct.consts; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.modules.renamer.PoolInterceptor; import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor; import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor; import org.jetbrains.java.decompiler.struct.gen.VarType; public class ConstantPool { public static final int FIELD = 1; public static final int METHOD = 2; // ***************************************************************************** // private fields // ***************************************************************************** private List pool = new ArrayList(); private PoolInterceptor interceptor; // ***************************************************************************** // constructors // ***************************************************************************** public ConstantPool(DataInputStream in) throws IOException { int size = in.readUnsignedShort(); int[] pass = new int[size]; // first dummy constant pool.add(null); // first pass: read the elements for (int i = 1; i < size; i++) { byte tag = (byte)in.readUnsignedByte(); switch (tag) { case CodeConstants.CONSTANT_Utf8: pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Utf8, in.readUTF())); break; case CodeConstants.CONSTANT_Integer: pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Integer, new Integer(in.readInt()))); break; case CodeConstants.CONSTANT_Float: pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Float, new Float(in.readFloat()))); break; case CodeConstants.CONSTANT_Long: pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Long, new Long(in.readLong()))); pool.add(null); i++; break; case CodeConstants.CONSTANT_Double: pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Double, new Double(in.readDouble()))); pool.add(null); i++; break; case CodeConstants.CONSTANT_Class: case CodeConstants.CONSTANT_String: case CodeConstants.CONSTANT_MethodType: pool.add(new PrimitiveConstant(tag, in.readUnsignedShort())); pass[i] = 1; break; case CodeConstants.CONSTANT_Fieldref: case CodeConstants.CONSTANT_Methodref: case CodeConstants.CONSTANT_InterfaceMethodref: case CodeConstants.CONSTANT_NameAndType: case CodeConstants.CONSTANT_InvokeDynamic: pool.add(new LinkConstant(tag, in.readUnsignedShort(), in.readUnsignedShort())); if(tag == CodeConstants.CONSTANT_NameAndType) { pass[i] = 1; } else { pass[i] = 2; } break; case CodeConstants.CONSTANT_MethodHandle: pool.add(new LinkConstant(tag, in.readUnsignedByte(), in.readUnsignedShort())); pass[i] = 3; break; } } // resolving complex pool elements for(int pass_index = 1; pass_index <= 3; pass_index++) { for(int i = 1; i < size; i++) { if(pass[i] == pass_index) { pool.get(i).resolveConstant(this); } } } // get global constant pool interceptor instance, if any available interceptor = DecompilerContext.getPoolInterceptor(); } // ***************************************************************************** // public methods // ***************************************************************************** public void writeToOutputStream(DataOutputStream out) throws FileNotFoundException, IOException { out.writeShort(pool.size()); for(int i=1;i 0) { for(int i=0;i