/** * Finalizes the build and finalizes the created type as a generic type description. * * @param annotation Type annotations place for the built generic type to declare. * @return A generic type description of the built type. */ public Generic build(Annotation... annotation) { return build(Arrays.asList(annotation)); }
/** * Creates a parameterized type without an owner type or with a non-generic owner type. * * @param rawType A raw version of the type to describe as a parameterized type. * @param parameter The type arguments to attach to the raw type as parameters. * @return A builder for creating a parameterized type. */ public static Builder parameterizedType(Class<?> rawType, java.lang.reflect.Type... parameter) { return parameterizedType(rawType, Arrays.asList(parameter)); }
/** * Defines type annotations to be declared by the current type. * * @param annotation Type annotations to be declared by the current type. * @return A new builder where the current type declares the supplied type annotations. */ public Builder annotate(AnnotationDescription... annotation) { return annotate(Arrays.asList(annotation)); }
private static <InT, OutT> DynamicType.Unloaded<?> createDynamicTypeFromSpec(StreamingLedgerSpec<InT, OutT> spec) throws NoSuchMethodException { PackageLocalNamingStrategy generatedTypeName = new PackageLocalNamingStrategy(spec.processFunction.getClass()); TypeDefinition generatedType = Generic.Builder.parameterizedType( ProcessFunctionInvoker.class, spec.inputType.getTypeClass(), spec.resultType.getTypeClass() ).build(); TypeDefinition processFunctionType = new TypeDescription.ForLoadedType(spec.processFunction.getClass()); ForLoadedConstructor superTypeConstructor = new ForLoadedConstructor(ProcessFunctionInvoker.class.getDeclaredConstructor()); MethodDescription processMethodType = processMethodTypeFromSpec(spec); Builder<?> builder = configureByteBuddyBuilder( generatedTypeName, generatedType, processFunctionType, superTypeConstructor, processMethodType, spec.stateBindings.size()); return builder.make(); }
static TypeDefinition createTypeDefinitionFromJavaType(JavaType javaType) { if (!javaType.hasGenericTypes()) { //simply use the raw class to construct the corresponding TypeDefinition return new TypeDescription.ForLoadedType(javaType.getRawClass()); } //create the appropriate Generic TypeDescription using containedType values final List<Type> genericParameters = new ArrayList<Type>(); for(int i=0; i<javaType.containedTypeCount(); i++) { genericParameters.add(javaType.containedType(i).getRawClass()); } return Generic.Builder.parameterizedType(javaType.getRawClass(), genericParameters).build(); } }
throw new IllegalArgumentException("Require at least one enumeration constant"); TypeDescription.Generic enumType = TypeDescription.Generic.Builder.parameterizedType(Enum.class, TargetType.class).build(); return new SubclassDynamicTypeBuilder<Enum<?>>(instrumentedTypeFactory.subclass(namingStrategy.subclass(enumType), ModifierContributor.Resolver.of(Visibility.PUBLIC, TypeManifestation.FINAL, EnumerationState.ENUMERATION).resolve(),
/** * Represents the built type into an array. * * @param arity The arity of the array. * @return A builder for creating an array of the currently built type. */ public Builder asArray(int arity) { if (arity < 1) { throw new IllegalArgumentException("Cannot define an array of a non-positive arity: " + arity); } TypeDescription.Generic typeDescription = build(); while (--arity > 0) { typeDescription = new OfGenericArray.Latent(typeDescription, Empty.INSTANCE); } return new Builder.OfGenericArrayType(typeDescription); }
/** * Creates a parameterized type. * * @param rawType A raw version of the type to describe as a parameterized type. * @param ownerType The owner type of the parameterized type. * @param parameters The type arguments to attach to the raw type as parameters. * @return A builder for creating a parameterized type. */ public static Builder parameterizedType(Class<?> rawType, java.lang.reflect.Type ownerType, List<? extends java.lang.reflect.Type> parameters) { return parameterizedType(ForLoadedType.of(rawType), ownerType == null ? null : Sort.describe(ownerType), new TypeList.Generic.ForLoadedTypes(parameters)); }
/** * Finalizes the build and finalizes the created type as a generic type description. * * @param annotations Type annotations place for the built generic type to declare. * @return A generic type description of the built type. */ public Generic build(List<? extends Annotation> annotations) { return build(new AnnotationList.ForLoadedAnnotations(annotations)); }
/** * Finalizes the build and finalizes the created type as a generic type description. * * @return A generic type description of the built type. */ public Generic build() { return doBuild(); }
/** * Transforms this type into the upper bound of a wildcard type. * * @return A generic type description of a wildcard type with this builder's type as an upper bound. */ public Generic asWildcardUpperBound() { return asWildcardUpperBound(Collections.<AnnotationDescription>emptySet()); }
/** * Creates a raw type of a type description where the supplied owner type is used as . * * @param type The type to represent as a raw type. * @param ownerType The raw type's (annotated) declaring type or {@code null} if no owner type should be declared. * @return A builder for creating a raw type. */ public static Builder rawType(Class<?> type, Generic ownerType) { return rawType(ForLoadedType.of(type), ownerType); }
/** * Transforms this type into the lower bound of a wildcard type. * * @param annotation Type annotations to be declared by the wildcard type. * @return A generic type description of a wildcard type with this builder's type as an lower bound. */ public Generic asWildcardLowerBound(AnnotationDescription... annotation) { return asWildcardLowerBound(Arrays.asList(annotation)); }
/** * Transforms this type into the lower bound of a wildcard type. * * @param annotation Type annotations to be declared by the wildcard type. * @return A generic type description of a wildcard type with this builder's type as an lower bound. */ public Generic asWildcardLowerBound(Annotation... annotation) { return asWildcardLowerBound(Arrays.asList(annotation)); }
/** * Defines type annotations to be declared by the current type. * * @param annotations Type annotations to be declared by the current type. * @return A new builder where the current type declares the supplied type annotations. */ public Builder annotate(Collection<? extends AnnotationDescription> annotations) { return doAnnotate(new ArrayList<AnnotationDescription>(annotations)); }
/** * Defines type annotations to be declared by the current type. * * @param annotation Type annotations to be declared by the current type. * @return A new builder where the current type declares the supplied type annotations. */ public Builder annotate(Annotation... annotation) { return annotate(Arrays.asList(annotation)); }
/** * Represents the built type into an array. * * @return A builder for creating an array of the currently built type. */ public Builder asArray() { return asArray(1); }
/** * Creates a parameterized type without an owner type or with a non-generic owner type. * * @param rawType A raw version of the type to describe as a parameterized type. * @param parameters The type arguments to attach to the raw type as parameters. * @return A builder for creating a parameterized type. */ public static Builder parameterizedType(TypeDescription rawType, Collection<? extends TypeDefinition> parameters) { return parameterizedType(rawType, Generic.UNDEFINED, parameters); }
/** * Finalizes the build and finalizes the created type as a generic type description. * * @param annotation Type annotations place for the built generic type to declare. * @return A generic type description of the built type. */ public Generic build(AnnotationDescription... annotation) { return build(Arrays.asList(annotation)); }
/** * Transforms this type into the lower bound of a wildcard type. * * @param annotations Type annotations to be declared by the wildcard type. * @return A generic type description of a wildcard type with this builder's type as an lower bound. */ public Generic asWildcardLowerBound(Collection<? extends AnnotationDescription> annotations) { return OfWildcardType.Latent.boundedBelow(build(), new Explicit(new ArrayList<AnnotationDescription>(annotations))); }