com.navisarv.mop.MappingOptimizerPlugin Maven / Gradle / Ivy
The newest version!
package com.navisarv.mop;
import com.navisarv.mop.instrumentation.InstrumentationContext;
import com.navisarv.mop.instrumentation.InstrumentationProcessor;
import com.navisarv.mop.instrumentation.MethodInstrumentation;
import com.navisarv.mop.util.MOPConstants;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.Plugin;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import com.sun.tools.javac.api.BasicJavacTask;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Names;
public class MappingOptimizerPlugin implements Plugin, TaskListener{
private Context context;
private TreeMaker treeMaker;
private Names symbolsTable;
private JavacElements javacElems;
private Log javacLogger;
@Override
public String getName() {
return MOPConstants.MOP_PLUGIN_NAME;
}
@Override
public void init(JavacTask task, String... arg1) {
context = ((BasicJavacTask) task).getContext();
task.addTaskListener(this);
}
@Override
public void finished(TaskEvent event) {
}
@Override
public void started(TaskEvent event) {
if (event.getKind() == TaskEvent.Kind.ENTER && !isContextClosed()) {
CompilationUnitTree compilationUnit = event.getCompilationUnit();
if(compilationUnit == null) {
return;
}
treeMaker = TreeMaker.instance(context);
symbolsTable = Names.instance(context);
javacElems = JavacElements.instance(context);
javacLogger = Log.instance(context);
InstrumentationContext instruContext = new InstrumentationContext(compilationUnit, context, treeMaker, symbolsTable, javacElems, javacLogger);
InstrumentationProcessor mopInstrumentationProcessor = new InstrumentationProcessor(instruContext, new MethodInstrumentation());
mopInstrumentationProcessor.scan(compilationUnit, null);
}
}
private boolean isContextClosed() {
try {
Log.instance(context);
return false;
} catch (Exception e) {
return true;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy