private void instrumentInstance(Object target, Recorder recorder, InstrumentationFilter filter) throws NonInstrumentableTypeException { Class<?> c = target.getClass(); if (c.isArray()) { throw new NonInstrumentableTypeException("Can't instrument arrays"); } do { for (Method method : c.getDeclaredMethods()) { if (!Modifier.isStatic(method.getModifiers()) && filter.matches(method)) { getContext().add(target, method, TargetSource.FIRST_PARAMETER, recorder); } } c = c.getSuperclass(); } while (getContext().isInstrumentable(c)); } }
private void instrumentClass(Class<?> targetClass, Recorder recorder, InstrumentationFilter filter) throws NonInstrumentableTypeException { if (targetClass.isArray()) { throw new NonInstrumentableTypeException("Can't instrument arrays"); } for (Constructor<?> constructor : targetClass.getDeclaredConstructors()) { getContext().add(targetClass, constructor, recorder); } // Instrument the static methods declared by the target class. Ignore // any parent class. for (Method method : targetClass.getDeclaredMethods()) { if (Modifier.isStatic(method.getModifiers()) && filter.matches(method)) { getContext().add(targetClass, method, TargetSource.CLASS, recorder); } } }
private void disallowSelectiveFilter(InstrumentationFilter filter) throws NonInstrumentableTypeException { if (filter != ALL_INSTRUMENTATION) { throw new NonInstrumentableTypeException( "The Jython instrumenters do not support selective instrumenters"); } }
/** * {@inheritDoc} */ @Override public boolean instrument(Test test, Recorder recorder, Object target, InstrumentationFilter filter) throws NonInstrumentableTypeException { if (target == null) { throw new NonInstrumentableTypeException("Can't instrument null/None"); } final boolean result = super.instrument(test, recorder, target, filter); if (result) { return true; } throw new NonInstrumentableTypeException("Failed to wrap " + target); }
private void checkWrappable(Class<?> theClass) throws NonInstrumentableTypeException { final String whyNot = whyCantIInstrument(theClass); if (whyNot != null) { throw new NonInstrumentableTypeException( "Cannot instrument " + theClass + " because " + whyNot); } }
/** * {@inheritDoc} */ @Override protected void transform(Recorder recorder, PyProxy target) throws NonInstrumentableTypeException { // For some reason, static linking to _getPyInstance fails. final PyObject pyInstance; try { pyInstance = (PyObject) target.getClass().getMethod("_getPyInstance").invoke(target); } catch (Exception e) { throw new NonInstrumentableTypeException(e.getMessage(), e); } instrumentPublicMethodsByName(pyInstance, "invoke", recorder, true); }
throw new NonInstrumentableTypeException( e.getMessage() + " [" + pyReflectedFunction + "]", e);
public void transform(Recorder recorder, PyProxy target) throws NonInstrumentableTypeException { final PyObject pyInstance; try { pyInstance = (PyObject) pyProxyPyInstanceMethod.invoke(target); } catch (Exception e) { throw new NonInstrumentableTypeException( "Could not call _getPyInstance", e); } for (Method method : methodsForPyInstance) { context.add(pyInstance, method, TargetSource.THIRD_PARAMETER, recorder); } context.add(pyInstance, pyReflectedFunctionCall, TargetSource.SECOND_PARAMETER, recorder); } };
private void instrumentInstance(Object target, Recorder recorder, InstrumentationFilter filter) throws NonInstrumentableTypeException { Class<?> c = target.getClass(); if (c.isArray()) { throw new NonInstrumentableTypeException("Can't instrument arrays"); } do { for (Method method : c.getDeclaredMethods()) { if (!Modifier.isStatic(method.getModifiers()) && filter.matches(method)) { getContext().add(target, method, TargetSource.FIRST_PARAMETER, recorder); } } c = c.getSuperclass(); } while (getContext().isInstrumentable(c)); } }
/** * {@inheritDoc} */ @Override public void add(Object target, Method method, TargetSource targetSource, Recorder recorder) throws NonInstrumentableTypeException { checkWrappable(method.getDeclaringClass()); try { final String location = m_weaver.weave(method, targetSource); m_recorderRegistry.register(target, location, recorder); } catch (WeavingException e) { throw new NonInstrumentableTypeException("Weaving failed", e); } // System.out.printf("add(%s, %s, %s, %s)%n", // target.hashCode(), location, // target, // method); }
throw new NonInstrumentableTypeException("Can't instrument arrays");
/** * {@inheritDoc} */ @Override public final boolean instrument(Test test, Recorder recorder, Object target, InstrumentationFilter filter) throws NonInstrumentableTypeException { final boolean changed = instrument(target, recorder, filter); if (changed) { try { m_context.applyChanges(); } catch (WeavingException e) { throw new NonInstrumentableTypeException(e.getMessage()); } } return changed; }
throw new NonInstrumentableTypeException("Unknown PyObject:" + target.getClass());