use of org.springsource.loaded.TypeDescriptorExtractor 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());
}
use of org.springsource.loaded.TypeDescriptorExtractor in project spring-loaded by spring-projects.
the class TypeDescriptorTests method complexMethodDescriptors.
@Test
public void complexMethodDescriptors() {
TypeRegistry registry = getTypeRegistry("data.ComplexClass");
byte[] bytes = loadBytesForClass("data.ComplexClass");
TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
assertEquals("data/ComplexClass", typeDescriptor.getName());
assertEquals("data/SimpleClass", typeDescriptor.getSupertypeName());
assertEquals(1, typeDescriptor.getSuperinterfacesName().length);
assertEquals("java/io/Serializable", typeDescriptor.getSuperinterfacesName()[0]);
assertEquals(0x20, typeDescriptor.getModifiers());
assertEquals(3, typeDescriptor.getFields().length);
assertEquals(9, typeDescriptor.getMethods().length);
assertEquals("0x2 privateMethod()I", typeDescriptor.getMethods()[0].toString());
assertEquals("0x1 publicMethod()Ljava/lang/String;", typeDescriptor.getMethods()[1].toString());
assertEquals("0x0 defaultMethod()Ljava/util/List;", typeDescriptor.getMethods()[2].toString());
assertEquals("0x0 thrower()V throws java/lang/Exception java/lang/IllegalStateException", typeDescriptor.getMethods()[3].toString());
}
use of org.springsource.loaded.TypeDescriptorExtractor in project spring-loaded by spring-projects.
the class IncrementalTypeDescriptorTests method simpleExtractor.
/**
* Test comparison of two simple classes.
*/
@Test
public void simpleExtractor() {
TypeRegistry registry = getTypeRegistry("");
byte[] bytes = loadBytesForClass("data.SimpleClass");
TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
byte[] bytes2 = ClassRenamer.rename("data.SimpleClass", loadBytesForClass("data.SimpleClass002"));
TypeDescriptor typeDescriptor2 = new TypeDescriptorExtractor(registry).extract(bytes2, true);
IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
itd.setLatestTypeDescriptor(typeDescriptor2);
List<MethodMember> newMethods = itd.getNewOrChangedMethods();
Assert.assertEquals(1, newMethods.size());
Assert.assertEquals("0x1 bar()Ljava/lang/String;", newMethods.get(0).toString());
List<MethodMember> deletedMethods = itd.getDeletedMethods();
Assert.assertEquals(1, deletedMethods.size());
Assert.assertEquals("0x1 foo()V", deletedMethods.get(0).toString());
}
use of org.springsource.loaded.TypeDescriptorExtractor in project spring-loaded by spring-projects.
the class InterfaceExtractorTest method simpleExtraction.
/**
* Attempt simple interface extraction for a class with one void no-arg method
*/
@Test
public void simpleExtraction() {
TypeRegistry registry = getTypeRegistry(null);
byte[] classBytes = loadBytesForClass("data.SimpleClass");
TypeDescriptor td = new TypeDescriptorExtractor(registry).extract(classBytes, true);
// @formatter:off
checkType(classBytes, "CLASS: data/SimpleClass v50 0x0020(synchronized) super java/lang/Object\n" + "SOURCE: SimpleClass.java null\n" + "METHOD: 0x0000() <init>()V\n" + " CODE\n" + " L0\n" + " ALOAD 0\n" + " INVOKESPECIAL java/lang/Object.<init>()V\n" + " RETURN\n" + " L1\n" + "METHOD: 0x0001(public) foo()V\n" + " CODE\n" + " L0\n" + " RETURN\n" + " L1\n" + "\n");
// @formatter:on
byte[] bytes = InterfaceExtractor.extract(classBytes, registry, td);
// @formatter:off
checkType(bytes, "CLASS: data/SimpleClass__I v50 0x0601(public abstract interface) super java/lang/Object\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClass;)V\n" + "METHOD: 0x0401(public abstract) foo(Ldata/SimpleClass;)V\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/SimpleClass;)I\n" + "METHOD: 0x0401(public abstract) equals(Ldata/SimpleClass;Ljava/lang/Object;)Z\n" + "METHOD: 0x0401(public abstract) clone(Ldata/SimpleClass;)Ljava/lang/Object; java/lang/CloneNotSupportedException\n" + "METHOD: 0x0401(public abstract) toString(Ldata/SimpleClass;)Ljava/lang/String;\n" + "\n");
// @formatter:on
}
use of org.springsource.loaded.TypeDescriptorExtractor in project spring-loaded by spring-projects.
the class SignatureFinder method gatherConstructorSignatures.
private void gatherConstructorSignatures(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.getConstructors()) {
sigs.add(method.getDescriptor());
}
}
Aggregations