Skip to content

Commit 3194093

Browse files
committed
mkdir
1 parent 8781068 commit 3194093

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/main/java/cn/enaium/joe/util/classes/ClassNode.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ default String getInternalPackageName(){
3131
}
3232

3333
default String getSuperClass(){
34-
return this.getClassNode().superName;
34+
return this.getNodeInternal().superName;
3535
}
3636

3737
default String[] getInterfaces(){
38-
return this.getClassNode().interfaces.toArray(String[]::new);
38+
return this.getNodeInternal().interfaces.toArray(String[]::new);
3939
}
4040

4141
default int getAccess(){
42-
return this.getClassNode().access;
42+
return this.getNodeInternal().access;
4343
}
4444

4545
default int getVersion(){
46-
return this.getClassNode().version;
46+
return this.getNodeInternal().version;
4747
}
4848

4949
default MethodNode[] getMethods(){
@@ -55,18 +55,20 @@ default FieldNode[] getFields(){
5555
}
5656

5757
default void trace(TraceClassVisitor traceClassVisitor){
58-
this.getClassNode().accept(traceClassVisitor);
58+
this.getNodeInternal().accept(traceClassVisitor);
5959
}
6060

6161
default void analyzeVisitor(ClassVisitor classVisitor){
62-
this.getClassNode().accept(classVisitor);
62+
this.getNodeInternal().accept(classVisitor);
6363
}
6464

6565
default void editVisitor(ClassVisitor classVisitor){
66-
this.getClassNode().accept(classVisitor);
66+
this.getNodeInternal().accept(classVisitor);
6767
this.updateBytes();
6868
}
6969

70+
org.objectweb.asm.tree.ClassNode getNodeInternal();
71+
7072
default Set<String> getParents(){
7173
Set<String> parent = new HashSet<>();
7274
if (this.getSuperClass() != null && !"java/lang/Object".equals(this.getSuperClass())) {
@@ -99,6 +101,9 @@ static ClassNode of(final org.objectweb.asm.tree.ClassNode classNode){
99101
}
100102

101103
class Impl implements ClassNode{
104+
105+
boolean isDir = false;
106+
102107
String internalName; String canonicalName; byte[] clazz; org.objectweb.asm.tree.ClassNode node;
103108
public Impl(String internalName, String canonicalName, byte[] clazz, org.objectweb.asm.tree.ClassNode node){
104109
this.internalName = internalName;
@@ -109,28 +114,31 @@ public Impl(String internalName, String canonicalName, byte[] clazz, org.objectw
109114

110115
@Override
111116
public String getInternalName() {
112-
return this.internalName;
117+
return this.node.name;
113118
}
114119

115120
@Override
116121
public String getCanonicalName() {
117-
return this.canonicalName;
122+
return this.node.name.replace('/', '.');
118123
}
119124

120125
@Override
121126
public byte[] getClassBytes() {
127+
if (this.isDir) updateBytes();
122128
return this.clazz;
123129
}
124130

125131
@Override
126132
public org.objectweb.asm.tree.ClassNode getClassNode() {
133+
this.isDir = true;
127134
return this.node;
128135
}
129136

130137
@Override
131138
public void updateBytes() {ClassWriter classWriter = new ClassWriter(0);
132-
getClassNode().accept(classWriter);
139+
node.accept(classWriter);
133140
this.clazz = classWriter.toByteArray();
141+
this.isDir = false;
134142
}
135143

136144
@Override
@@ -145,5 +153,10 @@ public void accept(ClassNode newNode) {
145153
public ClassNode clone() {
146154
return ClassNode.of(this.getClassBytes().clone());
147155
}
156+
157+
@Override
158+
public org.objectweb.asm.tree.ClassNode getNodeInternal() {
159+
return this.node;
160+
}
148161
}
149162
}

0 commit comments

Comments
 (0)