Package org.fakereplace.data

Examples of org.fakereplace.data.FieldData


        // is exactly compatible with the old class, otherwise an
        // IncompatibleClassChange exception will be thrown

        while (it.hasNext()) {
            FieldInfo m = (FieldInfo) it.next();
            FieldData md = null;
            for (FieldData i : fields) {
                if (i.getName().equals(m.getName()) && i.getType().equals(m.getDescriptor()) && i.getAccessFlags() == m.getAccessFlags()) {
                    try {
                        Field field = i.getField(oldClass);
                        AnnotationDataStore.recordFieldAnnotations(field, (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag));
                        // now revert the annotations:
                        m.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), field));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    md = i;
                    break;
                } else if (i.getName().equals(m.getName()) && i.getType().equals(m.getDescriptor())) {
                    // we have a field whoes access modifiers have changed.
                    if ((i.getAccessFlags() | AccessFlag.STATIC) == (m.getAccessFlags() | AccessFlag.STATIC)) {
                        // change from / to static can be handled fine
                    }
                }
            }
            // This is a newly added field.
            if (md == null) {
                if ((m.getAccessFlags() & AccessFlag.STATIC) != 0) {
                    addStaticField(file, loader, m, builder, oldClass);
                } else {
                    int fieldNo = addInstanceField(file, loader, m, builder, oldClass);
                    addedFields.add(new AddedFieldData(fieldNo, m.getName(), m.getDescriptor(), file.getName(), loader));
                    noAddedFields++;
                }
                it.remove();
            } else {
                fields.remove(md);
            }
        }
        // these fields have been removed,
        // TODO: rewrite classes that access them to throw a NoSuchFieldError
        for (FieldData md : fields) {
            if (md.getMemberType() == MemberType.NORMAL) {
                FieldInfo old = new FieldInfo(file.getConstPool(), md.getName(), md.getType());
                old.setAccessFlags(md.getAccessFlags());
                builder.removeField(md);
                try {
                    Field field = md.getField(oldClass);
                    file.addField(old);
                    old.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), field));
                } catch (DuplicateMemberException e) {
                    // this should not happen
                    throw new RuntimeException(e);
View Full Code Here


        ClassData cd = ClassDataStore.instance().getModifiedClassData(clazz.getClassLoader(), Descriptor.toJvmName(clazz.getName()));

        if (cd == null) {
            return clazz.getField(name);
        }
        FieldData fd = cd.getField(name);
        if (fd == null) {
            return clazz.getField(name);
        }
        if (!AccessFlag.isPublic(fd.getAccessFlags())) {
            throw new NoSuchFieldException(clazz.getName() + "." + name);
        }
        switch (fd.getMemberType()) {

            case NORMAL:
                return clazz.getField(name);
            case FAKE:
                try {
                    Class<?> c = clazz.getClassLoader().loadClass(fd.getClassName());
                    return c.getField(name);

                } catch (NoSuchFieldException e) {
                    throw e;
                } catch (Exception e) {
View Full Code Here

        ClassData cd = ClassDataStore.instance().getModifiedClassData(clazz.getClassLoader(), Descriptor.toJvmName(clazz.getName()));

        if (cd == null) {
            return clazz.getDeclaredField(name);
        }
        FieldData fd = cd.getField(name);
        if (fd == null) {
            return clazz.getDeclaredField(name);
        }

        switch (fd.getMemberType()) {
            case NORMAL:
                return clazz.getDeclaredField(name);
            case FAKE:
                try {
                    Class<?> c = clazz.getClassLoader().loadClass(fd.getClassName());
                    return c.getDeclaredField(name);
                } catch (NoSuchFieldException e) {
                    throw e;
                } catch (Exception e) {
                    throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of org.fakereplace.data.FieldData

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.