use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.
the class CatcherTests method rewrite.
/*
* Details on catchers
*
* Four types of method in the super type to think about:
* - private
* - protected
* - default
* - public
*
* And things to keep in mind:
* - private methods are not overridable (invokespecial is used to call them)
* - visibility cannot be reduced, only widened
* - static methods are not overridable
*
* Catching rules:
* - don't need a catcher for a private method, there cannot be code out there that calls it with INVOKEVIRTUAL
* - visibility is preserved except for protected/default, which is widened to public - this enables the executor to call the
* catcher. Doesn't seem to have any side effects (doesn't limit the ability for an overriding method in a further
* subclass to have been declared initially protected).
*/
@Test
public void rewrite() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("catchers.B");
loadClass("catchers.A");
TypeDescriptor typeDescriptor = typeRegistry.getExtractor().extract(loadBytesForClass("catchers.B"), true);
checkDoesNotContain(typeDescriptor, "privateMethod");
checkDoesContain(typeDescriptor, "0x1 publicMethod");
checkDoesContain(typeDescriptor, "0x1 protectedMethod");
checkDoesContain(typeDescriptor, "0x1 defaultMethod");
ReloadableType rtype = typeRegistry.addType("catchers.B", loadBytesForClass("catchers.B"));
reload(rtype, "2");
}
use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.
the class ReflectiveInterceptor method isDeleted.
private static boolean isDeleted(Constructor<?> c) {
ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(c.getDeclaringClass());
if (rtype == null) {
return false;
} else {
TypeDescriptor desc = rtype.getLatestTypeDescriptor();
MethodMember currentConstructor = desc.getConstructor(Type.getConstructorDescriptor(c));
if (currentConstructor == null) {
// Method not there, consider it deleted
return true;
} else {
return false;
}
}
}
use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.
the class ClassReflectionTests method testSomeBug.
@Test
public void testSomeBug() throws Exception {
reloadableClass(TARGET_PACKAGE + ".GetMethodInterface");
String className = TARGET_PACKAGE + ".GetMethodClass";
ReloadableType rtype = reloadableClass(className);
reloadType(rtype, "002");
TypeDescriptor descriptor = rtype.getLatestTypeDescriptor();
for (MethodMember m : descriptor.getMethods()) {
System.out.println(m);
if (m.getName().equals("im2")) {
//Fine!
return;
}
}
fail("There should be an im2 method");
}
use of org.springsource.loaded.TypeDescriptor 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());
}
use of org.springsource.loaded.TypeDescriptor in project spring-loaded by spring-projects.
the class IncrementalTypeDescriptorTests method changedModifiers.
// More subtle changes (modifier flags)
@Test
public void changedModifiers() throws Exception {
TypeRegistry registry = getTypeRegistry("");
byte[] bytes = loadBytesForClass("typedescriptor.C");
TypeDescriptor typeDescriptor = registry.getExtractor().extract(bytes, true);
byte[] bytes2 = ClassRenamer.rename("typedescriptor.C", loadBytesForClass("typedescriptor.C2"));
TypeDescriptor typeDescriptor2 = registry.getExtractor().extract(bytes2, true);
IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
itd.setLatestTypeDescriptor(typeDescriptor2);
System.out.println(itd.toString(true));
List<MethodMember> changed = itd.getNewOrChangedMethods();
MethodMember m = getMethod(changed, "staticMethod");
Assert.assertTrue(IncrementalTypeDescriptor.isNowNonStatic(m));
m = getMethod(changed, "instanceMethod");
Assert.assertTrue(IncrementalTypeDescriptor.isNowStatic(m));
m = getMethod(changed, "publicMethod1");
Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
// TODO Not detected as protected methods always made public in reloadable types... is that OK?
// m = getMethod(changed, "publicMethod2");
// Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
m = getMethod(changed, "publicMethod3");
Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
}
Aggregations