Search in sources :

Example 1 with TypeDescriptorExtractor

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

the class IncrementalTypeDescriptorTests method deletedMethods.

//	@Test
//	public void newversionDescriptor() {
//		byte[] classBytes = loadBytesForClass("data.SimpleClassFour");
//		TypeDescriptor td = TypeDescriptorExtractor.extractFor(classBytes);
//
//		byte[] classBytes2 = retrieveRename("data.SimpleClassFour", "data.SimpleClassFour002");
//		TypeDescriptor td2 = TypeDescriptorExtractor.extractFor(classBytes2);
//
//		IncrementalTypeDescriptor nvtd = new IncrementalTypeDescriptor(td);
//		nvtd.setLatestTypeDescriptor(td2);
//
//		// Now ask it questions about the changes
//		List<MethodMember> ms = nvtd.getNewOrChangedMethods();
//		Assert.assertEquals(2, ms.size());
//
//		MethodMember rm = grabFrom(ms, "extraOne");
//		Assert.assertNotNull(rm);
//		Assert.assertEquals("0x1 extraOne(Ljava/lang/String;)V", rm.toString());
//
//		rm = grabFrom(ms, "extraTwo");
//		Assert.assertNotNull(rm);
//		Assert.assertEquals("0x9 extraTwo(I)Ljava/lang/Double;", rm.toString());
//		//
//		//		boolean b = nvtd.defines(false, "extraOne", "(Ljava/lang/String;)V");
//		//		Assert.assertTrue(b);
//		//
//		//		b = nvtd.defines(true, "extraOne", "(Ljava/lang/String;)V");
//		//		Assert.assertFalse(b);
//	}
// regular method deleted
@Test
public void deletedMethods() throws Exception {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("typedescriptor.A");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
    byte[] bytes2 = ClassRenamer.rename("typedescriptor.A", loadBytesForClass("typedescriptor.A2"));
    TypeDescriptor typeDescriptor2 = new TypeDescriptorExtractor(registry).extract(bytes2, true);
    IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
    itd.setLatestTypeDescriptor(typeDescriptor2);
    Assert.assertEquals(1, itd.getDeletedMethods().size());
    Assert.assertEquals("0x1 m()V", itd.getDeletedMethods().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) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 2 with TypeDescriptorExtractor

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

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

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

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