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/StructGeneralAttribute.java | |
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/StructGeneralAttribute.java')
-rw-r--r-- | src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java | 95 |
1 files changed, 25 insertions, 70 deletions
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; - } } |