diff options
author | Roman Shevchenko <roman.shevchenko@jetbrains.com> | 2014-09-02 20:56:03 +0400 |
---|---|---|
committer | Roman Shevchenko <roman.shevchenko@jetbrains.com> | 2014-09-03 11:39:32 +0400 |
commit | 2df49d32a71818227e80a8628688906f2ede8a6a (patch) | |
tree | dced5f5ebf2f860d5683abf6910f180a67f9471d /src/org/jetbrains/java/decompiler/struct/attr | |
parent | c0c83126a69a0c652f343e972f727ffd7f5f10af (diff) | |
download | fernflower-2df49d32a71818227e80a8628688906f2ede8a6a.tar fernflower-2df49d32a71818227e80a8628688906f2ede8a6a.tar.gz fernflower-2df49d32a71818227e80a8628688906f2ede8a6a.tar.lz fernflower-2df49d32a71818227e80a8628688906f2ede8a6a.tar.xz fernflower-2df49d32a71818227e80a8628688906f2ede8a6a.zip |
java-decompiler: fixes and cleanups
- unified attribute loading code
- common methods for checking member flags
- verifying skip()
- correct resource closing
- typos
Diffstat (limited to 'src/org/jetbrains/java/decompiler/struct/attr')
-rw-r--r-- | src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java | 27 | ||||
-rw-r--r-- | src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java | 95 |
2 files changed, 25 insertions, 97 deletions
diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java index c52fcc7..53c02ec 100644 --- a/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java @@ -17,9 +17,6 @@ package org.jetbrains.java.decompiler.struct.attr; import org.jetbrains.java.decompiler.struct.consts.ConstantPool; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -38,30 +35,6 @@ public class StructExceptionsAttribute extends StructGeneralAttribute { } } - public void writeToStream(DataOutputStream out) throws IOException { - - out.writeShort(attribute_name_index); - - ByteArrayOutputStream codeout = new ByteArrayOutputStream(); - DataOutputStream dataout = new DataOutputStream(codeout); - - int len = throwsExceptions.size(); - dataout.writeShort(len); - - if (len > 0) { - info = new byte[len * 2]; - for (int i = 0, j = 0; i < len; i++, j += 2) { - int index = throwsExceptions.get(i).intValue(); - info[j] = (byte)(index >> 8); - info[j + 1] = (byte)(index & 0xFF); - } - dataout.write(info); - } - - out.writeInt(codeout.size()); - out.write(codeout.toByteArray()); - } - public String getExcClassname(int index, ConstantPool pool) { return pool.getPrimitiveConstant(throwsExceptions.get(index).intValue()).getString(); } diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java index bd0596a..632575f 100644 --- a/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java @@ -17,17 +17,13 @@ package org.jetbrains.java.decompiler.struct.attr; import org.jetbrains.java.decompiler.struct.consts.ConstantPool; -import java.io.DataOutputStream; -import java.io.IOException; - /* - attribute_info { - u2 attribute_name_index; - u4 attribute_length; - u1 info[attribute_length]; - } + attribute_info { + u2 attribute_name_index; + u4 attribute_length; + u1 info[attribute_length]; + } */ - public class StructGeneralAttribute { public static final String ATTRIBUTE_CODE = "Code"; @@ -48,74 +44,51 @@ public class StructGeneralAttribute { public static final String ATTRIBUTE_SYNTHETIC = "Synthetic"; public static final String ATTRIBUTE_DEPRECATED = "Deprecated"; - - // ***************************************************************************** - // private fields - // ***************************************************************************** - - protected int attribute_name_index; - - protected byte[] info; - protected String name; + protected byte[] info; - // ***************************************************************************** - // public methods - // ***************************************************************************** - - public void writeToStream(DataOutputStream out) throws IOException { - out.writeShort(attribute_name_index); - out.writeInt(info.length); - if (info.length > 0) { - out.write(info); - } - } - - public void initContent(ConstantPool pool) { - name = pool.getPrimitiveConstant(attribute_name_index).getString(); - } - - public static StructGeneralAttribute getMatchingAttributeInstance(int nameindex, String attrname) { + public static StructGeneralAttribute createAttribute(String name) { StructGeneralAttribute attr; - if (ATTRIBUTE_INNER_CLASSES.equals(attrname)) { + if (ATTRIBUTE_INNER_CLASSES.equals(name)) { attr = new StructInnerClassesAttribute(); } - else if (ATTRIBUTE_CONSTANT_VALUE.equals(attrname)) { + else if (ATTRIBUTE_CONSTANT_VALUE.equals(name)) { attr = new StructConstantValueAttribute(); } - else if (ATTRIBUTE_SIGNATURE.equals(attrname)) { + else if (ATTRIBUTE_SIGNATURE.equals(name)) { attr = new StructGenericSignatureAttribute(); } - else if (ATTRIBUTE_ANNOTATION_DEFAULT.equals(attrname)) { + else if (ATTRIBUTE_ANNOTATION_DEFAULT.equals(name)) { attr = new StructAnnDefaultAttribute(); } - else if (ATTRIBUTE_EXCEPTIONS.equals(attrname)) { + else if (ATTRIBUTE_EXCEPTIONS.equals(name)) { attr = new StructExceptionsAttribute(); } - else if (ATTRIBUTE_ENCLOSING_METHOD.equals(attrname)) { + else if (ATTRIBUTE_ENCLOSING_METHOD.equals(name)) { attr = new StructEnclosingMethodAttribute(); } - else if (ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS.equals(attrname) || - ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS.equals(attrname)) { + else if (ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS.equals(name) || + ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS.equals(name)) { attr = new StructAnnotationAttribute(); } - else if (ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS.equals(attrname) || - ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS.equals(attrname)) { + else if (ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS.equals(name) || + ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS.equals(name)) { attr = new StructAnnotationParameterAttribute(); } - else if (ATTRIBUTE_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.equals(attrname) || - ATTRIBUTE_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.equals(attrname)) { + else if (ATTRIBUTE_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.equals(name) || + ATTRIBUTE_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.equals(name)) { attr = new StructAnnotationTypeAttribute(); } - else if (ATTRIBUTE_LOCAL_VARIABLE_TABLE.equals(attrname)) { + else if (ATTRIBUTE_LOCAL_VARIABLE_TABLE.equals(name)) { attr = new StructLocalVariableTableAttribute(); } - else if (ATTRIBUTE_BOOTSTRAP_METHODS.equals(attrname)) { + else if (ATTRIBUTE_BOOTSTRAP_METHODS.equals(name)) { attr = new StructBootstrapMethodsAttribute(); } - else if (ATTRIBUTE_SYNTHETIC.equals(attrname) || ATTRIBUTE_DEPRECATED.equals(attrname)) { + else if (ATTRIBUTE_SYNTHETIC.equals(name) || + ATTRIBUTE_DEPRECATED.equals(name)) { attr = new StructGeneralAttribute(); } else { @@ -123,17 +96,11 @@ public class StructGeneralAttribute { return null; } - attr.setAttribute_name_index(nameindex); + attr.name = name; return attr; } - // ***************************************************************************** - // getter and setter methods - // ***************************************************************************** - - public byte[] getInfo() { - return info; - } + public void initContent(ConstantPool pool) { } public void setInfo(byte[] info) { this.info = info; @@ -142,16 +109,4 @@ public class StructGeneralAttribute { public String getName() { return name; } - - public void setName(String name) { - this.name = name; - } - - public int getAttribute_name_index() { - return attribute_name_index; - } - - public void setAttribute_name_index(int attribute_name_index) { - this.attribute_name_index = attribute_name_index; - } } |