Dynamic Compile Java && Check byte code
- Dynamic compile java source file to byte codes.
- Check which classes and methods are called in the byte codes.
Project Usage
Build
To build the project:
$ git clone git@github.com:baifan/dynamic-compiler.git
$ cd dynamic-compiler
## if you already has `mvn` in path, only use this cmd
## $ mvn compile package install
## if you doesn't has `mvn` in path, then use this cmd
$ ./mvnw compile package install
Binaries
This project does't upload to Maven Central. If you want to use it, you can install to local repository.
<dependency>
<groupId>tech.weyi.dynamic.compiler</groupId>
<artifactId>dynamic-compiler</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Method
Compile java source
import tech.weiyi.dynamic.bytecode.compiler.DynamicCompiler;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;
import java.util.Map;
class TestCompile {
public void testCompile(String clazzName, String clazzSource) {
Map<String, MemoryClazzFile> byteClazzMap = DynamicCompiler.compile(clazzName, clazzSource);
}
}
Analysis clazz element
import tech.weiyi.dynamic.bytecode.analysis.ClazzCallAnalyzer;
import tech.weiyi.dynamic.bytecode.analysis.ClazzElement;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;
import java.util.Map;
import java.util.Set;
class TestAnalysisClazz {
public void testAnalysisClazz(String clazzName, Map<String, MemoryClazzFile> memClsMap) {
MemoryClazzFile memoryClazzFile = memClsMap.get(clazzName);
Set<ClazzElement> clazzElements = ClazzCallAnalyzer.getUsedClassSet(memoryClazzFile.getBytes());
}
}
Analysis method element
import tech.weiyi.dynamic.bytecode.analysis.MethodCallAnalyzer;
import tech.weiyi.dynamic.bytecode.analysis.MethodCallElement;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;
import java.util.Map;
import java.util.Set;
class TestAnalysisMethod {
public void testAnalysisMethod(String clazzName, Map<String, MemoryClazzFile> memClsMap) {
MemoryClazzFile memoryClazzFile = memClsMap.get(clazzName);
Set<MethodCallElement> methodCallElements = MethodCallAnalyzer.getUsedClassSet(memoryClazzFile.getBytes());
}
}