use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.
the class DefaultEnhanceTemplate method enhance.
@Override
public InstrumentClass enhance(ExtensionModule module, String className, EnhanceCallback callback) {
IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onClass(className);
final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
callback.doEnhance(instrumentClass);
if (module instanceof ModuleLifecycleAdapter) {
((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
}
instrumentClass.execute();
return instrumentClass;
}
use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.
the class DefaultEnhanceTemplate method enhanceWithInterface.
@Override
public InstrumentClass enhanceWithInterface(ExtensionModule module, String interfaceClassName, EnhanceCallback callback) {
IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onAnyClass().hasInterfaceTypes(interfaceClassName);
final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
callback.doEnhance(instrumentClass);
if (module instanceof ModuleLifecycleAdapter) {
((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
}
instrumentClass.execute();
return instrumentClass;
}
use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.
the class DefaultEnhanceTemplate method enhanceWithSuperClass.
@Override
public InstrumentClass enhanceWithSuperClass(ExtensionModule module, EnhanceCallback callback, String... superClassNames) {
IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onAnyClass().withSuperClass(superClassNames);
final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
callback.doEnhance(instrumentClass);
if (module instanceof ModuleLifecycleAdapter) {
((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
}
instrumentClass.execute();
return instrumentClass;
}
use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.
the class MockPlugin method enhanceClassMethod.
public Map<String, EventWatcher> enhanceClassMethod(Map<String, Set<MockConfig>> configs) {
if (configs == null || configs.isEmpty()) {
return Collections.EMPTY_MAP;
}
Map<String, EventWatcher> watchers = new HashMap<String, EventWatcher>();
for (Map.Entry<String, Set<MockConfig>> entry : configs.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("pre enhance class:{} ,configs:{}", entry.getKey(), entry.getValue());
}
for (MockConfig mockConfig : entry.getValue()) {
IClassMatchBuilder buildingForClass = new EventWatchBuilder(moduleEventWatcher).onClass(entry.getKey());
IBehaviorMatchBuilder buildingForBehavior = buildingForClass.onAnyBehavior(mockConfig.getMethodName());
if (mockConfig.getMethodArgClasses() != null && !mockConfig.getMethodArgClasses().isEmpty()) {
buildingForBehavior.withParameterTypes(mockConfig.getMethodArgClasses().toArray(new String[mockConfig.getMethodArgClasses().size()]));
}
buildingForBehavior.onListener(Listeners.of(MockAdviceListener.class, new Object[] { mockConfig.getCodeScript() }));
watchers.put(mockConfig.getKey(), buildingForClass.onWatch());
}
}
return watchers;
}
Aggregations