Skip to content

Commit 90ce66b

Browse files
add instruction
1 parent 92549c8 commit 90ce66b

23 files changed

+2012
-63
lines changed

src/main/java/org/codingnewtalking/classfile/attribute/AttributeInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ public int getAttributeLength() {
5252
public String getAttributeName() {
5353
return constantPool.getConstantUtf8String(getAttributeNameIndex());
5454
}
55+
56+
public String toString(String baseBlank, String blankUnit, String blank4) {
57+
return "";
58+
}
5559
}

src/main/java/org/codingnewtalking/classfile/attribute/Code.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.codingnewtalking.classfile.util.Length2;
1010
import org.codingnewtalking.classfile.util.Length4;
1111
import org.codingnewtalking.classfile.util.Num2;
12+
import org.codingnewtalking.util.ForUtils;
1213

1314
/**
1415
* @author lixinjie
@@ -97,11 +98,25 @@ public AttributeInfo[] getAttributes() {
9798
}
9899

99100
@Override
100-
public String toString() {
101-
return "Code [getMaxStack()=" + getMaxStack() + ", getMaxLocals()=" + getMaxLocals() + ", getCodeLength()="
102-
+ getCodeLength() + ", getJvmCode()=" + getJvmCode() + ", getExceptionTableLength()="
103-
+ getExceptionTableLength() + ", getExceptionTables()=" + Arrays.toString(getExceptionTables())
104-
+ ", getAttributesCount()=" + getAttributesCount() + ", getAttributes()="
105-
+ Arrays.toString(getAttributes()) + "]";
101+
public String toString(String baseBlank, String blankUnit, String blank4) {
102+
return baseBlank
103+
+ "Code [getMaxStack()=" + getMaxStack() + ", getMaxLocals()=" + getMaxLocals() + ", getCodeLength()="
104+
+ getCodeLength()+ ", \r\n"
105+
+ baseBlank + blank4 + "getJvmCode()=" + getJvmCode()+ ", \r\n"
106+
+ baseBlank + blank4 + "getExceptionTableLength()=" + getExceptionTableLength()
107+
+ ", getExceptionTables()=" + Arrays.toString(getExceptionTables()) + ", \r\n"
108+
+ baseBlank + blank4 + "getAttributesCount()=" + getAttributesCount() + ", getAttributes()=[\r\n"
109+
+ toString(getAttributes(), baseBlank + blankUnit + blank4, blankUnit, blank4)
110+
+ baseBlank + blank4 + "]\r\n"
111+
+ baseBlank + "]";
112+
}
113+
114+
private String toString(AttributeInfo[] attributes, String baseBlank, String blankUnit, String blank4) {
115+
StringBuilder builder = new StringBuilder();
116+
ForUtils.each(attributes.length, (index) -> {
117+
builder.append(attributes[index].toString(baseBlank, blankUnit, blank4))
118+
.append("\r\n");
119+
});
120+
return builder.toString();
106121
}
107122
}

src/main/java/org/codingnewtalking/classfile/attribute/LineNumberTable.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.codingnewtalking.classfile.attribute;
22

3-
import java.util.Arrays;
4-
53
import org.codingnewtalking.classfile.ConstantPool;
64
import org.codingnewtalking.classfile.attribute.util.LineNumTable;
75
import org.codingnewtalking.classfile.util.Length2;
6+
import org.codingnewtalking.util.ForUtils;
87

98
/**
109
* @author lixinjie
@@ -35,9 +34,21 @@ public LineNumTable[] getLineNumTables() {
3534
}
3635

3736
@Override
38-
public String toString() {
39-
return "LineNumberTable [getLineNumTableLength()=" + getLineNumTableLength() + ", getLineNumTables()="
40-
+ Arrays.toString(getLineNumTables()) + "]";
37+
public String toString(String baseBlank, String blankUnit, String blank4) {
38+
return baseBlank
39+
+ "LineNumberTable [getLineNumTableLength()=" + getLineNumTableLength() + ", getLineNumTables()=[\r\n"
40+
+ toString(getLineNumTables(), baseBlank + blankUnit + blank4, blankUnit, blank4)
41+
+ baseBlank + blankUnit + blank4 + "]\r\n"
42+
+ baseBlank + blankUnit + "]";
4143
}
4244

45+
private String toString(LineNumTable[] lineNumTables, String baseBlank, String blankUnit, String blank4) {
46+
StringBuilder builder = new StringBuilder();
47+
ForUtils.each(lineNumTables.length, (index) -> {
48+
builder.append(baseBlank)
49+
.append(lineNumTables[index])
50+
.append("\r\n");
51+
});
52+
return builder.toString();
53+
}
4354
}

src/main/java/org/codingnewtalking/classfile/attribute/LocalVariableTable.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.codingnewtalking.classfile.attribute;
22

3-
import java.util.Arrays;
4-
53
import org.codingnewtalking.classfile.ConstantPool;
64
import org.codingnewtalking.classfile.attribute.util.LocalVarTable;
75
import org.codingnewtalking.classfile.util.Length2;
6+
import org.codingnewtalking.util.ForUtils;
87

98
/**
109
* @author lixinjie
@@ -30,16 +29,27 @@ public LocalVarTable[] getLocalVarTables() {
3029
if (localVarTables == null) {
3130
localVarTables = new LocalVarTable[getLocalVarTableLength()];
3231
for (int i = 0, len = localVarTables.length; i < len; i++) {
33-
localVarTables[i] = new LocalVarTable(bytes, offset + 8 + i * 10);
32+
localVarTables[i] = new LocalVarTable(bytes, offset + 8 + i * 10, constantPool);
3433
}
3534
}
3635
return localVarTables;
3736
}
3837

3938
@Override
40-
public String toString() {
41-
return "LocalVariableTable [getLocalVarTableLength()=" + getLocalVarTableLength() + ", getLocalVarTables()="
42-
+ Arrays.toString(getLocalVarTables()) + "]";
39+
public String toString(String baseBlank, String blankUnit, String blank4) {
40+
return baseBlank
41+
+ "LocalVariableTable [getLocalVarTableLength()=" + getLocalVarTableLength() + ", getLocalVarTables()=[\r\n"
42+
+ toString(getLocalVarTables(), baseBlank + blankUnit + blank4, blankUnit, blank4)
43+
+ baseBlank + blankUnit + blank4 + "]\r\n"
44+
+ baseBlank + blankUnit + "]";
4345
}
4446

47+
private String toString(LocalVarTable[] localVarTables, String baseBlank, String blankUnit, String blank4) {
48+
StringBuilder builder = new StringBuilder();
49+
ForUtils.each(localVarTables.length, (index) -> {
50+
builder.append(localVarTables[index].toString(baseBlank))
51+
.append("\r\n");
52+
});
53+
return builder.toString();
54+
}
4555
}

src/main/java/org/codingnewtalking/classfile/attribute/MethodParameters.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ public Parameter[] getParameters() {
3737
}
3838

3939
@Override
40-
public String toString() {
41-
return "MethodParameters [getParametersCount()=" + getParametersCount() + ", getParameters()="
42-
+ Arrays.toString(getParameters()) + "]";
40+
public String toString(String baseBlank, String blankUnit, String blank4) {
41+
return baseBlank
42+
+ "MethodParameters [getParametersCount()=" + getParametersCount() + ", getParameters()="
43+
+ Arrays.toString(getParameters()) + "\r\n"
44+
+ baseBlank + "]";
4345
}
4446
}

src/main/java/org/codingnewtalking/classfile/attribute/SourceFile.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@
99
*/
1010
public class SourceFile extends AttributeInfo {
1111

12-
private Index2 sourcefileIndex;
12+
private Index2 sourceFileIndex;
1313

1414
public SourceFile(byte[] bytes, int offset, ConstantPool constantPool) {
1515
super(bytes, offset, constantPool);
1616
}
1717

18-
public int getSourcefileIndex() {
19-
if (sourcefileIndex == null) {
20-
sourcefileIndex = new Index2(bytes, offset + 6);
18+
public int getSourceFileIndex() {
19+
if (sourceFileIndex == null) {
20+
sourceFileIndex = new Index2(bytes, offset + 6);
2121
}
22-
return sourcefileIndex.getIndex();
22+
return sourceFileIndex.getIndex();
23+
}
24+
25+
public String getSourceFile() {
26+
return constantPool.getConstantUtf8String(getSourceFileIndex());
2327
}
2428

2529
@Override
2630
public String toString() {
27-
return "SourceFile [getSourcefileIndex()=" + getSourcefileIndex() + "]";
31+
return "SourceFile [getSourceFileIndex()=" + getSourceFileIndex() + ", getSourceFile()=" + getSourceFile() + "]";
2832
}
2933
}

src/main/java/org/codingnewtalking/classfile/attribute/util/LocalVarTable.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.codingnewtalking.classfile.attribute.util;
22

3+
import org.codingnewtalking.classfile.ConstantPool;
34
import org.codingnewtalking.classfile.util.Index2;
45
import org.codingnewtalking.classfile.util.Length2;
56

@@ -11,16 +12,18 @@ public class LocalVarTable {
1112

1213
private byte[] bytes;
1314
private int offset;
15+
private ConstantPool constantPool;
1416

1517
private StartPc startPc;
1618
private Length2 length;
1719
private Index2 nameIndex;
1820
private Index2 descriptorIndex;
1921
private Index2 index;
2022

21-
public LocalVarTable(byte[] bytes, int offset) {
23+
public LocalVarTable(byte[] bytes, int offset, ConstantPool constantPool) {
2224
this.bytes = bytes;
2325
this.offset = offset;
26+
this.constantPool = constantPool;
2427
}
2528

2629
public int getStartPc() {
@@ -44,24 +47,35 @@ public int getNameIndex() {
4447
return nameIndex.getIndex();
4548
}
4649

50+
public String getName() {
51+
return constantPool.getConstantUtf8String(getNameIndex());
52+
}
53+
4754
public int getDescriptorIndex() {
4855
if (descriptorIndex == null) {
4956
descriptorIndex = new Index2(bytes, offset + 6);
5057
}
5158
return descriptorIndex.getIndex();
5259
}
5360

61+
public String getDescriptor() {
62+
return constantPool.getConstantUtf8String(getDescriptorIndex());
63+
}
64+
5465
public int getIndex() {
5566
if (index == null) {
5667
index = new Index2(bytes, offset + 8);
5768
}
5869
return index.getIndex();
5970
}
6071

61-
@Override
62-
public String toString() {
63-
return "LocalVarTable [getStartPc()=" + getStartPc() + ", getLength()=" + getLength() + ", getNameIndex()="
64-
+ getNameIndex() + ", getDescriptorIndex()=" + getDescriptorIndex() + ", getIndex()=" + getIndex()
65-
+ "]";
72+
public String toString(String baseBlank) {
73+
String blank15 = " ";
74+
return baseBlank
75+
+ "LocalVarTable [getStartPc()=" + getStartPc() + ", getLength()=" + getLength()
76+
+ ", getNameIndex()=" + getNameIndex() + ", getName()=" + getName() + ", \r\n"
77+
+ baseBlank + blank15 + "getDescriptorIndex()=" + getDescriptorIndex() + ", getDescriptor()=" + getDescriptor() + ", \r\n"
78+
+ baseBlank + blank15 + "getIndex()=" + getIndex() + "\r\n"
79+
+ baseBlank + blank15 + "]";
6680
}
6781
}

src/main/java/org/codingnewtalking/classfile/field/FieldInfo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@ public String getDescriptor() {
106106

107107
@Override
108108
public String toString() {
109-
return "FieldInfo [getAccessFlags()=" + getAccessFlags() + ", getNameIndex()=" + getNameIndex()
109+
String blank16 = " ";
110+
return "FieldInfo [getAccessFlags()=" + getAccessFlags() + ", \r\n"
111+
+ blank16 + "getNameIndex()=" + getNameIndex()
110112
+ ", getName()=" + getName()
111113
+ ", getDescriptorIndex()=" + getDescriptorIndex()
112-
+ ", getDescriptor()=" + getDescriptor()
113-
+ ", getAttributesCount()=" + getAttributesCount()
114-
+ ", getAttributes()=" + Arrays.toString(getAttributes()) + "]";
114+
+ ", getDescriptor()=" + getDescriptor() + ", \r\n"
115+
+ blank16 + "getAttributesCount()=" + getAttributesCount()
116+
+ ", getAttributes()=" + Arrays.toString(getAttributes()) + "\r\n"
117+
+ blank16 + "]";
115118
}
116119
}

src/main/java/org/codingnewtalking/classfile/method/MethodInfo.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.codingnewtalking.classfile.method;
22

3-
import java.util.Arrays;
4-
53
import org.codingnewtalking.classfile.ConstantPool;
64
import org.codingnewtalking.classfile.attribute.AttributeInfo;
75
import org.codingnewtalking.classfile.attribute.AttributeInfoBuilder;
86
import org.codingnewtalking.classfile.util.Count2;
97
import org.codingnewtalking.classfile.util.Index2;
108
import org.codingnewtalking.util.ByteUtils;
9+
import org.codingnewtalking.util.ForUtils;
1110

1211
/**
1312
* @author lixinjie
@@ -105,12 +104,26 @@ public String getDescriptor() {
105104

106105
@Override
107106
public String toString() {
108-
return "MethodInfo [getAccessFlags()=" + getAccessFlags() + ", getNameIndex()=" + getNameIndex()
107+
String blank4 = " ";
108+
String blankUnit = " ";
109+
return "MethodInfo [getAccessFlags()=" + getAccessFlags() + ", \r\n"
110+
+ blankUnit + "getNameIndex()=" + getNameIndex()
109111
+ ", getName()=" + getName()
110112
+ ", getDescriptorIndex()=" + getDescriptorIndex()
111-
+ ", getDescriptor()=" + getDescriptor()
112-
+ ", getAttributesCount()=" + getAttributesCount()
113-
+ ", getAttributes()=" + Arrays.toString(getAttributes()) + "]";
113+
+ ", getDescriptor()=" + getDescriptor() + ", \r\n"
114+
+ blankUnit + "getAttributesCount()=" + getAttributesCount()
115+
+ ", getAttributes()=[\r\n"
116+
+ toString(getAttributes(), blankUnit + blankUnit, blankUnit, blank4)
117+
+ blankUnit + "]\r\n"
118+
+ blankUnit + "]";
114119
}
115120

121+
private String toString(AttributeInfo[] attributes, String baseBlank, String blankUnit, String blank4) {
122+
StringBuilder builder = new StringBuilder();
123+
ForUtils.each(attributes.length, (index) -> {
124+
builder.append(attributes[index].toString(baseBlank, blankUnit, blank4))
125+
.append("\r\n");
126+
});
127+
return builder.toString();
128+
}
116129
}

0 commit comments

Comments
 (0)