use of org.springsource.loaded.FieldMember in project spring-loaded by spring-projects.
the class ReflectiveInterceptor method jlClassGetDeclaredFields.
public static Field[] jlClassGetDeclaredFields(Class<?> clazz) {
Field[] fields = clazz.getDeclaredFields();
ReloadableType rtype = getRType(clazz);
if (rtype == null) {
return fields;
} else {
if (!rtype.hasBeenReloaded()) {
//Not reloaded yet...
fields = removeMetaFields(fields);
fixModifiers(rtype, fields);
return fields;
} else {
// Was reloaded, it's up to us to create the field objects
TypeDescriptor typeDesc = rtype.getLatestTypeDescriptor();
FieldMember[] members = typeDesc.getFields();
fields = new Field[members.length];
int i = 0;
for (FieldMember f : members) {
String fieldTypeDescriptor = f.getDescriptor();
Class<?> type;
try {
type = Utils.toClass(Type.getType(fieldTypeDescriptor), rtype.typeRegistry.getClassLoader());
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
fields[i++] = JVM.newField(clazz, type, f.getModifiers(), f.getName(), f.getGenericSignature());
}
if (GlobalConfiguration.assertsMode) {
Utils.assertTrue(i == fields.length, "Bug: unexpected number of fields");
}
return fields;
}
}
}
use of org.springsource.loaded.FieldMember in project spring-loaded by spring-projects.
the class ReflectiveInterceptor method isDeleted.
private static boolean isDeleted(Field field) {
ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(field.getDeclaringClass());
if (rtype == null) {
return false;
} else {
TypeDescriptor desc = rtype.getLatestTypeDescriptor();
FieldMember currentField = desc.getField(field.getName());
if (currentField == null) {
// Method not there, consider it deleted
return true;
} else {
return false;
}
// Fields don't have deleted bits now, but maybe they get them in the future?
// } else {
// return FieldMember.isDeleted(currentField); // Deleted bit is set consider deleted
// }
}
}
use of org.springsource.loaded.FieldMember in project spring-loaded by spring-projects.
the class TypeDescriptorTests method fieldDescriptors.
@Test
public void fieldDescriptors() {
TypeRegistry registry = getTypeRegistry("");
byte[] bytes = loadBytesForClass("data.SomeFields");
TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, false);
FieldMember[] fields = typeDescriptor.getFields();
assertEquals(4, fields.length);
FieldMember privateField = fields[0];
assertEquals(Modifier.PRIVATE, privateField.getModifiers());
assertEquals("privateField", privateField.getName());
assertEquals("I", privateField.getDescriptor());
assertNull(privateField.getGenericSignature());
assertEquals("0x2 I privateField", privateField.toString());
FieldMember publicField = fields[1];
assertEquals(Modifier.PUBLIC, publicField.getModifiers());
assertEquals("publicField", publicField.getName());
assertEquals("Ljava/lang/String;", publicField.getDescriptor());
assertNull(publicField.getGenericSignature());
assertEquals("0x1 Ljava/lang/String; publicField", publicField.toString());
FieldMember defaultField = fields[2];
assertEquals(0, defaultField.getModifiers());
assertEquals("defaultField", defaultField.getName());
assertEquals("Ljava/util/List;", defaultField.getDescriptor());
assertEquals("Ljava/util/List<Ljava/lang/String;>;", defaultField.getGenericSignature());
assertEquals("0x0 Ljava/util/List; defaultField [Ljava/util/List<Ljava/lang/String;>;]", defaultField.toString());
FieldMember protectedField = fields[3];
assertEquals(Modifier.PROTECTED, protectedField.getModifiers());
assertEquals("protectedField", protectedField.getName());
assertEquals("Ljava/util/Map;", protectedField.getDescriptor());
assertEquals("Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/lang/Integer;>;>;", protectedField.getGenericSignature());
assertEquals("0x4 Ljava/util/Map; protectedField [Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/lang/Integer;>;>;]", protectedField.toString());
}
Aggregations