Package org.fakereplace.data

Examples of org.fakereplace.data.MethodData


        // and old. in the process we modify the new class so that is's signature
        // is exactly compatible with the old class, otherwise an
        // IncompatibleClassChange exception will be thrown
        while (it.hasNext()) {
            MethodInfo m = (MethodInfo) it.next();
            MethodData md = null;
            boolean upgradedVisibility = false;
            for (MethodData i : methods) {
                if (i.getMethodName().equals(m.getName()) && i.getDescriptor().equals(m.getDescriptor())) {

                    // if the access flags do not match then what we need to do
                    // depends on what has changed
                    if (i.getAccessFlags() != m.getAccessFlags()) {
                        if (AccessFlagUtils.upgradeVisibility(m.getAccessFlags(), i.getAccessFlags())) {
                            upgradedVisibility = true;
                        } else if (AccessFlagUtils.downgradeVisibility(m.getAccessFlags(), i.getAccessFlags())) {
                            // ignore this, we don't need to do anything
                        } else {
                            // we can't handle this yet
                            continue;
                        }
                    }
                    m.setAccessFlags(i.getAccessFlags());

                    // if it is the constructor
                    if (m.getName().equals("<init>")) {
                        try {
                            Constructor<?> meth = i.getConstructor(oldClass);
                            AnnotationDataStore.recordConstructorAnnotations(meth, (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag));
                            // now revert the annotations:
                            m.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), meth));
                            m.addAttribute(AnnotationReplacer.duplicateParameterAnnotationsAttribute(file.getConstPool(), meth));
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    } else if (!m.getName().equals("<clinit>")) {
                        // other methods
                        // static constructors cannot have annotations so
                        // we do not have to worry about them
                        try {
                            Method meth = i.getMethod(oldClass);
                            AnnotationDataStore.recordMethodAnnotations(meth, (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag));
                            AnnotationDataStore.recordMethodParameterAnnotations(meth, (ParameterAnnotationsAttribute) m.getAttribute(ParameterAnnotationsAttribute.visibleTag));
                            // now revert the annotations:
                            m.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), meth));
                            m.addAttribute(AnnotationReplacer.duplicateParameterAnnotationsAttribute(file.getConstPool(), meth));
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }

                    md = i;
                    break;
                }
            }
            // we do not need to deal with these
            if (m.getName().equals(Constants.ADDED_METHOD_NAME) || m.getName().equals(Constants.ADDED_STATIC_METHOD_NAME)) {
                break;
            }
            // This is a newly added method.
            // or the visilbility has been upgraded
            // with the visiblity upgrade we just copy the method
            // so it is still in the original
            if (md == null || upgradedVisibility) {
                if ((m.getAccessFlags() & AccessFlag.STATIC) != 0) {
                    Class<?> c = addMethod(file, loader, m, builder, staticCodeAttribute, true, oldClass);
                    if (c != null) {
                        superclassesToHotswap.add(c);
                    }
                } else if ((m.getName().equals("<init>"))) {
                    addConstructor(file, loader, m, builder, constructorCodeAttribute, oldClass);
                } else if (m.getName().equals("<clinit>")) {
                    // nop, we can't change this, just ignore it
                } else {
                    Class<?> c = addMethod(file, loader, m, builder, virtualCodeAttribute, false, oldClass);
                    if (c != null) {
                        superclassesToHotswap.add(c);
                    }
                }
                if (!upgradedVisibility) {
                    it.remove();
                }
            } else if (md != null) {
                methods.remove(md);
            }
            if (upgradedVisibility && md != null) {
                methods.remove(md);
            }
        }
        // these methods have been removed, change them to throw a
        // MethodNotFoundError

        for (MethodData md : methods) {
            if (md.getType() == MemberType.NORMAL) {
                createRemovedMethod(file, md, oldClass, builder);
            }
        }

        // if we did not return from a virtual method we need to call the parent
