/** * Resolves the given type description to the supplied target type if it represents the {@link TargetType} placeholder. * Array types are resolved to their component type and rebuilt as an array of the actual target type, if necessary. * * @param typeDescription The type description that might represent the {@link TargetType} placeholder. * @param targetType The actual target type. * @return A description of the resolved type. */ public static TypeDescription resolve(TypeDescription typeDescription, TypeDescription targetType) { int arity = 0; TypeDescription componentType = typeDescription; while (componentType.isArray()) { componentType = componentType.getComponentType(); arity++; } return componentType.represents(TargetType.class) ? TypeDescription.ArrayProjection.of(targetType, arity) : typeDescription; }
/** * {@inheritDoc} */ public InstrumentedType prepare(InstrumentedType instrumentedType) { for (String value : values) { instrumentedType = instrumentedType.withField(new FieldDescription.Token(value, ENUM_FIELD_MODIFIERS | Opcodes.ACC_ENUM, TargetType.DESCRIPTION.asGenericType())); } return instrumentedType .withField(new FieldDescription.Token(ENUM_VALUES, ENUM_FIELD_MODIFIERS | Opcodes.ACC_SYNTHETIC, TypeDescription.ArrayProjection.of(TargetType.DESCRIPTION).asGenericType())) .withInitializer(new InitializationAppender(values)); }
/** * {@inheritDoc} */ public TypeDescription asErasure() { return ArrayProjection.of(getComponentType().asErasure(), 1); }
/** * {@inheritDoc} */ public TypeDescription resolve() { return TypeDescription.ArrayProjection.of(resolution.resolve(), arity); } }
/** * Creates an array projection of an arity of one. * * @param componentType The component type of the array. * @return A projection of the component type as an array of the given value with an arity of one. */ public static TypeDescription of(TypeDescription componentType) { return of(componentType, 1); }