Search in sources :

Example 6 with MethodMember

use of org.springsource.loaded.MethodMember 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 7 with MethodMember

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

the class TypeRewriterTests method constructorReloadingDefault.

// Looking at a type with only a default ctor (so didn't originally declare anything)
@Test
public void constructorReloadingDefault() throws Exception {
    String t = "ctors.Default";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    MethodMember[] ctor = rtype.getLatestTypeDescriptor().getConstructors();
    // Only the ctor in the original type is in the descriptor
    assertEquals(1, ctor.length);
    assertEquals("0x1 <init>()V", ctor[0].toString());
    // There are in fact two constructors, one is our special one
    result = runConstructor(rtype.getClazz(), magicDescriptorForGeneratedCtors, new Object[] { null });
    assertNotNull(result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Example 8 with MethodMember

use of org.springsource.loaded.MethodMember 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)

Example 9 with MethodMember

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

the class TypeDescriptorTests method constructorDescriptorsAfterReloading.

@Test
public void constructorDescriptorsAfterReloading() {
    TypeRegistry registry = getTypeRegistry("");
    String d = "data.SomeConstructors";
    ReloadableType rtype = registry.addType(d, loadBytesForClass(d));
    MethodMember[] latestConstructors = rtype.getLatestTypeDescriptor().getConstructors();
    assertEquals(3, latestConstructors.length);
    rtype.loadNewVersion("2", retrieveRename(d, d + "002"));
    latestConstructors = rtype.getLatestTypeDescriptor().getConstructors();
    assertEquals(1, latestConstructors.length);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Example 10 with MethodMember

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

the class TypeDescriptorTests method defaultConstructorDescriptor.

@Test
public void defaultConstructorDescriptor() {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SomeConstructors2");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, false);
    MethodMember[] ctors = typeDescriptor.getConstructors();
    assertEquals(1, ctors.length);
    MethodMember publicCtor = ctors[0];
    // visibility matches type vis (for public/default)
    assertEquals(Modifier.PUBLIC, publicCtor.getModifiers());
    assertEquals("<init>", publicCtor.getName());
    assertEquals("()V", publicCtor.getDescriptor());
    assertNull(publicCtor.getGenericSignature());
    assertEquals("0x1 <init>()V", publicCtor.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

MethodMember (org.springsource.loaded.MethodMember)17 TypeDescriptor (org.springsource.loaded.TypeDescriptor)10 TypeRegistry (org.springsource.loaded.TypeRegistry)10 Test (org.junit.Test)8 ReloadableType (org.springsource.loaded.ReloadableType)8 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)5 Method (java.lang.reflect.Method)4 CurrentLiveVersion (org.springsource.loaded.CurrentLiveVersion)4 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)3 MethodHandle (java.lang.invoke.MethodHandle)1 MethodHandles (java.lang.invoke.MethodHandles)1 MethodType (java.lang.invoke.MethodType)1 ArrayList (java.util.ArrayList)1 Handle (org.objectweb.asm.Handle)1 Type (org.objectweb.asm.Type)1