-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASM integration in TypesLoaderVisitor
This patch replaces reflection by ASM and increases the performace almost a 20%. ASM parses binary files and allows to extract the minimum amount of information that is required to analyze.
- Loading branch information
Showing
3 changed files
with
151 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/org/walkmod/javalang/compiler/types/ASMClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.walkmod.javalang.compiler.types; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.io.File; | ||
|
||
|
||
public class ASMClass extends ClassNode { | ||
|
||
|
||
private String actualName; | ||
private Boolean anonymous; | ||
private boolean isPrivate = false; | ||
|
||
|
||
public ASMClass() { | ||
super(Opcodes.ASM5); | ||
} | ||
|
||
@Override | ||
public void visit(int version, int access, | ||
String name, String signature, String superName, String[] interfaces) { | ||
super.visit(version, access, name, signature, superName, interfaces); | ||
actualName = name; | ||
isPrivate = access == Opcodes.ACC_PRIVATE; | ||
} | ||
|
||
@Override | ||
public void visitInnerClass(String name, String outer, String innerName, int access) { | ||
super.visitInnerClass(name, outer, innerName, access); | ||
if (name.equals(actualName)) { | ||
anonymous = innerName == null; | ||
} | ||
} | ||
|
||
public Boolean isAnonymous() { | ||
return anonymous != null && anonymous; | ||
} | ||
|
||
public Boolean isMemberClass() { | ||
return anonymous != null && !anonymous; | ||
} | ||
|
||
public String getActualName() { | ||
return actualName; | ||
} | ||
|
||
public Boolean isPrivate() { | ||
return isPrivate; | ||
} | ||
|
||
public String getPackage() { | ||
if (!actualName.contains(File.separator)){ | ||
return null; | ||
} | ||
return getActualName().substring(0, getActualName().lastIndexOf(File.separator) + 1) | ||
.replaceAll(File.separator, "\\."); | ||
} | ||
|
||
public String getSimpleName() { | ||
int index = getActualName().lastIndexOf(File.separator); | ||
if (index != -1){ | ||
return actualName; | ||
} else { | ||
return getActualName().substring(index + 1); | ||
} | ||
} | ||
|
||
public String getCanonicalName() { | ||
return getPackage() + "." + getSimpleName().replaceAll("$", "\\."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters