Search in sources :

Example 6 with TypeDescriptor

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

the class InterfaceExtractorTest method varietyOfMethods.

@Test
public void varietyOfMethods() {
    TypeRegistry registry = getTypeRegistry(null);
    byte[] classBytes = loadBytesForClass("data.SimpleClassFour");
    TypeDescriptor td = new TypeDescriptorExtractor(registry).extract(classBytes, true);
    byte[] bytes = InterfaceExtractor.extract(classBytes, registry, td);
    // @formatter:off
    checkType(bytes, "CLASS: data/SimpleClassFour__I v50 0x0601(public abstract interface) super java/lang/Object\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClassFour;I)V\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClassFour;Ljava/lang/String;)V\n" + "METHOD: 0x0401(public abstract) boo(Ldata/SimpleClassFour;)V\n" + "METHOD: 0x0401(public abstract) foo(Ldata/SimpleClassFour;)V\n" + "METHOD: 0x0401(public abstract) goo(Ldata/SimpleClassFour;IDLjava/lang/String;)Ljava/lang/String;\n" + "METHOD: 0x0401(public abstract) hoo(Ldata/SimpleClassFour;J)I\n" + "METHOD: 0x0401(public abstract) woo(Ldata/SimpleClassFour;)V java/lang/RuntimeException java/lang/IllegalStateException\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/SimpleClassFour;)I\n" + "METHOD: 0x0401(public abstract) equals(Ldata/SimpleClassFour;Ljava/lang/Object;)Z\n" + "METHOD: 0x0401(public abstract) clone(Ldata/SimpleClassFour;)Ljava/lang/Object; java/lang/CloneNotSupportedException\n" + "METHOD: 0x0401(public abstract) toString(Ldata/SimpleClassFour;)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)

Example 7 with TypeDescriptor

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

the class SignatureFinder method gatherSignatures.

/**
	 * Gathers up all method signatures in a specific version
	 * 
	 * @throws Exception
	 */
private void gatherSignatures(String typeName, String version, Set<String> sigs) {
    TypeRegistry tr = getTypeRegistry("");
    byte[] bytes = null;
    if (version.equals("")) {
        bytes = loadBytesForClass(typeName);
    } else {
        bytes = retrieveRename(typeName, typeName + version);
    }
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(tr).extract(bytes, true);
    for (MethodMember method : typeDescriptor.getMethods()) {
        sigs.add(method.getNameAndDescriptor());
    }
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor)

Example 8 with TypeDescriptor

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

the class TypeRegistryTests method descriptorsWithCatchers.

@Test
public void descriptorsWithCatchers() {
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    TypeDescriptor dscDescriptor = typeRegistry.getDescriptorFor("data/SimpleClass");
    assertNotNull(dscDescriptor);
    assertEquals("data/SimpleClass", dscDescriptor.getName());
    // check for a catcher
    assertNotNull(findMethod("0x1 toString()Ljava/lang/String;", dscDescriptor));
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 9 with TypeDescriptor

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

the class TypeDescriptorTests method simpleMethodDescriptors.

@Test
public void simpleMethodDescriptors() {
    TypeRegistry registry = getTypeRegistry("data.SimpleClass");
    byte[] bytes = loadBytesForClass("data.SimpleClass");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
    assertEquals("data/SimpleClass", typeDescriptor.getName());
    assertEquals("java/lang/Object", typeDescriptor.getSupertypeName());
    assertEquals(0, typeDescriptor.getSuperinterfacesName().length);
    assertEquals(0x20, typeDescriptor.getModifiers());
    assertEquals(0, typeDescriptor.getFields().length);
    // will include catchers
    assertEquals(5, typeDescriptor.getMethods().length);
    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 10 with TypeDescriptor

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

the class TypeDescriptorTests method constructorDescriptors.

@Test
public void constructorDescriptors() {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SomeConstructors");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, false);
    MethodMember[] ctors = typeDescriptor.getConstructors();
    assertEquals(3, ctors.length);
    MethodMember publicCtor = ctors[0];
    assertEquals(Modifier.PUBLIC, publicCtor.getModifiers());
    assertEquals("<init>", publicCtor.getName());
    assertEquals("()V", publicCtor.getDescriptor());
    assertNull(publicCtor.getGenericSignature());
    assertEquals("0x1 <init>()V", publicCtor.toString());
    MethodMember privateCtor = ctors[1];
    assertEquals(Modifier.PRIVATE, privateCtor.getModifiers());
    assertEquals("<init>", privateCtor.getName());
    assertEquals("(Ljava/lang/String;I)V", privateCtor.getDescriptor());
    assertNull(privateCtor.getGenericSignature());
    assertEquals("0x2 <init>(Ljava/lang/String;I)V", privateCtor.toString());
    MethodMember protCtor = ctors[2];
    assertEquals(Modifier.PROTECTED, protCtor.getModifiers());
    assertEquals("<init>", protCtor.getName());
    assertEquals("(J)V", protCtor.getDescriptor());
    assertNull(protCtor.getGenericSignature());
    assertEquals("0x4 <init>(J)V", protCtor.toString());
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) 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