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

The following examples show how to use net.bytebuddy.description.type.TypeDefinition#represents() . 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;
}
 
Example 3
@Override
protected EqualsMethod equalsMethod(TypeDescription instrumentedType) {
    TypeDefinition typeDefinition = instrumentedType.getSuperClass();
    while (typeDefinition != null && !typeDefinition.represents(Object.class)) {
        if (typeDefinition.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class)) {
            return EqualsMethod.requiringSuperClassEquality();
        }
        MethodList<?> hashCode = typeDefinition.getDeclaredMethods().filter(isHashCode());
        if (!hashCode.isEmpty()) {
            return hashCode.getOnly().isAbstract()
                    ? EqualsMethod.isolated()
                    : EqualsMethod.requiringSuperClassEquality();
        }
        typeDefinition = typeDefinition.getSuperClass().asErasure();
    }
    return EqualsMethod.isolated();
}
 
Example 4
Source Project: byte-buddy   File: ArrayFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a suitable array creator for the given component type.
 *
 * @param componentType The component type of the array to be created.
 * @return A suitable array creator.
 */
private static ArrayCreator makeArrayCreatorFor(TypeDefinition componentType) {
    if (!componentType.isPrimitive()) {
        return new ArrayCreator.ForReferenceType(componentType.asErasure());
    } else if (componentType.represents(boolean.class)) {
        return ArrayCreator.ForPrimitiveType.BOOLEAN;
    } else if (componentType.represents(byte.class)) {
        return ArrayCreator.ForPrimitiveType.BYTE;
    } else if (componentType.represents(short.class)) {
        return ArrayCreator.ForPrimitiveType.SHORT;
    } else if (componentType.represents(char.class)) {
        return ArrayCreator.ForPrimitiveType.CHARACTER;
    } else if (componentType.represents(int.class)) {
        return ArrayCreator.ForPrimitiveType.INTEGER;
    } else if (componentType.represents(long.class)) {
        return ArrayCreator.ForPrimitiveType.LONG;
    } else if (componentType.represents(float.class)) {
        return ArrayCreator.ForPrimitiveType.FLOAT;
    } else if (componentType.represents(double.class)) {
        return ArrayCreator.ForPrimitiveType.DOUBLE;
    } else {
        throw new IllegalArgumentException("Cannot create array of type " + componentType);
    }
}
 
Example 5
Source Project: byte-buddy   File: HashCodeMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolves a type definition to a hash code.
 *
 * @param typeDefinition The type definition to resolve.
 * @return The stack manipulation to apply.
 */
public static StackManipulation of(TypeDefinition typeDefinition) {
    if (typeDefinition.represents(boolean.class)
            || typeDefinition.represents(byte.class)
            || typeDefinition.represents(short.class)
            || typeDefinition.represents(char.class)
            || typeDefinition.represents(int.class)) {
        return Trivial.INSTANCE;
    } else if (typeDefinition.represents(long.class)) {
        return LONG;
    } else if (typeDefinition.represents(float.class)) {
        return FLOAT;
    } else if (typeDefinition.represents(double.class)) {
        return DOUBLE;
    } else if (typeDefinition.represents(boolean[].class)) {
        return BOOLEAN_ARRAY;
    } else if (typeDefinition.represents(byte[].class)) {
        return BYTE_ARRAY;
    } else if (typeDefinition.represents(short[].class)) {
        return SHORT_ARRAY;
    } else if (typeDefinition.represents(char[].class)) {
        return CHARACTER_ARRAY;
    } else if (typeDefinition.represents(int[].class)) {
        return INTEGER_ARRAY;
    } else if (typeDefinition.represents(long[].class)) {
        return LONG_ARRAY;
    } else if (typeDefinition.represents(float[].class)) {
        return FLOAT_ARRAY;
    } else if (typeDefinition.represents(double[].class)) {
        return DOUBLE_ARRAY;
    } else if (typeDefinition.isArray()) {
        return typeDefinition.getComponentType().isArray()
                ? NESTED_ARRAY
                : REFERENCE_ARRAY;
    } else {
        return MethodInvocation.invoke(HASH_CODE).virtual(typeDefinition.asErasure());
    }
}
 
Example 6
Source Project: byte-buddy   File: EqualsMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolves a type definition to a equality comparison.
 *
 * @param typeDefinition The type definition to resolve.
 * @return The stack manipulation to apply.
 */
public static StackManipulation of(TypeDefinition typeDefinition) {
    if (typeDefinition.represents(boolean.class)
            || typeDefinition.represents(byte.class)
            || typeDefinition.represents(short.class)
            || typeDefinition.represents(char.class)
            || typeDefinition.represents(int.class)) {
        return ConditionalReturn.onNonEqualInteger();
    } else if (typeDefinition.represents(long.class)) {
        return new Compound(LONG, ConditionalReturn.onNonZeroInteger());
    } else if (typeDefinition.represents(float.class)) {
        return new Compound(FLOAT, ConditionalReturn.onNonZeroInteger());
    } else if (typeDefinition.represents(double.class)) {
        return new Compound(DOUBLE, ConditionalReturn.onNonZeroInteger());
    } else if (typeDefinition.represents(boolean[].class)) {
        return new Compound(BOOLEAN_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(byte[].class)) {
        return new Compound(BYTE_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(short[].class)) {
        return new Compound(SHORT_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(char[].class)) {
        return new Compound(CHARACTER_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(int[].class)) {
        return new Compound(INTEGER_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(long[].class)) {
        return new Compound(LONG_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(float[].class)) {
        return new Compound(FLOAT_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.represents(double[].class)) {
        return new Compound(DOUBLE_ARRAY, ConditionalReturn.onZeroInteger());
    } else if (typeDefinition.isArray()) {
        return new Compound(typeDefinition.getComponentType().isArray()
                ? NESTED_ARRAY
                : REFERENCE_ARRAY, ConditionalReturn.onZeroInteger());
    } else {
        return new Compound(MethodInvocation.invoke(EQUALS).virtual(typeDefinition.asErasure()), ConditionalReturn.onZeroInteger());
    }
}
 
Example 7
Source Project: byte-buddy   File: EqualsMethod.java    License: Apache License 2.0 2 votes vote down vote up
@Override
protected boolean resolve(TypeDefinition typeDefinition) {
    return typeDefinition.represents(String.class);
}