private CtField[] collectPersistentFields(CtClass managedCtClass) { List<CtField> persistentFieldList = new ArrayList<CtField>(); for ( CtField ctField : managedCtClass.getDeclaredFields() ) { // skip static fields and skip fields added by enhancement and outer reference in inner classes if ( ctField.getName().startsWith( "$$_hibernate_" ) || "this$0".equals( ctField.getName() ) ) { continue; } if ( !Modifier.isStatic( ctField.getModifiers() ) && enhancementContext.isPersistentField( ctField ) ) { persistentFieldList.add( ctField ); } } // HHH-10646 Add fields inherited from @MappedSuperclass // HHH-10981 There is no need to do it for @MappedSuperclass if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) { persistentFieldList.addAll( collectInheritPersistentFields( managedCtClass ) ); } CtField[] orderedFields = enhancementContext.order( persistentFieldList.toArray( new CtField[0] ) ); log.debugf( "Persistent fields for entity %s: %s", managedCtClass.getName(), Arrays.toString( orderedFields ) ); return orderedFields; }
/** * Registers a reflective class. The field accesses to the instances * of this class are instrumented. */ private void registerReflectiveClass(CtClass clazz) { CtField[] fs = clazz.getDeclaredFields(); for (int i = 0; i < fs.length; ++i) { CtField f = fs[i]; int mod = f.getModifiers(); if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) { String name = f.getName(); converter.replaceFieldRead(f, clazz, readPrefix + name); converter.replaceFieldWrite(f, clazz, writePrefix + name); } } }
private Collection<CtField> collectInheritPersistentFields(CtClass managedCtClass) { if ( managedCtClass == null || Object.class.getName().equals( managedCtClass.getName() ) ) { return Collections.emptyList(); } try { CtClass managedCtSuperclass = managedCtClass.getSuperclass(); if ( !enhancementContext.isMappedSuperclassClass( managedCtSuperclass ) ) { return collectInheritPersistentFields( managedCtSuperclass ); } log.debugf( "Found @MappedSuperclass %s to collectPersistenceFields", managedCtSuperclass.getName() ); List<CtField> persistentFieldList = new ArrayList<CtField>(); for ( CtField ctField : managedCtSuperclass.getDeclaredFields() ) { if ( ctField.getName().startsWith( "$$_hibernate_" ) || "this$0".equals( ctField.getName() ) ) { continue; } if ( !Modifier.isStatic( ctField.getModifiers() ) && enhancementContext.isPersistentField( ctField ) ) { persistentFieldList.add( ctField ); } } persistentFieldList.addAll( collectInheritPersistentFields( managedCtSuperclass ) ); return persistentFieldList; } catch ( NotFoundException nfe ) { log.warnf( "Could not find the superclass of %s", managedCtClass ); return Collections.emptyList(); } }
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(); } }
private List<CtField> collectCollectionFields(CtClass managedCtClass) { List<CtField> collectionList = new ArrayList<>(); for ( CtField ctField : managedCtClass.getDeclaredFields() ) { // skip static fields and skip fields added by enhancement if ( Modifier.isStatic( ctField.getModifiers() ) || ctField.getName().startsWith( "$$_hibernate_" ) ) { continue; } if ( enhancementContext.isPersistentField( ctField ) && !enhancementContext.isMappedCollection( ctField ) ) { if ( PersistentAttributesHelper.isAssignable( ctField, Collection.class.getName() ) || PersistentAttributesHelper.isAssignable( ctField, Map.class.getName() ) ) { collectionList.add( ctField ); } } } // HHH-10646 Add fields inherited from @MappedSuperclass // HHH-10981 There is no need to do it for @MappedSuperclass if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) { collectionList.addAll( collectInheritCollectionFields( managedCtClass ) ); } return collectionList; }
CtField[] fields = clazz.getDeclaredFields(); Arrays.sort(fields, new Comparator() { public int compare(Object o1, Object o2) {
/** * Registers a reflective class. The field accesses to the instances * of this class are instrumented. */ private void registerReflectiveClass(CtClass clazz) { CtField[] fs = clazz.getDeclaredFields(); for (int i = 0; i < fs.length; ++i) { CtField f = fs[i]; int mod = f.getModifiers(); if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) { String name = f.getName(); converter.replaceFieldRead(f, clazz, readPrefix + name); converter.replaceFieldWrite(f, clazz, writePrefix + name); } } }
private void processFields(CtClass clazz) throws CannotCompileException, NotFoundException { CtField[] fs = clazz.getDeclaredFields(); for (int i = 0; i < fs.length; ++i) { CtField f = fs[i]; int mod = f.getModifiers(); if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) { mod |= Modifier.STATIC; String name = f.getName(); CtClass ftype = f.getType(); CtMethod wmethod = CtNewMethod.wrapped(ftype, readPrefix + name, readParam, null, trapRead, ConstParameter.string(name), clazz); wmethod.setModifiers(mod); clazz.addMethod(wmethod); CtClass[] writeParam = new CtClass[2]; writeParam[0] = classPool.get("java.lang.Object"); writeParam[1] = ftype; wmethod = CtNewMethod.wrapped(CtClass.voidType, writePrefix + name, writeParam, null, trapWrite, ConstParameter.string(name), clazz); wmethod.setModifiers(mod); clazz.addMethod(wmethod); } } }
private static String getMappedByFromTargetEntity( CtField persistentField, CtClass targetEntity, JavassistEnhancementContext context) throws NotFoundException { // get mappedBy value by searching in the fields of the target entity class for ( CtField f : targetEntity.getDeclaredFields() ) { if ( context.isPersistentField( f ) && getMappedByFromAnnotation( f ).equals( persistentField.getName() ) && isAssignable( persistentField.getDeclaringClass(), inferFieldTypeName( f ) ) ) { log.debugf( "mappedBy association for field [%s#%s] is [%s#%s]", persistentField.getDeclaringClass().getName(), persistentField.getName(), targetEntity.getName(), f.getName() ); return f.getName(); } } return ""; }
CtField[] fields = clazz.getDeclaredFields(); Arrays.sort(fields, new Comparator<CtField>() { @Override
CtField ctfs[] = cc.getDeclaredFields();
private void ensureAPImethods(CtClass cc) throws NotFoundException, CannotCompileException { CtField ctfs[] = cc.getDeclaredFields(); boolean api = false; for( CtField ctf : ctfs ) current = current.getSuperclass(); api = false; for( CtField ctf : current.getDeclaredFields() ) if( ctf.getName().equals("API_WEAVER") ) api = true; boolean first = true; for(CtClass c : classes) { for( CtField ctf : c.getDeclaredFields() ) { int mods = ctf.getModifiers(); if( javassist.Modifier.isStatic(mods) ) {
private void processFields(CtClass clazz) throws CannotCompileException, NotFoundException { CtField[] fs = clazz.getDeclaredFields(); for (int i = 0; i < fs.length; ++i) { CtField f = fs[i]; int mod = f.getModifiers(); if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) { mod |= Modifier.STATIC; String name = f.getName(); CtClass ftype = f.getType(); CtMethod wmethod = CtNewMethod.wrapped(ftype, readPrefix + name, readParam, null, trapRead, ConstParameter.string(name), clazz); wmethod.setModifiers(mod); clazz.addMethod(wmethod); CtClass[] writeParam = new CtClass[2]; writeParam[0] = classPool.get("java.lang.Object"); writeParam[1] = ftype; wmethod = CtNewMethod.wrapped(CtClass.voidType, writePrefix + name, writeParam, null, trapWrite, ConstParameter.string(name), clazz); wmethod.setModifiers(mod); clazz.addMethod(wmethod); } } }
CtField[] fieldsToCopy = template.getDeclaredFields(); for (CtField field : fieldsToCopy) { if (field.hasAnnotation(NonCopied.class)) {
CtField[] fieldsToCopy = template.getDeclaredFields(); for (CtField field : fieldsToCopy) { if (field.hasAnnotation(NonCopied.class)) {
CtClass template = classPool.get(trimmed); CtField[] fieldsToCopy = template.getDeclaredFields();
private synchronized CtClass javassistLoadClass( CtClass cc ) throws NotFoundException, CannotCompileException, BadBytecode { if( cc.isFrozen() ) return cc; // serialize parent javassistLoadClass(cc.getSuperclass()); // Serialize enums first, since we need the raw_enum function for this class for( CtField ctf : cc.getDeclaredFields() ) { CtClass base = ctf.getType(); while( base.isArray() ) base = base.getComponentType(); if( base.subclassOf(_enum) && base != cc ) javassistLoadClass(base); } CtClass ccr = addSerializationMethods(cc); ccr.freeze(); return ccr; }
private Map<String, CtField> buildFieldMap(CtClass ctClass) { Map<String, CtField> fieldMap = new HashMap<>(); CtField[] declaredFields = ctClass.getDeclaredFields(); for (CtField field : declaredFields) { if (options.getFilters().includeField(field)) { String name = field.getName(); fieldMap.put(name, field); } } return fieldMap; }
private void addFieldDependencies(CtClass ctClass, Collection<String> imports) { for (CtField field : ctClass.getDeclaredFields()) { imports.add(DescriptorParser.parseClassNameFromConstantPoolDescriptor(field.getFieldInfo2().getDescriptor())); } }
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); } }