From 076e4393f25bf1ad1ff1bd2853153e2b595dd90b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 28 Aug 2014 21:34:14 +0400 Subject: java-decompiler: post-import cleanup (formatting and copyright) --- .../decompiler/struct/consts/ConstantPool.java | 602 +++++++++++---------- .../decompiler/struct/consts/LinkConstant.java | 283 +++++----- .../decompiler/struct/consts/PooledConstant.java | 189 +++---- .../struct/consts/PrimitiveConstant.java | 218 ++++---- .../decompiler/struct/consts/VariableTypeEnum.java | 74 +-- 5 files changed, 688 insertions(+), 678 deletions(-) (limited to 'src/org/jetbrains/java/decompiler/struct/consts') diff --git a/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java b/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java index 8951cd1..5a593af 100644 --- a/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java +++ b/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java @@ -1,26 +1,20 @@ /* - * Fernflower - The Analytical Java Decompiler - * http://www.reversed-java.com + * Copyright 2000-2014 JetBrains s.r.o. * - * (C) 2008 - 2010, Stiver + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This software is NEITHER public domain NOR free software - * as per GNU License. See license.txt for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This software is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - 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; @@ -28,289 +22,297 @@ import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor; import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor; import org.jetbrains.java.decompiler.struct.gen.VarType; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + 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 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 < pool.size(); i++) { + PooledConstant cnst = (PooledConstant)pool.get(i); + if (cnst != null) { + cnst.writeToStream(out); + } + } + } + + public static void skipPool(DataInputStream in) throws IOException { + + int size = in.readUnsignedShort(); + + for (int i = 1; i < size; i++) { + switch (in.readUnsignedByte()) { + case CodeConstants.CONSTANT_Utf8: + in.readUTF(); + break; + case CodeConstants.CONSTANT_Integer: + case CodeConstants.CONSTANT_Float: + case CodeConstants.CONSTANT_Fieldref: + case CodeConstants.CONSTANT_Methodref: + case CodeConstants.CONSTANT_InterfaceMethodref: + case CodeConstants.CONSTANT_NameAndType: + case CodeConstants.CONSTANT_InvokeDynamic: + in.skip(4); + break; + case CodeConstants.CONSTANT_Long: + case CodeConstants.CONSTANT_Double: + in.skip(8); + i++; + break; + case CodeConstants.CONSTANT_Class: + case CodeConstants.CONSTANT_String: + case CodeConstants.CONSTANT_MethodType: + in.skip(2); + break; + case CodeConstants.CONSTANT_MethodHandle: + in.skip(3); + } + } + } + + public int size() { + return pool.size(); + } + + public String[] getClassElement(int element_type, int class_index, int name_index, int descriptor_index) { + + String classname = ((PrimitiveConstant)getConstant(class_index)).getString(); + String elementname = ((PrimitiveConstant)getConstant(name_index)).getString(); + String descriptor = ((PrimitiveConstant)getConstant(descriptor_index)).getString(); + + if (interceptor != null) { + String new_element = interceptor.getName(classname + " " + elementname + " " + descriptor); + + if (new_element != null) { + elementname = new_element.split(" ")[1]; + } + + String new_descriptor = buildNewDescriptor(element_type == FIELD ? CodeConstants.CONSTANT_Fieldref : CodeConstants.CONSTANT_Methodref, + descriptor); + if (new_descriptor != null) { + descriptor = new_descriptor; + } + } + + return new String[]{elementname, descriptor}; + } + + public PooledConstant getConstant(int index) { + return pool.get(index); + } + + public PrimitiveConstant getPrimitiveConstant(int index) { + PrimitiveConstant cn = (PrimitiveConstant)getConstant(index); + + if (cn != null && interceptor != null) { + if (cn.type == CodeConstants.CONSTANT_Class) { + String newname = buildNewClassname(cn.getString()); + if (newname != null) { + cn = new PrimitiveConstant(CodeConstants.CONSTANT_Class, newname); + } + } + } + + return cn; + } + + public LinkConstant getLinkConstant(int index) { + LinkConstant ln = (LinkConstant)getConstant(index); + + if (ln != null && interceptor != null) { + if (ln.type == CodeConstants.CONSTANT_Fieldref || + ln.type == CodeConstants.CONSTANT_Methodref || + ln.type == CodeConstants.CONSTANT_InterfaceMethodref) { + + String new_classname = buildNewClassname(ln.classname); + String new_element = interceptor.getName(ln.classname + " " + ln.elementname + " " + ln.descriptor); + String new_descriptor = buildNewDescriptor(ln.type, ln.descriptor); + + if (new_classname != null || new_element != null || new_descriptor != null) { + + ln = new LinkConstant(ln.type, new_classname == null ? ln.classname : new_classname, + new_element == null ? ln.elementname : new_element.split(" ")[1], + new_descriptor == null ? ln.descriptor : new_descriptor); + } + } + } + + return ln; + } + + private String buildNewClassname(String classname) { + + VarType vt = new VarType(classname, true); + + String newname = interceptor.getName(vt.value); + if (newname != null) { + StringBuilder buffer = new StringBuilder(); + + if (vt.arraydim > 0) { + for (int i = 0; i < vt.arraydim; i++) { + buffer.append("["); + } + + buffer.append("L" + newname + ";"); + } + else { + buffer.append(newname); + } + + return buffer.toString(); + } + + return null; + } + + private String buildNewDescriptor(int type, String descriptor) { + + boolean updated = false; + + if (type == CodeConstants.CONSTANT_Fieldref) { + FieldDescriptor fd = FieldDescriptor.parseDescriptor(descriptor); + + VarType ftype = fd.type; + if (ftype.type == CodeConstants.TYPE_OBJECT) { + String newclname = buildNewClassname(ftype.value); + if (newclname != null) { + ftype.value = newclname; + updated = true; + } + } + + if (updated) { + return fd.getDescriptor(); + } + } + else { + + MethodDescriptor md = MethodDescriptor.parseDescriptor(descriptor); + // params + for (VarType partype : md.params) { + if (partype.type == CodeConstants.TYPE_OBJECT) { + String newclname = buildNewClassname(partype.value); + if (newclname != null) { + partype.value = newclname; + updated = true; + } + } + } + + // return value + if (md.ret.type == CodeConstants.TYPE_OBJECT) { + String newclname = buildNewClassname(md.ret.value); + if (newclname != null) { + md.ret.value = newclname; + updated = true; + } + } + + if (updated) { + return md.getDescriptor(); + } + } + + return null; + } } diff --git a/src/org/jetbrains/java/decompiler/struct/consts/LinkConstant.java b/src/org/jetbrains/java/decompiler/struct/consts/LinkConstant.java index 770a5e3..c20b5af 100644 --- a/src/org/jetbrains/java/decompiler/struct/consts/LinkConstant.java +++ b/src/org/jetbrains/java/decompiler/struct/consts/LinkConstant.java @@ -1,17 +1,18 @@ /* - * Fernflower - The Analytical Java Decompiler - * http://www.reversed-java.com + * Copyright 2000-2014 JetBrains s.r.o. * - * (C) 2008 - 2010, Stiver + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This software is NEITHER public domain NOR free software - * as per GNU License. See license.txt for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This software is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - package org.jetbrains.java.decompiler.struct.consts; import java.io.DataOutputStream; @@ -24,136 +25,142 @@ import java.io.IOException; public class LinkConstant extends PooledConstant { - // ***************************************************************************** - // public fields - // ***************************************************************************** - - public int index1, index2; - - public String classname; - - public String elementname; - - public String descriptor; - - public int paramCount = 0; - - public boolean isVoid = false;; - - public boolean returnCategory2 = false; - - - // ***************************************************************************** - // constructors - // ***************************************************************************** - - public LinkConstant(int type, String classname, String elementname, String descriptor) { - this.type = type; - this.classname = classname; - this.elementname = elementname; - this.descriptor = descriptor; - - initConstant(); - } - - public LinkConstant(int type, int index1, int index2) { - this.type = type; - this.index1 = index1; - this.index2 = index2; - } - - - // ***************************************************************************** - // public methods - // ***************************************************************************** - - public void resolveConstant(ConstantPool pool) { - - if(type == CONSTANT_NameAndType) { - elementname = pool.getPrimitiveConstant(index1).getString(); - descriptor = pool.getPrimitiveConstant(index2).getString(); - } else if(type == CONSTANT_MethodHandle) { - LinkConstant ref_info = pool.getLinkConstant(index2); - - classname = ref_info.classname; - elementname = ref_info.elementname; - descriptor = ref_info.descriptor; - - } else { - if(type != CONSTANT_InvokeDynamic) { - classname = pool.getPrimitiveConstant(index1).getString(); - } - - LinkConstant nametype = pool.getLinkConstant(index2); - elementname = nametype.elementname; - descriptor = nametype.descriptor; - } - - initConstant(); - } - - public void writeToStream(DataOutputStream out) throws IOException { - out.writeByte(type); - if(type == CONSTANT_MethodHandle) { - out.writeByte(index1); - } else { - out.writeShort(index1); - } - out.writeShort(index2); - } - - - public boolean equals(Object o) { - if(o == this) return true; - if(o == null || !(o instanceof LinkConstant)) return false; - - LinkConstant cn = (LinkConstant)o; + // ***************************************************************************** + // public fields + // ***************************************************************************** + + public int index1, index2; + + public String classname; + + public String elementname; + + public String descriptor; + + public int paramCount = 0; + + public boolean isVoid = false; + ; + + public boolean returnCategory2 = false; + + + // ***************************************************************************** + // constructors + // ***************************************************************************** + + public LinkConstant(int type, String classname, String elementname, String descriptor) { + this.type = type; + this.classname = classname; + this.elementname = elementname; + this.descriptor = descriptor; + + initConstant(); + } + + public LinkConstant(int type, int index1, int index2) { + this.type = type; + this.index1 = index1; + this.index2 = index2; + } + + + // ***************************************************************************** + // public methods + // ***************************************************************************** + + public void resolveConstant(ConstantPool pool) { + + if (type == CONSTANT_NameAndType) { + elementname = pool.getPrimitiveConstant(index1).getString(); + descriptor = pool.getPrimitiveConstant(index2).getString(); + } + else if (type == CONSTANT_MethodHandle) { + LinkConstant ref_info = pool.getLinkConstant(index2); + + classname = ref_info.classname; + elementname = ref_info.elementname; + descriptor = ref_info.descriptor; + } + else { + if (type != CONSTANT_InvokeDynamic) { + classname = pool.getPrimitiveConstant(index1).getString(); + } + + LinkConstant nametype = pool.getLinkConstant(index2); + elementname = nametype.elementname; + descriptor = nametype.descriptor; + } + + initConstant(); + } + + public void writeToStream(DataOutputStream out) throws IOException { + out.writeByte(type); + if (type == CONSTANT_MethodHandle) { + out.writeByte(index1); + } + else { + out.writeShort(index1); + } + out.writeShort(index2); + } + + + public boolean equals(Object o) { + if (o == this) return true; + if (o == null || !(o instanceof LinkConstant)) return false; + + LinkConstant cn = (LinkConstant)o; return this.type == cn.type && - this.elementname.equals(cn.elementname) && - this.descriptor.equals(cn.descriptor) && - (this.type != CONSTANT_NameAndType || this.classname.equals(cn.classname)); + this.elementname.equals(cn.elementname) && + this.descriptor.equals(cn.descriptor) && + (this.type != CONSTANT_NameAndType || this.classname.equals(cn.classname)); + } + + // ***************************************************************************** + // private methods + // ***************************************************************************** + + private void initConstant() { + + if (type == CONSTANT_Methodref || + type == CONSTANT_InterfaceMethodref || + type == CONSTANT_InvokeDynamic || + type == CONSTANT_MethodHandle) { + resolveDescriptor(descriptor); + } + else if (type == CONSTANT_Fieldref) { + returnCategory2 = ("D".equals(descriptor) || "J".equals(descriptor)); + } + } + + private void resolveDescriptor(String descr) { + + String[] arr = descr.split("[()]"); + String par = arr[1]; + + int index = 0, counter = 0; + int len = par.length(); + + while (index < len) { + + char c = par.charAt(index); + if (c == 'L') { + index = par.indexOf(";", index); + } + else if (c == '[') { + index++; + continue; + } + + counter++; + index++; + } + + paramCount = counter; + isVoid = "V".equals(arr[2]); + returnCategory2 = ("D".equals(arr[2]) || "J".equals(arr[2])); } - - // ***************************************************************************** - // private methods - // ***************************************************************************** - - private void initConstant() { - - if(type == CONSTANT_Methodref || type == CONSTANT_InterfaceMethodref || type == CONSTANT_InvokeDynamic || type == CONSTANT_MethodHandle) { - resolveDescriptor(descriptor); - } else if(type == CONSTANT_Fieldref) { - returnCategory2 = ("D".equals(descriptor) || "J".equals(descriptor)); - } - - } - - private void resolveDescriptor(String descr){ - - String[] arr = descr.split("[()]"); - String par = arr[1]; - - int index = 0, counter = 0; - int len = par.length(); - - while(index ldc class - return REFERENCE; - default: - throw new RuntimeException("Huh?? What are you trying to load?"); - } - } - - public Object getValue(int index){ - return values[index]; - } - - - // ***************************************************************************** - // getter and setter methods - // ***************************************************************************** - - public Object[] getValues() { - return values; - } - - public void setValues(Object[] values) { - this.values = values; - } + // ***************************************************************************** + // public fields + // ***************************************************************************** + + public int type; + + public boolean own = false; + + public int returnType; + + + // ***************************************************************************** + // private fields + // ***************************************************************************** + + private Object[] values; + + // ***************************************************************************** + // constructors + // ***************************************************************************** + + public PooledConstant() { + } + + public PooledConstant(int type, Object[] values) { + this.type = type; + this.values = values; + this.returnType = poolTypeToIntern(type); + } + + public PooledConstant(int type, boolean own, Object[] values) { + this.type = type; + this.own = own; + this.values = values; + this.returnType = poolTypeToIntern(type); + } + + // ***************************************************************************** + // public methods + // ***************************************************************************** + + public void resolveConstant(ConstantPool pool) { + // to be overwritten + } + + public void writeToStream(DataOutputStream out) throws IOException { + // to be overwritten + } + + public int poolTypeToIntern(int type) { + + switch (type) { + case CONSTANT_Integer: + return INT; + case CONSTANT_Float: + return FLOAT; + case CONSTANT_Long: + return LONG; + case CONSTANT_Double: + return DOUBLE; + case CONSTANT_String: + case CONSTANT_Class: // 1.5 -> ldc class + return REFERENCE; + default: + throw new RuntimeException("Huh?? What are you trying to load?"); + } + } + + public Object getValue(int index) { + return values[index]; + } + + + // ***************************************************************************** + // getter and setter methods + // ***************************************************************************** + + public Object[] getValues() { + return values; + } + public void setValues(Object[] values) { + this.values = values; + } } diff --git a/src/org/jetbrains/java/decompiler/struct/consts/PrimitiveConstant.java b/src/org/jetbrains/java/decompiler/struct/consts/PrimitiveConstant.java index f01a695..4cd4dd8 100644 --- a/src/org/jetbrains/java/decompiler/struct/consts/PrimitiveConstant.java +++ b/src/org/jetbrains/java/decompiler/struct/consts/PrimitiveConstant.java @@ -1,17 +1,18 @@ /* - * Fernflower - The Analytical Java Decompiler - * http://www.reversed-java.com + * Copyright 2000-2014 JetBrains s.r.o. * - * (C) 2008 - 2010, Stiver + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This software is NEITHER public domain NOR free software - * as per GNU License. See license.txt for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This software is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - package org.jetbrains.java.decompiler.struct.consts; import java.io.DataOutputStream; @@ -23,104 +24,103 @@ import java.io.IOException; public class PrimitiveConstant extends PooledConstant { - // ***************************************************************************** - // public fields - // ***************************************************************************** - - public int index; - - public Object value; - - public boolean isArray; - - // ***************************************************************************** - // constructors - // ***************************************************************************** - - public PrimitiveConstant(int type, Object value) { - this.type = type; - this.value = value; - - initConstant(); - } - - public PrimitiveConstant(int type, int index) { - this.type = type; - this.index = index; - } - - // ***************************************************************************** - // public methods - // ***************************************************************************** - - public int getInt() { - return ((Integer)value).intValue(); - } - - public long getLong() { - return ((Long)value).longValue(); - } - - public float getFloat() { - return ((Float)value).floatValue(); - } - - public double getDouble() { - return ((Double)value).doubleValue(); - } - - public String getString() { - return (String)value; - } - - public void resolveConstant(ConstantPool pool) { - - if(type == CONSTANT_Class || type == CONSTANT_String || type == CONSTANT_MethodType) { - value = pool.getPrimitiveConstant(index).getString(); - initConstant(); - } - } - - public void writeToStream(DataOutputStream out) throws IOException { - - out.writeByte(type); - switch(type) { - case CONSTANT_Integer: - out.writeInt(getInt()); - break; - case CONSTANT_Float: - out.writeFloat(getFloat()); - break; - case CONSTANT_Long: - out.writeLong(getLong()); - break; - case CONSTANT_Double: - out.writeDouble(getDouble()); - break; - case CONSTANT_Utf8: - out.writeUTF(getString()); - break; - default: // CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType - out.writeShort(index); - } - } - - public boolean equals(Object o) { - if(o == this) return true; - if(o == null || !(o instanceof PrimitiveConstant)) return false; - - PrimitiveConstant cn = (PrimitiveConstant)o; - return this.type == cn.type && - this.isArray == cn.isArray && - this.value.equals(cn.value); - - } - - private void initConstant() { - if(type == CONSTANT_Class) { - String className = getString(); - isArray = (className.length() > 0 && className.charAt(0)=='['); // empty string for a class name seems to be possible in some android files - } - } - + // ***************************************************************************** + // public fields + // ***************************************************************************** + + public int index; + + public Object value; + + public boolean isArray; + + // ***************************************************************************** + // constructors + // ***************************************************************************** + + public PrimitiveConstant(int type, Object value) { + this.type = type; + this.value = value; + + initConstant(); + } + + public PrimitiveConstant(int type, int index) { + this.type = type; + this.index = index; + } + + // ***************************************************************************** + // public methods + // ***************************************************************************** + + public int getInt() { + return ((Integer)value).intValue(); + } + + public long getLong() { + return ((Long)value).longValue(); + } + + public float getFloat() { + return ((Float)value).floatValue(); + } + + public double getDouble() { + return ((Double)value).doubleValue(); + } + + public String getString() { + return (String)value; + } + + public void resolveConstant(ConstantPool pool) { + + if (type == CONSTANT_Class || type == CONSTANT_String || type == CONSTANT_MethodType) { + value = pool.getPrimitiveConstant(index).getString(); + initConstant(); + } + } + + public void writeToStream(DataOutputStream out) throws IOException { + + out.writeByte(type); + switch (type) { + case CONSTANT_Integer: + out.writeInt(getInt()); + break; + case CONSTANT_Float: + out.writeFloat(getFloat()); + break; + case CONSTANT_Long: + out.writeLong(getLong()); + break; + case CONSTANT_Double: + out.writeDouble(getDouble()); + break; + case CONSTANT_Utf8: + out.writeUTF(getString()); + break; + default: // CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType + out.writeShort(index); + } + } + + public boolean equals(Object o) { + if (o == this) return true; + if (o == null || !(o instanceof PrimitiveConstant)) return false; + + PrimitiveConstant cn = (PrimitiveConstant)o; + return this.type == cn.type && + this.isArray == cn.isArray && + this.value.equals(cn.value); + } + + private void initConstant() { + if (type == CONSTANT_Class) { + String className = getString(); + isArray = + (className.length() > 0 && className.charAt(0) == '['); // empty string for a class name seems to be possible in some android files + } + } } diff --git a/src/org/jetbrains/java/decompiler/struct/consts/VariableTypeEnum.java b/src/org/jetbrains/java/decompiler/struct/consts/VariableTypeEnum.java index fc58c7e..ef949aa 100644 --- a/src/org/jetbrains/java/decompiler/struct/consts/VariableTypeEnum.java +++ b/src/org/jetbrains/java/decompiler/struct/consts/VariableTypeEnum.java @@ -1,47 +1,47 @@ /* - * Fernflower - The Analytical Java Decompiler - * http://www.reversed-java.com + * Copyright 2000-2014 JetBrains s.r.o. * - * (C) 2008 - 2010, Stiver + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This software is NEITHER public domain NOR free software - * as per GNU License. See license.txt for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This software is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - package org.jetbrains.java.decompiler.struct.consts; public interface VariableTypeEnum { - public final static int BOOLEAN = 1; - public final static int BYTE = 2; - public final static int CHAR = 3; - public final static int SHORT = 4; - public final static int INT = 5; - public final static int FLOAT = 6; - public final static int LONG = 7; - public final static int DOUBLE = 8; - public final static int RETURN_ADDRESS = 9; - public final static int REFERENCE = 10; - public final static int INSTANCE_UNINITIALIZED = 11; - public final static int VALUE_UNKNOWN = 12; - public final static int VOID = 13; - - public final static Integer BOOLEAN_OBJ = new Integer(BOOLEAN); - public final static Integer BYTE_OBJ = new Integer(BYTE); - public final static Integer CHAR_OBJ = new Integer(CHAR); - public final static Integer SHORT_OBJ = new Integer(SHORT); - public final static Integer INT_OBJ = new Integer(INT); - public final static Integer FLOAT_OBJ = new Integer(FLOAT); - public final static Integer LONG_OBJ = new Integer(LONG); - public final static Integer DOUBLE_OBJ = new Integer(DOUBLE); - public final static Integer RETURN_ADDRESS_OBJ = new Integer(RETURN_ADDRESS); - public final static Integer REFERENCE_OBJ = new Integer(REFERENCE); - public final static Integer INSTANCE_UNINITIALIZED_OBJ = new Integer(INSTANCE_UNINITIALIZED); - public final static Integer VALUE_UNKNOWN_OBJ = new Integer(VALUE_UNKNOWN); - public final static Integer VOID_OBJ = new Integer(VOID); - + public final static int BOOLEAN = 1; + public final static int BYTE = 2; + public final static int CHAR = 3; + public final static int SHORT = 4; + public final static int INT = 5; + public final static int FLOAT = 6; + public final static int LONG = 7; + public final static int DOUBLE = 8; + public final static int RETURN_ADDRESS = 9; + public final static int REFERENCE = 10; + public final static int INSTANCE_UNINITIALIZED = 11; + public final static int VALUE_UNKNOWN = 12; + public final static int VOID = 13; + + public final static Integer BOOLEAN_OBJ = new Integer(BOOLEAN); + public final static Integer BYTE_OBJ = new Integer(BYTE); + public final static Integer CHAR_OBJ = new Integer(CHAR); + public final static Integer SHORT_OBJ = new Integer(SHORT); + public final static Integer INT_OBJ = new Integer(INT); + public final static Integer FLOAT_OBJ = new Integer(FLOAT); + public final static Integer LONG_OBJ = new Integer(LONG); + public final static Integer DOUBLE_OBJ = new Integer(DOUBLE); + public final static Integer RETURN_ADDRESS_OBJ = new Integer(RETURN_ADDRESS); + public final static Integer REFERENCE_OBJ = new Integer(REFERENCE); + public final static Integer INSTANCE_UNINITIALIZED_OBJ = new Integer(INSTANCE_UNINITIALIZED); + public final static Integer VALUE_UNKNOWN_OBJ = new Integer(VALUE_UNKNOWN); + public final static Integer VOID_OBJ = new Integer(VOID); } -- cgit v1.2.3