com.navisarv.mop.instrumentation.InstrumentationProcessor Maven / Gradle / Ivy
The newest version!
package com.navisarv.mop.instrumentation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePathScanner;
public class InstrumentationProcessor extends TreePathScanner {
private InstrumentationContext context = null;
private List> availInstrumentations = null;
@SafeVarargs
public InstrumentationProcessor(InstrumentationContext instruContext, MOPInstrumentation extends Tree>...instrumentation) {
this.context = instruContext;
availInstrumentations = new ArrayList<>();
if((instrumentation != null) && (instrumentation.length != 0)){
availInstrumentations.addAll(Arrays.asList(instrumentation));
}
}
@Override
public Void visitMethod(MethodTree method, Void v) {
MethodInstrumentation methodInstrumentation = (MethodInstrumentation) findInstrumentation(MethodTree.class);
if(methodInstrumentation != null) {
methodInstrumentation.instrument(method, context);
}
return super.visitMethod(method, v);
}
private MOPInstrumentation extends Tree> findInstrumentation(Class extends Tree> type){
return availInstrumentations.stream().filter(instr-> instr.getInstrumentationType() == type).findFirst().orElse(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy