Search in sources :

Example 16 with TypeDescriptor

use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.

the class ReflectiveInterceptor method jlClassGetDeclaredFields.

public static Field[] jlClassGetDeclaredFields(Class<?> clazz) {
    Field[] fields = clazz.getDeclaredFields();
    ReloadableType rtype = getRType(clazz);
    if (rtype == null) {
        return fields;
    } else {
        if (!rtype.hasBeenReloaded()) {
            //Not reloaded yet...
            fields = removeMetaFields(fields);
            fixModifiers(rtype, fields);
            return fields;
        } else {
            // Was reloaded, it's up to us to create the field objects
            TypeDescriptor typeDesc = rtype.getLatestTypeDescriptor();
            FieldMember[] members = typeDesc.getFields();
            fields = new Field[members.length];
            int i = 0;
            for (FieldMember f : members) {
                String fieldTypeDescriptor = f.getDescriptor();
                Class<?> type;
                try {
                    type = Utils.toClass(Type.getType(fieldTypeDescriptor), rtype.typeRegistry.getClassLoader());
                } catch (ClassNotFoundException e) {
                    throw new IllegalStateException(e);
                }
                fields[i++] = JVM.newField(clazz, type, f.getModifiers(), f.getName(), f.getGenericSignature());
            }
            if (GlobalConfiguration.assertsMode) {
                Utils.assertTrue(i == fields.length, "Bug: unexpected number of fields");
            }
            return fields;
        }
    }
}
Also used : Field(java.lang.reflect.Field) ReloadableType(org.springsource.loaded.ReloadableType) TypeDescriptor(org.springsource.loaded.TypeDescriptor) FieldMember(org.springsource.loaded.FieldMember)

Example 17 with TypeDescriptor

use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.

the class ReflectiveInterceptor method isDeleted.

private static boolean isDeleted(Field field) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(field.getDeclaringClass());
    if (rtype == null) {
        return false;
    } else {
        TypeDescriptor desc = rtype.getLatestTypeDescriptor();
        FieldMember currentField = desc.getField(field.getName());
        if (currentField == null) {
            // Method not there, consider it deleted
            return true;
        } else {
            return false;
        }
    // Fields don't have deleted bits now, but maybe they get them in the future?
    //			} else {
    //				return FieldMember.isDeleted(currentField); // Deleted bit is set consider deleted
    //			}
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeDescriptor(org.springsource.loaded.TypeDescriptor) FieldMember(org.springsource.loaded.FieldMember)

Example 18 with TypeDescriptor

use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.

the class IncrementalTypeDescriptorTests method simpleExtractor.

/**
	 * Test comparison of two simple classes.
	 */
@Test
public void simpleExtractor() {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SimpleClass");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
    byte[] bytes2 = ClassRenamer.rename("data.SimpleClass", loadBytesForClass("data.SimpleClass002"));
    TypeDescriptor typeDescriptor2 = new TypeDescriptorExtractor(registry).extract(bytes2, true);
    IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
    itd.setLatestTypeDescriptor(typeDescriptor2);
    List<MethodMember> newMethods = itd.getNewOrChangedMethods();
    Assert.assertEquals(1, newMethods.size());
    Assert.assertEquals("0x1 bar()Ljava/lang/String;", newMethods.get(0).toString());
    List<MethodMember> deletedMethods = itd.getDeletedMethods();
    Assert.assertEquals(1, deletedMethods.size());
    Assert.assertEquals("0x1 foo()V", deletedMethods.get(0).toString());
}
Also used : IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeDescriptor(org.springsource.loaded.TypeDescriptor) IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 19 with TypeDescriptor

use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.

the class IncrementalTypeDescriptorTests method deletedMethods2.

// overridden (caught) method deleted
@Test
public void deletedMethods2() throws Exception {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("typedescriptor.B");
    TypeDescriptor typeDescriptor = registry.getExtractor().extract(bytes, true);
    byte[] bytes2 = ClassRenamer.rename("typedescriptor.B", loadBytesForClass("typedescriptor.B2"));
    TypeDescriptor typeDescriptor2 = registry.getExtractor().extract(bytes2, true);
    IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
    itd.setLatestTypeDescriptor(typeDescriptor2);
    List<MethodMember> deleted = itd.getDeletedMethods();
    System.out.println(deleted);
    Assert.assertEquals(1, deleted.size());
    Assert.assertEquals("0x1 m()V", deleted.get(0).toString());
}
Also used : IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeDescriptor(org.springsource.loaded.TypeDescriptor) IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Example 20 with TypeDescriptor

use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.

the class InterfaceExtractorTest method simpleExtraction.

/**
	 * Attempt simple interface extraction for a class with one void no-arg method
	 */
@Test
public void simpleExtraction() {
    TypeRegistry registry = getTypeRegistry(null);
    byte[] classBytes = loadBytesForClass("data.SimpleClass");
    TypeDescriptor td = new TypeDescriptorExtractor(registry).extract(classBytes, true);
    // @formatter:off
    checkType(classBytes, "CLASS: data/SimpleClass v50 0x0020(synchronized) super java/lang/Object\n" + "SOURCE: SimpleClass.java null\n" + "METHOD: 0x0000() <init>()V\n" + "    CODE\n" + " L0\n" + "    ALOAD 0\n" + "    INVOKESPECIAL java/lang/Object.<init>()V\n" + "    RETURN\n" + " L1\n" + "METHOD: 0x0001(public) foo()V\n" + "    CODE\n" + " L0\n" + "    RETURN\n" + " L1\n" + "\n");
    // @formatter:on
    byte[] bytes = InterfaceExtractor.extract(classBytes, registry, td);
    // @formatter:off
    checkType(bytes, "CLASS: data/SimpleClass__I v50 0x0601(public abstract interface) super java/lang/Object\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClass;)V\n" + "METHOD: 0x0401(public abstract) foo(Ldata/SimpleClass;)V\n" + "METHOD: 0x0401(public abstract) __execute([Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + "METHOD: 0x0401(public abstract) ___clinit___()V\n" + "METHOD: 0x0401(public abstract) hashCode(Ldata/SimpleClass;)I\n" + "METHOD: 0x0401(public abstract) equals(Ldata/SimpleClass;Ljava/lang/Object;)Z\n" + "METHOD: 0x0401(public abstract) clone(Ldata/SimpleClass;)Ljava/lang/Object; java/lang/CloneNotSupportedException\n" + "METHOD: 0x0401(public abstract) toString(Ldata/SimpleClass;)Ljava/lang/String;\n" + "\n");
// @formatter:on
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Aggregations

TypeDescriptor (org.springsource.loaded.TypeDescriptor)25 TypeRegistry (org.springsource.loaded.TypeRegistry)20 Test (org.junit.Test)18 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)13 MethodMember (org.springsource.loaded.MethodMember)10 ReloadableType (org.springsource.loaded.ReloadableType)6 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)4 FieldMember (org.springsource.loaded.FieldMember)3 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1