byte[] transform(ClassReader cr,boolean stubNativesOnly){
  boolean hasNativeMethods=hasNativeMethods(cr);
  String className=cr.getClassName();
  String newName=transformName(className);
  if (newName != className) {
    mRenameCount++;
    mClassesNotRenamed.remove(className);
  }
  mLog.debug("Transform %s%s%s%s",className,newName == className ? "" : " (renamed to " + newName + ")",hasNativeMethods ? " -- has natives" : "",stubNativesOnly ? " -- stub natives only" : "");
  ClassWriter cw=new ClassWriter(ClassWriter.COMPUTE_MAXS);
  ClassVisitor rv=cw;
  if (newName != className) {
    rv=new RenameClassAdapter(cw,className,newName);
  }
  ClassVisitor cv=new TransformClassAdapter(mLog,mStubMethods,mDeleteReturns.get(className),newName,rv,stubNativesOnly,stubNativesOnly || hasNativeMethods);
  Set<String> delegateMethods=mDelegateMethods.get(className);
  if (delegateMethods != null && !delegateMethods.isEmpty()) {
    if (hasNativeMethods || !(delegateMethods.size() == 1 && delegateMethods.contains(DelegateClassAdapter.ALL_NATIVES))) {
      cv=new DelegateClassAdapter(mLog,cv,className,delegateMethods);
    }
  }
  cr.accept(cv,0);
  return cw.toByteArray();
}

byte [ ] transform ( ClassReader cr , boolean stubNativesOnly ) { boolean hasNativeMethods = hasNativeMethods ( cr ) ; String className = cr . getClassName ( ) ; String newName = transformName ( className ) ; if ( newName != className ) { mRenameCount ++ ; mClassesNotRenamed . remove ( className ) ; } mLog . debug ( "Transform %s%s%s%s" , className , newName == className ? "" : " (renamed to " + newName + ")" , hasNativeMethods ? " -- has natives" : "" , stubNativesOnly ? " -- stub natives only" : "" ) ; ClassWriter cw = new ClassWriter ( ClassWriter . COMPUTE_MAXS ) ; ClassVisitor rv = cw ; if ( newName != className ) { rv = new RenameClassAdapter ( cw , className , newName ) ; } ClassVisitor cv = new TransformClassAdapter ( mLog , mStubMethods , mDeleteReturns . get ( className ) , newName , rv , stubNativesOnly , stubNativesOnly || hasNativeMethods ) ; Set < String > delegateMethods = mDelegateMethods . get ( className ) ; if ( delegateMethods != null && ! delegateMethods . isEmpty ( ) ) { if ( hasNativeMethods || ! ( delegateMethods . size ( ) == 1 && delegateMethods . contains ( DelegateClassAdapter . ALL_NATIVES ) ) ) { cv = new DelegateClassAdapter ( mLog , cv , className , delegateMethods ) ; } } cr . accept ( cv , 0 ) ; return cw . toByteArray ( ) ; }
transforms a class . < p / > there are 3 kind of transformations : 1 - for " mock " dependencies classes , we want to remove all code from methods and replace by a stub . native methods must be implemented with this stub too . abstract methods are left intact . modified classes must be overridable ( non - private , non - final ) . native methods must be made non - final , non - private . 2 - for " keep " classes , we want to rewrite all native methods as indicated above . if a class has native methods , it must also be made non - private , non - final . note that unfortunately static methods cannot be changed to non - static ( since static and non - static are invoked differently . )
