private void handleCompositeField(CtClass managedCtClass, CtField persistentField, CtMethod fieldWriter) throws NotFoundException, CannotCompileException { if ( !enhancementContext.isCompositeClass( persistentField.getType() ) || !PersistentAttributesHelper.hasAnnotation( persistentField, Embedded.class ) ) { return; } // make sure to add the CompositeOwner interface addCompositeOwnerInterface( managedCtClass ); // cleanup previous owner fieldWriter.insertBefore( String.format( "if (%1$s != null) { ((%2$s) %1$s).%3$s(\"%1$s\"); }%n", persistentField.getName(), CompositeTracker.class.getName(), EnhancerConstants.TRACKER_COMPOSITE_CLEAR_OWNER ) ); // trigger track changes fieldWriter.insertAfter( String.format( "if (%1$s != null) { ((%2$s) %1$s).%4$s(\"%1$s\", (%3$s) this); }%n" + "%5$s(\"%1$s\");", persistentField.getName(), CompositeTracker.class.getName(), CompositeOwner.class.getName(), EnhancerConstants.TRACKER_COMPOSITE_SET_OWNER, EnhancerConstants.TRACKER_CHANGER_NAME ) ); }
method.insertAfter("{" + "durationMillis_java_agent_instrument = System.currentTimeMillis() - startMillis_java_agent_instrument;" + String.format("try{com.uber.profiling.transformers.MethodProfilerStaticProxy.collectMethodDuration(\"%s\", \"%s\", durationMillis_java_agent_instrument);}catch(Throwable ex){ex.printStackTrace();}", normalizedClassName, method.getName()) +
fieldWriter.insertAfter( String.format( " if ($1 != null && %s && $1.%s() != this) { $1.%s(this); }%n", fieldWriter.insertAfter( String.format( " if ($1 != null && %1$s) {%n" + fieldWriter.insertAfter( String.format( " if ($1 != null && %s) {%n" + fieldWriter.insertAfter( String.format( " if ($1 != null && %s) {%n" +
@InitMethod static void initClass(CtClass c) throws CannotCompileException, NotFoundException { CtMethod flushMethod = c.getDeclaredMethod("flush"); flushMethod.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); }
protected static void insertAssertedVerificationCodeAfter( @Nonnull CtMethod method, @Nonnull String verificationCode ) throws CannotCompileException { method.insertAfter(wrapInAssertion(method.getDeclaringClass(), verificationCode)); }
@InitMethod static void initClass(CtClass c) throws CannotCompileException, NotFoundException { CtMethod flushMethod = c.getDeclaredMethod("flush"); flushMethod.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); }
@InitMethod static void initClass(CtClass c) throws CannotCompileException { // every method which calls HasDataPresenter.ensurePendingState() should call // BrowserSimulatorImpl.get().fireLoopEnd() at the end, so finally and deferred // commands would be executed just after the method itself for (CtMethod m : c.getMethods()) { if (methodsToPatch.contains(m.getName())) { m.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); } } }
@InitMethod static void initClass(CtClass c) throws CannotCompileException, NotFoundException { CtMethod fireNativeEvent = c.getMethod( "fireNativeEvent", "(Lcom/google/gwt/dom/client/NativeEvent;Lcom/google/gwt/event/shared/HasHandlers;Lcom/google/gwt/dom/client/Element;)V"); // fire browser event loop first because some command or async callback may modify the DOM // structure + fire NativePreviewHandler fireNativeEvent.insertBefore(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd(); " + DomEventPatcher.class.getName() + ".triggerNativeEvent($1, $3);"); // fire browser event loop at the end because some command may have been scheduled or RPC call // made when the event was dispatched. fireNativeEvent.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); }
@InitMethod static void initClass(CtClass c) throws CannotCompileException, NotFoundException { CtMethod fireNativeEvent = c.getMethod( "fireNativeEvent", "(Lcom/google/gwt/dom/client/NativeEvent;Lcom/google/gwt/event/shared/HasHandlers;Lcom/google/gwt/dom/client/Element;)V"); // fire browser event loop first because some command or async callback may modify the DOM // structure + fire NativePreviewHandler fireNativeEvent.insertBefore(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd(); " + DomEventPatcher.class.getName() + ".triggerNativeEvent($1, $3);"); // fire browser event loop at the end because some command may have been scheduled or RPC call // made when the event was dispatched. fireNativeEvent.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); }
private static void insertMetrics(CtClass fullDAOCtClass, CtMethod daoMethod, CtClass daoInterfaceCtClass) throws CannotCompileException, NotFoundException { final String timerField = createTimerField(fullDAOCtClass, daoMethod, daoInterfaceCtClass); logger.debug("Adding metrics to method " + daoMethod.getName() + "()"); daoMethod.addLocalVariable("__tc", ClassPool.getDefault().get(TimerContext.class.getName())); daoMethod.insertBefore("__tc = this." + timerField + ".time();"); daoMethod.insertAfter("__tc.stop();", false); }
@InitMethod static void initClass(CtClass c) throws CannotCompileException { // every method which calls HasDataPresenter.ensurePendingState() should call // BrowserSimulatorImpl.get().fireLoopEnd() at the end, so finally and deferred // commands would be executed just after the method itself for (CtMethod m : c.getMethods()) { if (methodsToPatch.contains(m.getName())) { m.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();"); } } }
private void instrumentSetText(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setText = c.getDeclaredMethod("setText", setArgs); addTextField(c); setText.insertBefore("this.instrument_oldText = this.getText();"); setText.insertAfter(GwtFinder.class.getName() + ".onSetText(this, $1, this.instrument_oldText);"); } catch (NotFoundException e) { // don't instrument method if not existing } }
private void instrumentSetHTML(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setHTML = c.getDeclaredMethod("setHTML", setArgs); addHTMLField(c); setHTML.insertBefore("this.instrument_oldHTML = this.getHTML();"); setHTML.insertAfter(GwtFinder.class.getName() + ".onSetHTML(this, $1, this.instrument_oldHTML);"); } catch (NotFoundException e) { // don't instrument method if not existing } }
private void instrumentSetText(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setText = c.getDeclaredMethod("setText", setArgs); addTextField(c); setText.insertBefore("this.instrument_oldText = this.getText();"); setText.insertAfter(GwtFinder.class.getName() + ".onSetText(this, $1, this.instrument_oldText);"); } catch (NotFoundException e) { // don't instrument method if not existing } }
private void instrumentSetHTML(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setHTML = c.getDeclaredMethod("setHTML", setArgs); addHTMLField(c); setHTML.insertBefore("this.instrument_oldHTML = this.getHTML();"); setHTML.insertAfter(GwtFinder.class.getName() + ".onSetHTML(this, $1, this.instrument_oldHTML);"); } catch (NotFoundException e) { // don't instrument method if not existing } }
private void instrumentSetName(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setName = c.getDeclaredMethod("setName", setArgs); addTextField(c); setName.insertBefore("this.instrument_oldName = this.getName();"); setName.insertAfter(GwtFinder.class.getName() + ".onSetName(this, $1, this.instrument_oldName);"); } catch (NotFoundException e) { // don't instrument method if not existing } } }
private void addCodeToInitialiseMethod(CtClass clazz, String code, String methodName) throws NotFoundException { CtMethod method = clazz.getDeclaredMethod(methodName); try { method.insertAfter(code); } catch (CannotCompileException e) { e.printStackTrace(); throw new RuntimeException("code was: " + code + " for method " + method.getName()); } }
private void instrumentSetName(CtClass c) throws CannotCompileException { // add behavior to HasHTML.setHTML method try { CtMethod setName = c.getDeclaredMethod("setName", setArgs); addTextField(c); setName.insertBefore("this.instrument_oldName = this.getName();"); setName.insertAfter(GwtFinder.class.getName() + ".onSetName(this, $1, this.instrument_oldName);"); } catch (NotFoundException e) { // don't instrument method if not existing } } }
private void instrumentPost(CtMethod m, Post post) throws CannotCompileException { String postValue = post.value(); if( postValue.trim().equals("")){ postValue = m.getName() + "$Post($$)"; } String postMessage = post.message(); String code = createCode(postValue, postMessage); try { m.insertAfter(code); } catch (CannotCompileException e) { throw new CannotCompileException(code + "\nCaused by: " + e.toString(), e); } }
@Override public void preProcessAnnotatedMethod(T annotation, MethodAnnotationContext context) throws NotFoundException { if (ignoreReturns || !isActive(context)) return; // TODO handle properly Ensure.that(!context.isVoid(), "Context must not be void: %s", context.getMethod().getLongName()); try { context.getMethod().insertAfter(ASSERT_FULLY_QUALIFIED_NAME + createMethodCheck(annotation, context) + ";"); } catch (CannotCompileException e) { logError(context, context.getMethod(), e); throw SoftException.soften(e); } }