Java Code Examples for net.bytebuddy.description.type.TypeDefinition#getDeclaredFields()

The following examples show how to use net.bytebuddy.description.type.TypeDefinition#getDeclaredFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lams   File: EnhancerImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Collection<FieldDescription> collectInheritCollectionFields(TypeDefinition managedCtClass) {
	TypeDefinition managedCtSuperclass = managedCtClass.getSuperClass();
	if ( managedCtSuperclass == null || managedCtSuperclass.represents( Object.class ) ) {
		return Collections.emptyList();
	}

	if ( !enhancementContext.isMappedSuperclassClass( managedCtSuperclass.asErasure() ) ) {
		return collectInheritCollectionFields( managedCtSuperclass.asErasure() );
	}
	List<FieldDescription> collectionList = new ArrayList<FieldDescription>();

	for ( FieldDescription ctField : managedCtSuperclass.getDeclaredFields() ) {
		if ( !Modifier.isStatic( ctField.getModifiers() ) ) {
			if ( enhancementContext.isPersistentField( ctField ) && !enhancementContext.isMappedCollection( ctField ) ) {
				if ( ctField.getType().asErasure().isAssignableTo( Collection.class ) || ctField.getType().asErasure().isAssignableTo( Map.class ) ) {
					collectionList.add( ctField );
				}
			}
		}
	}
	collectionList.addAll( collectInheritCollectionFields( managedCtSuperclass ) );
	return collectionList;
}
 
Example 2
private static Collection<FieldDescription> collectInheritPersistentFields(
		TypeDefinition managedCtClass,
		ByteBuddyEnhancementContext enhancementContext) {
	if ( managedCtClass == null || managedCtClass.represents( Object.class ) ) {
		return Collections.emptyList();
	}
	TypeDefinition managedCtSuperclass = managedCtClass.getSuperClass();

	if ( !enhancementContext.isMappedSuperclassClass( managedCtSuperclass.asErasure() ) ) {
		return collectInheritPersistentFields( managedCtSuperclass, enhancementContext );
	}
	log.debugf( "Found @MappedSuperclass %s to collectPersistenceFields", managedCtSuperclass );
	List<FieldDescription> persistentFieldList = new ArrayList<FieldDescription>();

	for ( FieldDescription ctField : managedCtSuperclass.getDeclaredFields() ) {
		if ( ctField.getName().startsWith( "$$_hibernate_" ) || "this$0".equals( ctField.getName() ) ) {
			continue;
		}
		if ( !ctField.isStatic() && enhancementContext.isPersistentField( ctField ) ) {
			persistentFieldList.add( ctField );
		}
	}
	persistentFieldList.addAll( collectInheritPersistentFields( managedCtSuperclass, enhancementContext ) );
	return persistentFieldList;
}