use of javassist.CtField in project powermock by powermock.
the class ClassReplicaCreator method copyFields.
private void copyFields(CtClass originalClassAsCtClass, final CtClass newClass) throws CannotCompileException, NotFoundException {
CtField[] declaredFields = originalClassAsCtClass.getDeclaredFields();
CtField[] undeclaredFields = originalClassAsCtClass.getFields();
Set<CtField> allFields = new HashSet<CtField>();
Collections.addAll(allFields, declaredFields);
Collections.addAll(allFields, undeclaredFields);
for (CtField ctField : allFields) {
CtField f = new CtField(ctField.getType(), ctField.getName(), newClass);
newClass.addField(f);
}
}
use of javassist.CtField in project powermock by powermock.
the class ClassReplicaCreator method addDelegatorField.
/**
* Add a field to the replica class that holds the instance delegator. I.e.
* if we're creating a instance replica of {@code java.lang.Long} this
* methods adds a new field of type {@code delegator.getClass()} to the
* replica class.
*/
private <T> void addDelegatorField(T delegator, final CtClass replicaClass) throws CannotCompileException {
CtField f = CtField.make(String.format("private %s %s = null;", delegator.getClass().getName(), POWERMOCK_INSTANCE_DELEGATOR_FIELD_NAME), replicaClass);
replicaClass.addField(f);
}
use of javassist.CtField in project yyl_example by Relucent.
the class JdwpTest method main.
public static void main(String[] args) throws CannotCompileException, NotFoundException, IOException, IllegalConnectorArgumentsException {
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.makeClass("yyl.test.TestClass");
CtField cf = new CtField(pool.get("java.lang.String"), "name", cc);
cc.addField(cf);
HotSwapper hs = new HotSwapper(1234);
hs.reload(cc.getName(), cc.toBytecode());
cc.toClass();
}
use of javassist.CtField in project uavstack by uavorg.
the class AbstractAdaptor method defineField.
protected void defineField(String fieldName, String fieldClass, String varClass, String initCode) throws CannotCompileException, NotFoundException {
CtClass cc = pool.get(varClass);
String fd = "private " + fieldClass + " " + fieldName;
if (StringHelper.isEmpty(initCode)) {
fd += ";";
} else {
fd += "=" + initCode + ";";
}
CtField f = CtField.make(fd, cc);
cc.addField(f);
}
use of javassist.CtField in project hibernate-orm by hibernate.
the class EntityEnhancer method collectInheritCollectionFields.
private Collection<CtField> collectInheritCollectionFields(CtClass managedCtClass) {
if (managedCtClass == null || Object.class.getName().equals(managedCtClass.getName())) {
return Collections.emptyList();
}
try {
CtClass managedCtSuperclass = managedCtClass.getSuperclass();
if (!enhancementContext.isMappedSuperclassClass(managedCtSuperclass)) {
return collectInheritCollectionFields(managedCtSuperclass);
}
List<CtField> collectionList = new ArrayList<CtField>();
for (CtField ctField : managedCtSuperclass.getDeclaredFields()) {
if (!Modifier.isStatic(ctField.getModifiers())) {
if (enhancementContext.isPersistentField(ctField) && !enhancementContext.isMappedCollection(ctField)) {
if (PersistentAttributesHelper.isAssignable(ctField, Collection.class.getName()) || PersistentAttributesHelper.isAssignable(ctField, Map.class.getName())) {
collectionList.add(ctField);
}
}
}
}
collectionList.addAll(collectInheritCollectionFields(managedCtSuperclass));
return collectionList;
} catch (NotFoundException nfe) {
return Collections.emptyList();
}
}
Aggregations