java-decompiler: optimization (empty lists allocation avoided)

This commit is contained in:
Roman Shevchenko 2014-09-04 18:16:16 +04:00
parent 1cea85e49a
commit 686b5abef9
15 changed files with 345 additions and 343 deletions

View File

@ -61,10 +61,10 @@ public class ClassesProcessor {
StructInnerClassesAttribute inner = (StructInnerClassesAttribute)cl.getAttributes().getWithKey("InnerClasses");
if (inner != null) {
for (int i = 0; i < inner.getClassentries().size(); i++) {
for (int i = 0; i < inner.getClassEntries().size(); i++) {
int[] entry = inner.getClassentries().get(i);
String[] strentry = inner.getStringentries().get(i);
int[] entry = inner.getClassEntries().get(i);
String[] strentry = inner.getStringEntries().get(i);
Object[] arr = new Object[4]; // arr[0] not used
@ -165,8 +165,8 @@ public class ClassesProcessor {
StructClass scl = supernode.classStruct;
StructInnerClassesAttribute inner = (StructInnerClassesAttribute)scl.getAttributes().getWithKey("InnerClasses");
for (int i = 0; i < inner.getStringentries().size(); i++) {
String nestedClass = inner.getStringentries().get(i)[0];
for (int i = 0; i < inner.getStringEntries().size(); i++) {
String nestedClass = inner.getStringEntries().get(i)[0];
if (!setNestedClasses.contains(nestedClass)) {
continue;
}

View File

@ -201,7 +201,7 @@ public class NestedClassProcessor {
StructEnclosingMethodAttribute attr =
(StructEnclosingMethodAttribute)child.classStruct.getAttributes().getWithKey("EnclosingMethod");
if (attr != null && attr.getMethodName() != null) {
if (node.classStruct.qualifiedName.equals(attr.getClassname()) &&
if (node.classStruct.qualifiedName.equals(attr.getClassName()) &&
node.classStruct.getMethod(attr.getMethodName(), attr.getMethodDescriptor()) != null) {
child.enclosingMethod = InterpreterUtil.makeUniqueKey(attr.getMethodName(), attr.getMethodDescriptor());
continue;

View File

@ -51,8 +51,7 @@ public class VarProcessor {
defproc.setVarDefinitions();
}
public void setDebugVarNames(HashMap<Integer, String> mapDebugVarNames) {
public void setDebugVarNames(Map<Integer, String> mapDebugVarNames) {
if (varvers == null) {
return;
}

View File

@ -18,20 +18,15 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
public class StructAnnDefaultAttribute extends StructGeneralAttribute {
private Exprent defaultValue;
public void initContent(ConstantPool pool) {
name = ATTRIBUTE_ANNOTATION_DEFAULT;
DataInputStream data = new DataInputStream(new ByteArrayInputStream(info));
defaultValue = StructAnnotationAttribute.parseAnnotationElement(data, pool);
@Override
public void initContent(ConstantPool pool) throws IOException {
defaultValue = StructAnnotationAttribute.parseAnnotationElement(stream(), pool);
}
public Exprent getDefaultValue() {

View File

@ -22,65 +22,67 @@ import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant;
import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StructAnnotationAttribute extends StructGeneralAttribute {
private List<AnnotationExprent> annotations;
public void initContent(ConstantPool pool) {
@Override
public void initContent(ConstantPool pool) throws IOException {
annotations = parseAnnotations(pool, stream());
}
super.initContent(pool);
annotations = new ArrayList<AnnotationExprent>();
DataInputStream data = new DataInputStream(new ByteArrayInputStream(info, 2, info.length));
int len = (((info[0] & 0xFF) << 8) | (info[1] & 0xFF));
public static List<AnnotationExprent> parseAnnotations(ConstantPool pool, DataInputStream data) throws IOException {
int len = data.readUnsignedShort();
if (len > 0) {
List<AnnotationExprent> annotations = new ArrayList<AnnotationExprent>(len);
for (int i = 0; i < len; i++) {
annotations.add(parseAnnotation(data, pool));
}
return annotations;
}
else {
return Collections.emptyList();
}
}
public static AnnotationExprent parseAnnotation(DataInputStream data, ConstantPool pool) {
try {
String classname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
VarType cltype = new VarType(classname);
public static AnnotationExprent parseAnnotation(DataInputStream data, ConstantPool pool) throws IOException {
String className = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
List<String> names;
List<Exprent> values;
int len = data.readUnsignedShort();
List<String> parnames = new ArrayList<String>();
List<Exprent> parvalues = new ArrayList<Exprent>();
if (len > 0) {
names = new ArrayList<String>(len);
values = new ArrayList<Exprent>(len);
for (int i = 0; i < len; i++) {
parnames.add(pool.getPrimitiveConstant(data.readUnsignedShort()).getString());
parvalues.add(parseAnnotationElement(data, pool));
names.add(pool.getPrimitiveConstant(data.readUnsignedShort()).getString());
values.add(parseAnnotationElement(data, pool));
}
}
else {
names = Collections.emptyList();
values = Collections.emptyList();
}
return new AnnotationExprent(cltype.value, parnames, parvalues);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
return new AnnotationExprent(new VarType(className).value, names, values);
}
public static Exprent parseAnnotationElement(DataInputStream data, ConstantPool pool) {
try {
public static Exprent parseAnnotationElement(DataInputStream data, ConstantPool pool) throws IOException {
int tag = data.readUnsignedByte();
switch (tag) {
case 'e': // enum constant
String classname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
String constname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
String className = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
String constName = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
FieldDescriptor descr = FieldDescriptor.parseDescriptor(className);
return new FieldExprent(constName, descr.type.value, true, null, descr);
FieldDescriptor descr = FieldDescriptor.parseDescriptor(classname);
return new FieldExprent(constname, descr.type.value, true, null, descr);
case 'c': // class
String descriptor = pool.getPrimitiveConstant(data.readUnsignedShort()).getString();
VarType type = FieldDescriptor.parseDescriptor(descriptor).type;
@ -121,29 +123,34 @@ public class StructAnnotationAttribute extends StructGeneralAttribute {
throw new RuntimeException("invalid class type: " + type.type);
}
return new ConstExprent(VarType.VARTYPE_CLASS, value);
case '[': // array
int len = data.readUnsignedShort();
List<Exprent> lst = new ArrayList<Exprent>();
case '[': // array
List<Exprent> elements = Collections.emptyList();
int len = data.readUnsignedShort();
if (len > 0) {
elements = new ArrayList<Exprent>(len);
for (int i = 0; i < len; i++) {
lst.add(parseAnnotationElement(data, pool));
elements.add(parseAnnotationElement(data, pool));
}
}
VarType newtype;
if (lst.isEmpty()) {
newtype = new VarType(CodeConstants.TYPE_OBJECT, 1, "java/lang/Object");
VarType newType;
if (elements.isEmpty()) {
newType = new VarType(CodeConstants.TYPE_OBJECT, 1, "java/lang/Object");
}
else {
VarType eltype = lst.get(0).getExprType();
newtype = new VarType(eltype.type, 1, eltype.value);
VarType elementType = elements.get(0).getExprType();
newType = new VarType(elementType.type, 1, elementType.value);
}
NewExprent newexpr = new NewExprent(newtype, new ArrayList<Exprent>());
newexpr.setDirectArrayInit(true);
newexpr.setLstArrayElements(lst);
return newexpr;
NewExprent newExpr = new NewExprent(newType, Collections.<Exprent>emptyList());
newExpr.setDirectArrayInit(true);
newExpr.setLstArrayElements(elements);
return newExpr;
case '@': // annotation
return parseAnnotation(data, pool);
default:
PrimitiveConstant cn = pool.getPrimitiveConstant(data.readUnsignedShort());
switch (tag) {
@ -170,11 +177,6 @@ public class StructAnnotationAttribute extends StructGeneralAttribute {
}
}
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public List<AnnotationExprent> getAnnotations() {
return annotations;

View File

@ -18,37 +18,30 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StructAnnotationParameterAttribute extends StructGeneralAttribute {
private List<List<AnnotationExprent>> paramAnnotations;
public void initContent(ConstantPool pool) {
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
super.initContent(pool);
paramAnnotations = new ArrayList<List<AnnotationExprent>>();
DataInputStream data = new DataInputStream(new ByteArrayInputStream(info));
try {
int len = data.readUnsignedByte();
if (len > 0) {
paramAnnotations = new ArrayList<List<AnnotationExprent>>(len);
for (int i = 0; i < len; i++) {
List<AnnotationExprent> lst = new ArrayList<AnnotationExprent>();
int annsize = data.readUnsignedShort();
for (int j = 0; j < annsize; j++) {
lst.add(StructAnnotationAttribute.parseAnnotation(data, pool));
}
paramAnnotations.add(lst);
List<AnnotationExprent> annotations = StructAnnotationAttribute.parseAnnotations(pool, data);
paramAnnotations.add(annotations);
}
}
catch (IOException ex) {
throw new RuntimeException(ex);
else {
paramAnnotations = Collections.emptyList();
}
}

View File

@ -18,81 +18,77 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StructAnnotationTypeAttribute extends StructGeneralAttribute {
public static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS = 0x00;
public static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD = 0x01;
public static final int ANNOTATION_TARGET_TYPE_EXTENDS_IMPLEMENTS = 0x10;
public static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS_BOUND = 0x11;
public static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD_BOUND = 0x12;
public static final int ANNOTATION_TARGET_TYPE_FIELD = 0x13;
public static final int ANNOTATION_TARGET_TYPE_RETURN = 0x14;
public static final int ANNOTATION_TARGET_TYPE_RECEIVER = 0x15;
public static final int ANNOTATION_TARGET_TYPE_FORMAL = 0x16;
public static final int ANNOTATION_TARGET_TYPE_THROWS = 0x17;
public static final int ANNOTATION_TARGET_TYPE_LOCAL_VARIABLE = 0x40;
public static final int ANNOTATION_TARGET_TYPE_RESOURCE_VARIABLE = 0x41;
public static final int ANNOTATION_TARGET_TYPE_EXCEPTION = 0x42;
public static final int ANNOTATION_TARGET_TYPE_INSTANCEOF = 0x43;
public static final int ANNOTATION_TARGET_TYPE_NEW = 0x44;
public static final int ANNOTATION_TARGET_TYPE_DOUBLECOLON_NEW = 0x45;
public static final int ANNOTATION_TARGET_TYPE_DOUBLECOLON_ID = 0x46;
public static final int ANNOTATION_TARGET_TYPE_CAST = 0x47;
public static final int ANNOTATION_TARGET_TYPE_INVOKATION_CONSTRUCTOR = 0x48;
public static final int ANNOTATION_TARGET_TYPE_INVOKATION_METHOD = 0x49;
public static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_NEW = 0x4A;
public static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_ID = 0x4B;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS = 0x00;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD = 0x01;
private static final int ANNOTATION_TARGET_TYPE_EXTENDS_IMPLEMENTS = 0x10;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS_BOUND = 0x11;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD_BOUND = 0x12;
private static final int ANNOTATION_TARGET_TYPE_FIELD = 0x13;
private static final int ANNOTATION_TARGET_TYPE_RETURN = 0x14;
private static final int ANNOTATION_TARGET_TYPE_RECEIVER = 0x15;
private static final int ANNOTATION_TARGET_TYPE_FORMAL = 0x16;
private static final int ANNOTATION_TARGET_TYPE_THROWS = 0x17;
private static final int ANNOTATION_TARGET_TYPE_LOCAL_VARIABLE = 0x40;
private static final int ANNOTATION_TARGET_TYPE_RESOURCE_VARIABLE = 0x41;
private static final int ANNOTATION_TARGET_TYPE_EXCEPTION = 0x42;
private static final int ANNOTATION_TARGET_TYPE_INSTANCEOF = 0x43;
private static final int ANNOTATION_TARGET_TYPE_NEW = 0x44;
private static final int ANNOTATION_TARGET_TYPE_DOUBLE_COLON_NEW = 0x45;
private static final int ANNOTATION_TARGET_TYPE_DOUBLE_COLON_ID = 0x46;
private static final int ANNOTATION_TARGET_TYPE_CAST = 0x47;
private static final int ANNOTATION_TARGET_TYPE_INVOCATION_CONSTRUCTOR = 0x48;
private static final int ANNOTATION_TARGET_TYPE_INVOCATION_METHOD = 0x49;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLE_COLON_NEW = 0x4A;
private static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLE_COLON_ID = 0x4B;
public static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER = 1;
public static final int ANNOTATION_TARGET_UNION_SUPERTYPE = 2;
public static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER_BOUND = 3;
public static final int ANNOTATION_TARGET_UNION_EMPTY = 4;
public static final int ANNOTATION_TARGET_UNION_FORMAL_PARAMETER = 5;
public static final int ANNOTATION_TARGET_UNION_THROWS = 6;
public static final int ANNOTATION_TARGET_UNION_LOCALVAR = 7;
public static final int ANNOTATION_TARGET_UNION_CATCH = 8;
public static final int ANNOTATION_TARGET_UNION_OFFSET = 9;
public static final int ANNOTATION_TARGET_UNION_TYPE_ARGUMENT = 10;
private static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER = 1;
private static final int ANNOTATION_TARGET_UNION_SUPERTYPE = 2;
private static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER_BOUND = 3;
private static final int ANNOTATION_TARGET_UNION_EMPTY = 4;
private static final int ANNOTATION_TARGET_UNION_FORMAL_PARAMETER = 5;
private static final int ANNOTATION_TARGET_UNION_THROWS = 6;
private static final int ANNOTATION_TARGET_UNION_LOCAL_VAR = 7;
private static final int ANNOTATION_TARGET_UNION_CATCH = 8;
private static final int ANNOTATION_TARGET_UNION_OFFSET = 9;
private static final int ANNOTATION_TARGET_UNION_TYPE_ARGUMENT = 10;
@SuppressWarnings("FieldCanBeLocal") private List<AnnotationLocation> locations;
@SuppressWarnings("FieldCanBeLocal") private List<AnnotationExprent> annotations;
List<AnnotationLocation> locations = new ArrayList<AnnotationLocation>();
List<AnnotationExprent> annotations = new ArrayList<AnnotationExprent>();
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
public void initContent(ConstantPool pool) {
super.initContent(pool);
DataInputStream data = new DataInputStream(new ByteArrayInputStream(info));
try {
int ann_number = data.readUnsignedByte();
for (int i = 0; i < ann_number; i++) {
int len = data.readUnsignedByte();
if (len > 0) {
locations = new ArrayList<AnnotationLocation>(len);
annotations = new ArrayList<AnnotationExprent>(len);
for (int i = 0; i < len; i++) {
locations.add(parseAnnotationLocation(data));
annotations.add(StructAnnotationAttribute.parseAnnotation(data, pool));
}
}
catch (IOException ex) {
throw new RuntimeException(ex);
else {
locations = Collections.emptyList();
annotations = Collections.emptyList();
}
}
public AnnotationLocation parseAnnotationLocation(DataInputStream data) throws IOException {
private static AnnotationLocation parseAnnotationLocation(DataInputStream data) throws IOException {
AnnotationLocation ann_location = new AnnotationLocation();
// target type
ann_location.target_type = data.readUnsignedByte();
// target union
switch (ann_location.target_type) {
case ANNOTATION_TARGET_TYPE_GENERIC_CLASS:
case ANNOTATION_TARGET_TYPE_GENERIC_METHOD:
@ -118,22 +114,22 @@ public class StructAnnotationTypeAttribute extends StructGeneralAttribute {
break;
case ANNOTATION_TARGET_TYPE_LOCAL_VARIABLE:
case ANNOTATION_TARGET_TYPE_RESOURCE_VARIABLE:
ann_location.target_union = ANNOTATION_TARGET_UNION_LOCALVAR;
ann_location.target_union = ANNOTATION_TARGET_UNION_LOCAL_VAR;
break;
case ANNOTATION_TARGET_TYPE_EXCEPTION:
ann_location.target_union = ANNOTATION_TARGET_UNION_CATCH;
break;
case ANNOTATION_TARGET_TYPE_INSTANCEOF:
case ANNOTATION_TARGET_TYPE_NEW:
case ANNOTATION_TARGET_TYPE_DOUBLECOLON_NEW:
case ANNOTATION_TARGET_TYPE_DOUBLECOLON_ID:
case ANNOTATION_TARGET_TYPE_DOUBLE_COLON_NEW:
case ANNOTATION_TARGET_TYPE_DOUBLE_COLON_ID:
ann_location.target_union = ANNOTATION_TARGET_UNION_OFFSET;
break;
case ANNOTATION_TARGET_TYPE_CAST:
case ANNOTATION_TARGET_TYPE_INVOKATION_CONSTRUCTOR:
case ANNOTATION_TARGET_TYPE_INVOKATION_METHOD:
case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_NEW:
case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_ID:
case ANNOTATION_TARGET_TYPE_INVOCATION_CONSTRUCTOR:
case ANNOTATION_TARGET_TYPE_INVOCATION_METHOD:
case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLE_COLON_NEW:
case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLE_COLON_ID:
ann_location.target_union = ANNOTATION_TARGET_UNION_TYPE_ARGUMENT;
break;
default:
@ -158,7 +154,7 @@ public class StructAnnotationTypeAttribute extends StructGeneralAttribute {
break;
case ANNOTATION_TARGET_UNION_EMPTY:
break;
case ANNOTATION_TARGET_UNION_LOCALVAR:
case ANNOTATION_TARGET_UNION_LOCAL_VAR:
int table_length = data.readUnsignedShort();
ann_location.data = new int[table_length * 3 + 1];
@ -175,7 +171,6 @@ public class StructAnnotationTypeAttribute extends StructGeneralAttribute {
}
// target path
int path_length = data.readUnsignedByte();
ann_location.target_path_kind = new int[path_length];
@ -190,14 +185,10 @@ public class StructAnnotationTypeAttribute extends StructGeneralAttribute {
}
private static class AnnotationLocation {
public int target_type;
public int target_union;
public int[] data;
public int[] target_path_kind;
public int[] target_argument_index;
}
}

View File

@ -19,7 +19,6 @@ import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.LinkConstant;
import org.jetbrains.java.decompiler.struct.consts.PooledConstant;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
@ -27,16 +26,12 @@ import java.util.List;
public class StructBootstrapMethodsAttribute extends StructGeneralAttribute {
private List<LinkConstant> method_refs = new ArrayList<LinkConstant>();
private List<List<PooledConstant>> method_arguments = new ArrayList<List<PooledConstant>>();
private List<LinkConstant> methodRefs = new ArrayList<LinkConstant>();
private List<List<PooledConstant>> methodArguments = new ArrayList<List<PooledConstant>>();
public void initContent(ConstantPool pool) {
name = ATTRIBUTE_BOOTSTRAP_METHODS;
try {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(info, 0, info.length));
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
int method_number = data.readUnsignedShort();
@ -52,24 +47,20 @@ public class StructBootstrapMethodsAttribute extends StructGeneralAttribute {
list_arguments.add(pool.getConstant(bootstrap_argument_ref));
}
method_refs.add(pool.getLinkConstant(bootstrap_method_ref));
method_arguments.add(list_arguments);
}
}
catch (IOException ex) {
throw new RuntimeException(ex);
methodRefs.add(pool.getLinkConstant(bootstrap_method_ref));
methodArguments.add(list_arguments);
}
}
public int getMethodsNumber() {
return method_refs.size();
return methodRefs.size();
}
public LinkConstant getMethodReference(int index) {
return method_refs.get(index);
return methodRefs.get(index);
}
public List<PooledConstant> getMethodArguments(int index) {
return method_arguments.get(index);
return methodArguments.get(index);
}
}

View File

@ -17,14 +17,15 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.IOException;
public class StructConstantValueAttribute extends StructGeneralAttribute {
private int index;
public void initContent(ConstantPool pool) {
name = ATTRIBUTE_CONSTANT_VALUE;
index = ((info[0] & 0xFF) << 8) | (info[1] & 0xFF);
@Override
public void initContent(ConstantPool pool) throws IOException {
index = stream().readUnsignedShort();
}
public int getIndex() {

View File

@ -18,32 +18,31 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.LinkConstant;
import java.io.DataInputStream;
import java.io.IOException;
public class StructEnclosingMethodAttribute extends StructGeneralAttribute {
private String classname;
private String mtname;
private String className;
private String methodName;
private String methodDescriptor;
public void initContent(ConstantPool pool) {
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
int classIndex = data.readUnsignedShort();
int methodIndex = data.readUnsignedShort();
name = ATTRIBUTE_ENCLOSING_METHOD;
int clindex = (((info[0] & 0xFF) << 8) | (info[1] & 0xFF));
int mtindex = (((info[2] & 0xFF) << 8) | (info[3] & 0xFF));
classname = pool.getPrimitiveConstant(clindex).getString();
if (mtindex != 0) {
LinkConstant lk = pool.getLinkConstant(mtindex);
mtname = lk.elementname;
className = pool.getPrimitiveConstant(classIndex).getString();
if (methodIndex != 0) {
LinkConstant lk = pool.getLinkConstant(methodIndex);
methodName = lk.elementname;
methodDescriptor = lk.descriptor;
}
}
public String getClassname() {
return classname;
public String getClassName() {
return className;
}
public String getMethodDescriptor() {
@ -51,6 +50,6 @@ public class StructEnclosingMethodAttribute extends StructGeneralAttribute {
}
public String getMethodName() {
return mtname;
return methodName;
}
}

View File

@ -17,21 +17,28 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StructExceptionsAttribute extends StructGeneralAttribute {
private List<Integer> throwsExceptions = new ArrayList<Integer>();
private List<Integer> throwsExceptions;
public void initContent(ConstantPool pool) {
name = ATTRIBUTE_EXCEPTIONS;
int length = 2 + (((info[0] & 0xFF) << 8) | (info[1] & 0xFF)) * 2;
for (int i = 2; i < length; i += 2) {
int index = ((info[i] & 0xFF) << 8) | (info[i + 1] & 0xFF);
throwsExceptions.add(index);
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
int len = data.readUnsignedShort();
if (len > 0) {
throwsExceptions = new ArrayList<Integer>(len);
for (int i = 0; i < len; i++) {
throwsExceptions.add(data.readUnsignedShort());
}
}
else {
throwsExceptions = Collections.emptyList();
}
}
@ -42,8 +49,4 @@ public class StructExceptionsAttribute extends StructGeneralAttribute {
public List<Integer> getThrowsExceptions() {
return throwsExceptions;
}
public void setThrowsExceptions(List<Integer> throwsExceptions) {
this.throwsExceptions = throwsExceptions;
}
}

View File

@ -16,6 +16,10 @@
package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/*
attribute_info {
@ -44,9 +48,8 @@ public class StructGeneralAttribute {
public static final String ATTRIBUTE_SYNTHETIC = "Synthetic";
public static final String ATTRIBUTE_DEPRECATED = "Deprecated";
protected String name;
protected byte[] info;
private String name;
private byte[] info;
public static StructGeneralAttribute createAttribute(String name) {
StructGeneralAttribute attr;
@ -100,7 +103,11 @@ public class StructGeneralAttribute {
return attr;
}
public void initContent(ConstantPool pool) { }
protected DataInputFullStream stream() {
return new DataInputFullStream(new ByteArrayInputStream(info));
}
public void initContent(ConstantPool pool) throws IOException { }
public void setInfo(byte[] info) {
this.info = info;

View File

@ -17,14 +17,16 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.IOException;
public class StructGenericSignatureAttribute extends StructGeneralAttribute {
private String signature;
public void initContent(ConstantPool pool) {
name = ATTRIBUTE_SIGNATURE;
signature = pool.getPrimitiveConstant(((info[0] & 0xFF) << 8) | (info[1] & 0xFF)).getString();
@Override
public void initContent(ConstantPool pool) throws IOException {
int index = stream().readUnsignedShort();
signature = pool.getPrimitiveConstant(index).getString();
}
public String getSignature() {

View File

@ -17,56 +17,56 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StructInnerClassesAttribute extends StructGeneralAttribute {
private List<int[]> classentries = new ArrayList<int[]>();
private List<int[]> classEntries;
private List<String[]> stringEntries;
private List<String[]> stringentries = new ArrayList<String[]>();
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
public void initContent(ConstantPool pool) {
int len = data.readUnsignedShort();
if (len > 0) {
classEntries = new ArrayList<int[]>(len);
stringEntries = new ArrayList<String[]>(len);
name = ATTRIBUTE_INNER_CLASSES;
int length = 2 + (((info[0] & 0xFF) << 8) | (info[1] & 0xFF)) * 8;
int i = 2;
while (i < length) {
int[] arr = new int[4];
for (int i = 0; i < len; i++) {
int[] classEntry = new int[4];
for (int j = 0; j < 4; j++) {
arr[j] = ((info[i] & 0xFF) << 8) | (info[i + 1] & 0xFF);
i += 2;
classEntry[j] = data.readUnsignedShort();
}
classEntries.add(classEntry);
classentries.add(arr);
// inner name, enclosing class, original simple name
String[] stringEntry = new String[3];
stringEntry[0] = pool.getPrimitiveConstant(classEntry[0]).getString();
if (classEntry[1] != 0) {
stringEntry[1] = pool.getPrimitiveConstant(classEntry[1]).getString();
}
for (int[] entry : classentries) {
String[] arr = new String[3];
// inner name
arr[0] = pool.getPrimitiveConstant(entry[0]).getString();
//enclosing class
if (entry[1] != 0) {
arr[1] = pool.getPrimitiveConstant(entry[1]).getString();
if (classEntry[2] != 0) {
stringEntry[2] = pool.getPrimitiveConstant(classEntry[2]).getString();
}
// original simple name
if (entry[2] != 0) {
arr[2] = pool.getPrimitiveConstant(entry[2]).getString();
stringEntries.add(stringEntry);
}
stringentries.add(arr);
}
else {
classEntries = Collections.emptyList();
stringEntries = Collections.emptyList();
}
}
public List<int[]> getClassentries() {
return classentries;
public List<int[]> getClassEntries() {
return classEntries;
}
public List<String[]> getStringentries() {
return stringentries;
public List<String[]> getStringEntries() {
return stringEntries;
}
}

View File

@ -16,25 +16,44 @@
package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/*
u2 local_variable_table_length;
local_variable {
u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
}
*/
public class StructLocalVariableTableAttribute extends StructGeneralAttribute {
private HashMap<Integer, String> mapVarNames = new HashMap<Integer, String>();
private Map<Integer, String> mapVarNames = new HashMap<Integer, String>();
public void initContent(ConstantPool pool) {
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputFullStream data = stream();
name = ATTRIBUTE_LOCAL_VARIABLE_TABLE;
int len = ((info[0] & 0xFF) << 8) | (info[1] & 0xFF);
int ind = 6;
for (int i = 0; i < len; i++, ind += 10) {
int nindex = ((info[ind] & 0xFF) << 8) | (info[ind + 1] & 0xFF);
int vindex = ((info[ind + 4] & 0xFF) << 8) | (info[ind + 5] & 0xFF);
mapVarNames.put(vindex, pool.getPrimitiveConstant(nindex).getString());
int len = data.readUnsignedShort();
if (len > 0) {
mapVarNames = new HashMap<Integer, String>(len);
for (int i = 0; i < len; i++) {
data.discard(4);
int nameIndex = data.readUnsignedShort();
data.discard(2);
int varIndex = data.readUnsignedShort();
mapVarNames.put(varIndex, pool.getPrimitiveConstant(nameIndex).getString());
}
}
else {
mapVarNames = Collections.emptyMap();
}
}
@ -42,7 +61,7 @@ public class StructLocalVariableTableAttribute extends StructGeneralAttribute {
mapVarNames.putAll(attr.getMapVarNames());
}
public HashMap<Integer, String> getMapVarNames() {
public Map<Integer, String> getMapVarNames() {
return mapVarNames;
}
}