View Full Code Here


            if (!staticMethod) {
                newMethodDesc = "(L" + Descriptor.toJvmName(file.getName()) + ";" + newMethodDesc.substring(1);
            }
            Transformer.getManipulator().replaceVirtualMethodInvokationWithStatic(file.getName(), proxyName, mInfo.getName(), mInfo.getDescriptor(), newMethodDesc, loader);

            MethodData md = builder.addFakeMethod(mInfo.getName(), mInfo.getDescriptor(), proxyName, mInfo.getAccessFlags());
            ClassDataStore.instance().registerReplacedMethod(proxyName, md);
            if (!staticMethod) {
                Class<?> sup = oldClass.getSuperclass();
                while (sup != null) {
                    for (Method m : sup.getDeclaredMethods()) {
View Full Code Here

        try {
            generateBoxedConditionalCodeBlock(methodCount, mInfo, file.getConstPool(), bytecode, false, true);
            String proxyName = generateFakeConstructorBytecode(mInfo, file.getConstPool(), methodCount, file.getName(), loader);
            ClassDataStore.instance().registerProxyName(oldClass, proxyName);
            Transformer.getManipulator().rewriteConstructorAccess(file.getName(), mInfo.getDescriptor(), methodCount, loader);
            MethodData md = builder.addFakeConstructor(mInfo.getName(), mInfo.getDescriptor(), proxyName, mInfo.getAccessFlags(), methodCount);
            ClassDataStore.instance().registerReplacedMethod(proxyName, md);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

        return method.getModifiers();
    }

    public static Object invoke(Method method, Object instance, Object[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        if (!Modifier.isStatic(method.getModifiers())) {
            MethodData info = ClassDataStore.instance().getMethodInformation(method.getDeclaringClass().getName());
            try {
                Method invoke = info.getMethodToInvoke(method.getDeclaringClass());
                Object[] newAgrs = prependInstanceToParams(instance, args);
                return invokeWithPermissionCheck(method, invoke, null, newAgrs);
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            } catch (SecurityException e) {
View Full Code Here

                return clazz.getDeclaredMethods();
            }
            Method[] meth = clazz.getDeclaredMethods();
            List<Method> visible = new ArrayList<Method>(meth.length);
            for (int i = 0; i < meth.length; ++i) {
                MethodData mData = cd.getData(meth[i]);
                if (mData == null || mData.getType() == MemberType.NORMAL) {
                    visible.add(meth[i]);
                }
            }

            for (MethodData i : cd.getMethods()) {
View Full Code Here

            }

            Method[] meth = clazz.getMethods();
            List<Method> visible = new ArrayList<Method>(meth.length);
            for (int i = 0; i < meth.length; ++i) {
                MethodData mData = cd.getData(meth[i]);
                if (mData == null || mData.getType() == MemberType.NORMAL) {
                    visible.add(meth[i]);
                }
            }

            ClassData cta = cd;
View Full Code Here

        if (cd == null) {
            Method meth = clazz.getMethod(name, parameters);
            return meth;
        }
        String args = '(' + DescriptorUtils.classArrayToDescriptorString(parameters) + ')';
        MethodData md = cd.getMethodData(name, args);
        Class<?> superClass = clazz;
        while (superClass.getSuperclass() != null && md == null && superClass != Object.class) {
            superClass = superClass.getSuperclass();
            cd = ClassDataStore.instance().getModifiedClassData(superClass.getClassLoader(), Descriptor.toJvmName(superClass.getName()));
            if (cd != null) {
                md = cd.getMethodData(name, args);
            }
        }

        if (md == null) {
            Method meth = clazz.getMethod(name, parameters);
            return meth;
        }

        switch (md.getType()) {
            case NORMAL:
                Method meth = superClass.getMethod(name, parameters);
                return meth;
            case FAKE:
                try {
                    if (!AccessFlag.isPublic(md.getAccessFlags())) {
                        throw new NoSuchMethodException(clazz.getName() + "." + name);
                    }
                    Class<?> c = superClass.getClassLoader().loadClass(md.getClassName());
                    meth = c.getMethod(name, parameters);
                    return meth;
                } catch (NoSuchMethodException e) {
                    throw e;
                } catch (Exception e) {
View Full Code Here

        if (parameters != null) {
            args = '(' + DescriptorUtils.classArrayToDescriptorString(parameters) + ')';
        } else {
            args = "()";
        }
        MethodData md = cd.getMethodData(name, args);
        if (md == null) {
            Method meth = clazz.getDeclaredMethod(name, parameters);
            return meth;
        }

        switch (md.getType()) {
            case NORMAL:
                Method meth = clazz.getDeclaredMethod(name, parameters);
                return meth;
            case FAKE:
                try {
                    Class<?> c = clazz.getClassLoader().loadClass(md.getClassName());
                    meth = c.getDeclaredMethod(name, parameters);

                    return meth;
                } catch (NoSuchMethodException e) {
                    throw e;
View Full Code Here

public class ConstructorReflection {

    @SuppressWarnings("restriction")
    public static Object newInstance(Constructor<?> method, Object... args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
        final MethodData data = ClassDataStore.instance().getMethodInformation(method.getDeclaringClass().getName());
        final Class<?> info = ClassDataStore.instance().getRealClassFromProxyName(method.getDeclaringClass().getName());
        try {
            final Constructor<?> invoke = info.getConstructor(int.class, Object[].class, ConstructorArgument.class);
            Object ar = args;
            if (ar == null) {
                ar = new Object[0];
            }
            if (!Modifier.isPublic(method.getModifiers()) && !method.isAccessible()) {
                Class<?> caller = sun.reflect.Reflection.getCallerClass(2);
                Reflection.ensureMemberAccess(caller, method.getDeclaringClass(), null, method.getModifiers());
            }
            return invoke.newInstance(data.getMethodNo(), ar, null);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

        if (cd == null || !cd.isReplaceable()) {
            Constructor<?> meth = clazz.getConstructor(parameters);
            return meth;
        }
        String args = '(' + DescriptorUtils.classArrayToDescriptorString(parameters) + ')';
        MethodData md = cd.getMethodData("<init>", args);
        if (md == null) {
            Constructor<?> meth = clazz.getConstructor(parameters);
            return meth;
        }

        switch (md.getType()) {
            case NORMAL:
                Constructor<?> meth = clazz.getConstructor(parameters);
                return meth;
            case FAKE_CONSTRUCTOR:
                try {
                    Class<?> c = clazz.getClassLoader().loadClass(md.getClassName());
                    meth = c.getConstructor(parameters);
                    return meth;
                } catch (NoSuchMethodException e) {
                    throw e;
                } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.fakereplace.data.MethodData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.