/** * Creates a new annotation. * If there already exists a class/interface with the same name, * the new interface overwrites that previous one. * * @param name a fully-qualified interface name. * Or null if the annotation has no super interface. * @throws RuntimeException if the existing interface is frozen. * @since 3.19 */ public CtClass makeAnnotation(String name) throws RuntimeException { try { CtClass cc = makeInterface(name, get("java.lang.annotation.Annotation")); cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); return cc; } catch (NotFoundException e) { // should never happen. throw new RuntimeException(e.getMessage(), e); } }
@Override protected void insertCode(List<CtClass> box, File jarFile) throws IOException, CannotCompileException { ZipOutputStream outStream = new JarOutputStream(new FileOutputStream(jarFile)); //get every class in the box ,ready to insert code for (CtClass ctClass : box) { //change modifier to public ,so all the class in the apk will be public ,you will be able to access it in the patch ctClass.setModifiers(AccessFlag.setPublic(ctClass.getModifiers())); if (isNeedInsertClass(ctClass.getName()) && !(ctClass.isInterface() || ctClass.getDeclaredMethods().length < 1)) { //only insert code into specific classes zipFile(transformCode(ctClass.toBytecode(), ctClass.getName().replaceAll("\\.", "/")), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class"); } else { zipFile(ctClass.toBytecode(), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class"); } } outStream.close(); }
/** * Creates a new annotation. * If there already exists a class/interface with the same name, * the new interface overwrites that previous one. * * @param name a fully-qualified interface name. * Or null if the annotation has no super interface. * @throws RuntimeException if the existing interface is frozen. * @since 3.19 */ public CtClass makeAnnotation(String name) throws RuntimeException { try { CtClass cc = makeInterface(name, get("java.lang.annotation.Annotation")); cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); return cc; } catch (NotFoundException e) { // should never happen. throw new RuntimeException(e.getMessage(), e); } }
targetCt.setModifiers(Modifier.FINAL); targetCt.setModifiers(Modifier.PUBLIC);
if (isNeedInsertClass(ctClass.getName())) { ctClass.setModifiers(AccessFlag.setPublic(ctClass.getModifiers())); if (ctClass.isInterface() || ctClass.getDeclaredMethods().length < 1) {
CtClass addSerializationMethods( CtClass cc ) throws CannotCompileException, NotFoundException { if( cc.subclassOf(_enum) ) exposeRawEnumArray(cc); if( cc.subclassOf(_iced) ) ensureAPImethods(cc); if( cc.subclassOf(_iced) || cc.subclassOf(_dtask)|| cc.subtypeOf(_freezable)) { cc.setModifiers(javassist.Modifier.setPublic(cc.getModifiers())); ensureSerMethods(cc); ensureNullaryCtor(cc); ensureNewInstance(cc); ensureType(cc); } return cc; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static Class<? extends Enum> createEnum(ClassLoader classLoader, String clsName, List<String> values) { if (values == null || values.size() == 0) { throw new Error("values is not allowed empty."); } classLoader = JvmUtils.correctClassLoader(classLoader); ClassPool classPool = getOrCreateClassPool(classLoader); CtClass ctClass = classPool.makeClass(clsName); ctClass.setModifiers(ctClass.getModifiers() | javassist.Modifier.ENUM); try { ctClass.setSuperclass(classPool.get(Enum.class.getName())); addEnumConstructor(classPool, ctClass); addEnumValuesMethod(ctClass, values); return ctClass.toClass(classLoader, null); } catch (Throwable e) { throw new Error(e); } }
public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException { CtClass ctClass = pool.get(classname); int modifiers = ctClass.getModifiers(); if (!Modifier.isPublic(modifiers)) { ctClass.setModifiers(modifiers + Modifier.PUBLIC); } }
public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException { CtClass ctClass = pool.get(classname); int modifiers = ctClass.getModifiers(); if (!Modifier.isPublic(modifiers)) { ctClass.setModifiers(modifiers + Modifier.PUBLIC); } }
private void injectClassHandlerToInstrumentedClasses(ClassPool classPool) throws NotFoundException, CannotCompileException { int index; synchronized (CLASS_HANDLERS) { CLASS_HANDLERS.add(classHandler); index = CLASS_HANDLERS.size() - 1; } CtClass robolectricInternalsCtClass = classPool.get(RobolectricInternals.class.getName()); robolectricInternalsCtClass.setModifiers(Modifier.PUBLIC); robolectricInternalsCtClass.getClassInitializer().insertBefore("{\n" + "classHandler = " + AndroidTranslator.class.getName() + ".getClassHandler(" + index + ");\n" + "}"); }
@InitMethod static void init(CtClass ctClass) { // set GwtTransient class public ctClass.setModifiers(ctClass.getModifiers() + Modifier.PUBLIC); }
@InitMethod static void init(CtClass ctClass) { // set GwtTransient class public ctClass.setModifiers(ctClass.getModifiers() + Modifier.PUBLIC); }
/** * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it. */ public static CtClass makeNestedClass(CtClass outer, String name, boolean isStatic, int modifiers, CtClass superClass) throws CannotCompileException { CtClass inner = makeNestedClass(outer, name, true); inner.setModifiers(modifiers); inner.setSuperclass(superClass); return inner; }
public void modify(CtClass classToModify) throws Exception { int modifiers = classToModify.getModifiers(); if (!Modifier.isPublic(modifiers)) { classToModify.setModifiers(modifiers + Modifier.PUBLIC); } }
private CtClass setupClass()throws NotFoundException, CannotCompileException { String className = getGeneratedJoinPointClassName(callingIndex, targetClass.getName(), calledHash); //Create inner joinpoint class in advised class, super class is ConstructorInvocation jp = TransformerCommon.makeNestedClass(callingClass, className, true); int mod = jp.getModifiers(); jp.setModifiers(mod | Modifier.PUBLIC); CtClass invocation = INVOCATION_CT_TYPE; jp.setSuperclass(invocation); addUntransformableInterface(instrumentor, jp); return jp; }
private CtClass setupClass()throws NotFoundException, CannotCompileException { String className = getGeneratedJoinPointClassName(callingHash, targetClass.getName(), calledHash); //Create inner joinpoint class in advised class, super class is ConstructorInvocation jp = TransformerCommon.makeNestedClass(callingClass, className, true); int mod = jp.getModifiers(); jp.setModifiers(mod | Modifier.PUBLIC); CtClass invocation = INVOCATION_CT_TYPE; jp.setSuperclass(invocation); addUntransformableInterface(instrumentor, jp); return jp; }
private CtClass setupClass()throws NotFoundException, CannotCompileException { String className = getGeneratedJoinPointClassName(originalMethodName, hash); //Create inner joinpoint class in advised class, super class is MethodInvocation jp = TransformerCommon.makeNestedClass(advisedClass, className, true); int mod = jp.getModifiers(); jp.setModifiers(mod | Modifier.PUBLIC); CtClass methodInvocation = INVOCATION_CT_TYPE; jp.setSuperclass(methodInvocation); addUntransformableInterface(instrumentor, jp); return jp; }
private CtClass loadInterface(Node node) { CtClass klass = createInterface(node); int mod = decodeModifiers(ConfigFileUtil.getNodeAttribute(node, "modifiers")); mod |= Modifier.INTERFACE | Modifier.ABSTRACT; klass.setModifiers(mod); loadHierarchy(klass, node); loadMethods(klass, node); loadFields(klass, node); return klass; }
private static void transform(final CtClass clazz, final String name) { try { final int modifiers = clazz.getModifiers(); if (Modifier.isPackage(modifiers)) { if (isNotSystemClass(name) && !(clazz.isInterface() && clazz.getDeclaringClass() != null)) { clazz.setModifiers(Modifier.setPublic(modifiers)); } } } catch (NotFoundException e) { // OK, continue } }
private CtClass loadClass(Node node) { CtClass klass = createClass(node); int mod = decodeModifiers(ConfigFileUtil.getNodeAttribute(node, "modifiers")); klass.setModifiers(mod); loadHierarchy(klass, node); loadConstructors(klass, node); loadMethods(klass, node); loadFields(klass, node); return klass; }