java-compiler-api

Best choice? Edit bytecode (asm) or edit java file before compiling

馋奶兔 提交于 2019-12-08 02:56:13
问题 Goal Detecting where comparisons between and copies of variables are made Inject code near the line where the operation has happened The purpose of the code: everytime the class is ran make a counter increase General purpose: count the amount of comparisons and copies made after execution with certain parameters 2 options Note: I always have a .java file to begin with 1) Edit java file Find comparisons with regex and inject pieces of code near the line And then compile the class (My

Is there a tool that we could use to compare two Jars at Binary/Byte code level? [closed]

▼魔方 西西 提交于 2019-12-06 16:05:33
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . The idea is to compare two jars and see if they were generated from same source and compare if they're identical at Binary/Byte code level. Also if they're both compiled with the same compiler i.e. Eclipse JDT or JIT etc compiler. I've looked at Apache Common BCEL, but it only does comparison after decomposing the original byte-code into source code and then it compares it like diff tool; that compares text line

How do I find the type declaration of an identifier using the Java Tree Compiler API?

对着背影说爱祢 提交于 2019-12-06 12:45:31
I have the name of a variable/identifier, say, x , and the JCCompilationUnit and Scope . Is there a way to find the type of x ? public Symbol getSymbol(CompilationUnitTree cut, JCStatement stmt, List<JCExpression> typeParams, Name varName, List<JCExpression> args) { java.util.List<Type> typeSyms = getArgTypes(typeParams, cut, stmt); java.util.List<Type> argsSyms = getArgTypes(args, cut, stmt); final Scope scope = getScope(cut, stmt); Symbol t = contains(scope, typeSyms, varName, argsSyms); //first lookup scope for all public identifiers TypeElement cl = scope.getEnclosingClass(); while (t ==

JavaCompiler not compiling files properly

杀马特。学长 韩版系。学妹 提交于 2019-12-06 12:04:22
问题 I am trying to get used to the JavaCompiler and trying to compile programs with it, I can successfully compile programs that comprises of single file but when im trying to compile projects with multiple files. I get errors on compiling files that implement other classes and where ever the class uses a method from the implemented class. Here is the code that I am using to compile the java code private final String directoryForBin = "C:/TempBINfolder/bin"; public List doCompilation(String

Best choice? Edit bytecode (asm) or edit java file before compiling

ⅰ亾dé卋堺 提交于 2019-12-06 07:40:14
Goal Detecting where comparisons between and copies of variables are made Inject code near the line where the operation has happened The purpose of the code: everytime the class is ran make a counter increase General purpose: count the amount of comparisons and copies made after execution with certain parameters 2 options Note: I always have a .java file to begin with 1) Edit java file Find comparisons with regex and inject pieces of code near the line And then compile the class (My application uses JavaCompiler) 2)Use ASM Bytecode engineering Also detecting where the events i want to track

getJavaFileForOutput(…) method of custom JavaFileManager not called by compiler

与世无争的帅哥 提交于 2019-12-06 06:49:19
I have a custom JavaFileManager that looks something like this: public class InMemoryForwardingFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> { private final Map<String, ByteArrayJavaFileObject> javaFileObjects = new HashMap<>(); @Override public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException{ JavaFileObject fileObject = new ByteArrayJavaFileObject( ... ); javaFileObjects.put(className, fileObject); return fileObject; } @Override public ClassLoader getClassLoader(Location location){ return new

JavaCompiler not compiling files properly

断了今生、忘了曾经 提交于 2019-12-04 17:16:48
I am trying to get used to the JavaCompiler and trying to compile programs with it, I can successfully compile programs that comprises of single file but when im trying to compile projects with multiple files. I get errors on compiling files that implement other classes and where ever the class uses a method from the implemented class. Here is the code that I am using to compile the java code private final String directoryForBin = "C:/TempBINfolder/bin"; public List doCompilation(String sourceCode, String locationOfFile) { List<String> compile = new ArrayList<>(); SimpleJavaFileObject

What is the difference between using javac and javax.tools.JavaCompiler?

放肆的年华 提交于 2019-12-03 03:37:41
问题 Maven Compiler Plugin documentation states: The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse And indeed when forceJavacCompilerUse is not specified in our build there are some build errors, for example when the code references the com.sun. packages

What is the difference between using javac and javax.tools.JavaCompiler?

余生颓废 提交于 2019-12-02 16:37:34
Maven Compiler Plugin documentation states : The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse And indeed when forceJavacCompilerUse is not specified in our build there are some build errors, for example when the code references the com.sun. packages (legacy, we know that its a bad idea...) What are other differences between these two compile modes in

Does javax.tools depend on the JDK?

北慕城南 提交于 2019-11-30 15:23:30
问题 I want to use JavaCompiler to dynamically create some classes. I found the source code of the javax.tools package, but there is no implementation; some posts on the internet say it depends on tools.jar , I am not sure tools.jar associates with JRE. So, can I run the program in a JRE environment without JDK installed? Another question, what is the implementation detail of JavaCompiler , is it creating a new process to invoke the javac command? thanks 回答1: JRE's need to include the interfaces,