Search in sources :

Example 11 with TypeDescriptorExtractor

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

the class TypeDescriptorExtractorTests method nonReloadableExtract.

@Test
public void nonReloadableExtract() {
    TypeRegistry tr = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("java.lang.Object");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(tr).extract(bytes, false);
    System.out.println(typeDescriptor.toString());
    Assert.assertEquals("java/lang/Object", typeDescriptor.getName());
    Assert.assertEquals(null, typeDescriptor.getSupertypeName());
    Assert.assertEquals(0, typeDescriptor.getSuperinterfacesName().length);
    Assert.assertEquals(0x21, typeDescriptor.getModifiers());
    Assert.assertEquals(0, typeDescriptor.getFields().length);
    Assert.assertEquals(12, typeDescriptor.getMethods().length);
    Assert.assertNotNull(findMethod("0x104 clone()Ljava/lang/Object; throws java/lang/CloneNotSupportedException", typeDescriptor));
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 12 with TypeDescriptorExtractor

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

the class TypeDescriptorExtractorTests method simpleExtractor.

/**
	 * Test extraction on a very simple class.
	 */
@Test
public void simpleExtractor() {
    TypeRegistry tr = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SimpleClass");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(tr).extract(bytes, true);
    Assert.assertEquals("data/SimpleClass", typeDescriptor.getName());
    Assert.assertEquals("java/lang/Object", typeDescriptor.getSupertypeName());
    Assert.assertEquals(0, typeDescriptor.getSuperinterfacesName().length);
    Assert.assertEquals(0x20, typeDescriptor.getModifiers());
    Assert.assertEquals(0, typeDescriptor.getFields().length);
    Assert.assertEquals(5, typeDescriptor.getMethods().length);
    Assert.assertEquals("0x1 foo()V", typeDescriptor.getMethods()[0].toString());
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 13 with TypeDescriptorExtractor

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

the class TypeDescriptorTests method fieldDescriptors.

@Test
public void fieldDescriptors() {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SomeFields");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, false);
    FieldMember[] fields = typeDescriptor.getFields();
    assertEquals(4, fields.length);
    FieldMember privateField = fields[0];
    assertEquals(Modifier.PRIVATE, privateField.getModifiers());
    assertEquals("privateField", privateField.getName());
    assertEquals("I", privateField.getDescriptor());
    assertNull(privateField.getGenericSignature());
    assertEquals("0x2 I privateField", privateField.toString());
    FieldMember publicField = fields[1];
    assertEquals(Modifier.PUBLIC, publicField.getModifiers());
    assertEquals("publicField", publicField.getName());
    assertEquals("Ljava/lang/String;", publicField.getDescriptor());
    assertNull(publicField.getGenericSignature());
    assertEquals("0x1 Ljava/lang/String; publicField", publicField.toString());
    FieldMember defaultField = fields[2];
    assertEquals(0, defaultField.getModifiers());
    assertEquals("defaultField", defaultField.getName());
    assertEquals("Ljava/util/List;", defaultField.getDescriptor());
    assertEquals("Ljava/util/List<Ljava/lang/String;>;", defaultField.getGenericSignature());
    assertEquals("0x0 Ljava/util/List; defaultField [Ljava/util/List<Ljava/lang/String;>;]", defaultField.toString());
    FieldMember protectedField = fields[3];
    assertEquals(Modifier.PROTECTED, protectedField.getModifiers());
    assertEquals("protectedField", protectedField.getName());
    assertEquals("Ljava/util/Map;", protectedField.getDescriptor());
    assertEquals("Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/lang/Integer;>;>;", protectedField.getGenericSignature());
    assertEquals("0x4 Ljava/util/Map; protectedField [Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/lang/Integer;>;>;]", protectedField.toString());
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) FieldMember(org.springsource.loaded.FieldMember) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Aggregations

TypeDescriptor (org.springsource.loaded.TypeDescriptor)13 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)13 TypeRegistry (org.springsource.loaded.TypeRegistry)13 Test (org.junit.Test)11 MethodMember (org.springsource.loaded.MethodMember)5 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)2 FieldMember (org.springsource.loaded.FieldMember)1