public void addCustomShadowClass(String classOrPackageToBeInstrumented) { androidTranslator.addCustomShadowClass(classOrPackageToBeInstrumented); }
@Override public void start(ClassPool classPool) throws NotFoundException, CannotCompileException { injectClassHandlerToInstrumentedClasses(classPool); }
if (classHasFromAndroidEquivalent(className)) { replaceClassWithFromAndroidEquivalent(classPool, className); return; if (shouldInstrument(ctClass)) { int modifiers = ctClass.getModifiers(); if (Modifier.isFinal(modifiers)) {
private boolean declareField(CtClass ctClass, String fieldName, CtClass fieldType) throws CannotCompileException, NotFoundException { CtMethod ctMethod = getMethod(ctClass, "get" + fieldName, ""); if (ctMethod == null) { return false; } CtClass getterFieldType = ctMethod.getReturnType(); if (!getterFieldType.equals(fieldType)) { return false; } if (getField(ctClass, fieldName) == null) { CtField field = new CtField(fieldType, fieldName, ctClass); field.setModifiers(Modifier.PRIVATE); ctClass.addField(field); } return true; }
public RobolectricClassLoader(ClassHandler classHandler, List<String> customClassNames) { super(RobolectricClassLoader.class.getClassLoader(), null); delegateLoadingOf(AndroidTranslator.class.getName()); delegateLoadingOf(ClassHandler.class.getName()); final String classCachePath = System.getProperty("cached.robolectric.classes.path"); final File classCacheDirectory; if (null == classCachePath || "".equals(classCachePath.trim())) { classCacheDirectory = new File("./tmp"); } else { classCacheDirectory = new File(classCachePath); } classCache = new ClassCache(new File(classCacheDirectory, "cached-robolectric-classes.jar").getAbsolutePath(), AndroidTranslator.CACHE_VERSION); try { ClassPool classPool = new ClassPool(); classPool.appendClassPath(new LoaderClassPath(RobolectricClassLoader.class.getClassLoader())); androidTranslator = new AndroidTranslator(classHandler, classCache, customClassNames); addTranslator(classPool, androidTranslator); } catch (NotFoundException e) { throw new RuntimeException(e); } catch (CannotCompileException e) { throw new RuntimeException(e); } }