Package com.tonic.builder
Class AnnotationBuilder<P>
- java.lang.Object
-
- com.tonic.builder.AnnotationBuilder<P>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AnnotationBuilder<P>annotationArray(String name, AnnotationBuilder<?>... annotations)Adds a nested-annotation-array element.AnnotationBuilder<P>annotationValue(String name, AnnotationBuilder<?> annotation)Adds a nested-annotation element.voidattachTo(ClassFile classFile, ConstPool pool)Attaches this annotation to a class.voidattachTo(MemberEntry member, ConstPool pool)Attaches this annotation to a field or method, appending to the existingRuntime[In]VisibleAnnotationsattribute of matching visibility when present, or creating one otherwise.AnnotationBuilder<P>booleanArray(String name, boolean... values)Adds a boolean-array element.Annotationbuild(ConstPool pool)Materializes this specification into anAnnotation, interning entries as needed.AnnotationBuilder<P>byteArray(String name, byte... values)Adds a byte-array element.AnnotationBuilder<P>byteValue(String name, byte v)Adds a byte element.AnnotationBuilder<P>charArray(String name, char... values)Adds a char-array element.AnnotationBuilder<P>charValue(String name, char v)Adds a char element.AnnotationBuilder<P>classArray(String name, String... types)Adds a class-literal-array element.AnnotationBuilder<P>classValue(String name, String type)Adds a class-literal element.AnnotationBuilder<P>doubleArray(String name, double... values)Adds a double-array element.Pend()AnnotationBuilder<P>enumArray(String name, String enumType, String... constants)Adds an enum-constant-array element with all constants from one enum type.AnnotationBuilder<P>enumValue(String name, String enumType, String constant)Adds an enum-constant element.AnnotationBuilder<P>floatArray(String name, float... values)Adds a float-array element.AnnotationBuilder<P>intArray(String name, int... values)Adds an int-array element.booleanisVisible()AnnotationBuilder<P>longArray(String name, long... values)Adds a long-array element.static AnnotationBuilder<Void>of(String type)Starts a standalone annotation of the given type.AnnotationBuilder<P>shortArray(String name, short... values)Adds a short-array element.AnnotationBuilder<P>shortValue(String name, short v)Adds a short element.AnnotationBuilder<P>stringArray(String name, String... values)Adds a String-array element.AnnotationBuilder<P>stringValue(String name, String v)Adds a String element.AnnotationBuilder<P>value(String name, boolean v)Adds a boolean element.AnnotationBuilder<P>value(String name, double v)Adds a double element.AnnotationBuilder<P>value(String name, float v)Adds a float element.AnnotationBuilder<P>value(String name, int v)Adds an int element.AnnotationBuilder<P>value(String name, long v)Adds a long element.AnnotationBuilder<P>visible(boolean visible)Marks this annotation runtime-visible (default) or invisible.
-
-
-
Method Detail
-
of
public static AnnotationBuilder<Void> of(String type)
Starts a standalone annotation of the given type.- Parameters:
type- the annotation type as an internal name (com/example/Foo), dotted name, or field descriptor (Lcom/example/Foo;)- Returns:
- a new standalone builder
-
visible
public AnnotationBuilder<P> visible(boolean visible)
Marks this annotation runtime-visible (default) or invisible.- Parameters:
visible- true for RuntimeVisibleAnnotations, false for RuntimeInvisibleAnnotations- Returns:
- this builder
-
isVisible
public boolean isVisible()
- Returns:
- whether visible
-
end
public P end()
- Returns:
- the parent builder this annotation was opened from, or null when standalone
-
value
public AnnotationBuilder<P> value(String name, int v)
Adds an int element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
value
public AnnotationBuilder<P> value(String name, boolean v)
Adds a boolean element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
value
public AnnotationBuilder<P> value(String name, long v)
Adds a long element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
value
public AnnotationBuilder<P> value(String name, float v)
Adds a float element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
value
public AnnotationBuilder<P> value(String name, double v)
Adds a double element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
byteValue
public AnnotationBuilder<P> byteValue(String name, byte v)
Adds a byte element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
charValue
public AnnotationBuilder<P> charValue(String name, char v)
Adds a char element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
shortValue
public AnnotationBuilder<P> shortValue(String name, short v)
Adds a short element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
stringValue
public AnnotationBuilder<P> stringValue(String name, String v)
Adds a String element.- Parameters:
name- the element namev- the value- Returns:
- this builder
-
classValue
public AnnotationBuilder<P> classValue(String name, String type)
Adds a class-literal element.- Parameters:
name- the element nametype- a class name (internal or dotted) or a raw type descriptor- Returns:
- this builder
-
enumValue
public AnnotationBuilder<P> enumValue(String name, String enumType, String constant)
Adds an enum-constant element.- Parameters:
name- the element nameenumType- the enum type (internal or dotted name, or field descriptor)constant- the enum constant's name- Returns:
- this builder
-
annotationValue
public AnnotationBuilder<P> annotationValue(String name, AnnotationBuilder<?> annotation)
Adds a nested-annotation element.- Parameters:
name- the element nameannotation- the nested annotation's builder, materialized when this one builds- Returns:
- this builder
-
intArray
public AnnotationBuilder<P> intArray(String name, int... values)
Adds an int-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
booleanArray
public AnnotationBuilder<P> booleanArray(String name, boolean... values)
Adds a boolean-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
byteArray
public AnnotationBuilder<P> byteArray(String name, byte... values)
Adds a byte-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
charArray
public AnnotationBuilder<P> charArray(String name, char... values)
Adds a char-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
shortArray
public AnnotationBuilder<P> shortArray(String name, short... values)
Adds a short-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
longArray
public AnnotationBuilder<P> longArray(String name, long... values)
Adds a long-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
floatArray
public AnnotationBuilder<P> floatArray(String name, float... values)
Adds a float-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
doubleArray
public AnnotationBuilder<P> doubleArray(String name, double... values)
Adds a double-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
stringArray
public AnnotationBuilder<P> stringArray(String name, String... values)
Adds a String-array element.- Parameters:
name- the element namevalues- the array values- Returns:
- this builder
-
classArray
public AnnotationBuilder<P> classArray(String name, String... types)
Adds a class-literal-array element.- Parameters:
name- the element nametypes- class names (internal or dotted) or raw type descriptors- Returns:
- this builder
-
enumArray
public AnnotationBuilder<P> enumArray(String name, String enumType, String... constants)
Adds an enum-constant-array element with all constants from one enum type.- Parameters:
name- the element nameenumType- the enum type (internal or dotted name, or field descriptor)constants- the enum constants' names- Returns:
- this builder
-
annotationArray
public AnnotationBuilder<P> annotationArray(String name, AnnotationBuilder<?>... annotations)
Adds a nested-annotation-array element.- Parameters:
name- the element nameannotations- the nested annotations' builders, materialized when this one builds- Returns:
- this builder
-
build
public Annotation build(ConstPool pool)
Materializes this specification into anAnnotation, interning entries as needed.- Parameters:
pool- the constant pool to intern type, name, and value entries into- Returns:
- the materialized annotation
-
attachTo
public void attachTo(MemberEntry member, ConstPool pool)
Attaches this annotation to a field or method, appending to the existingRuntime[In]VisibleAnnotationsattribute of matching visibility when present, or creating one otherwise.- Parameters:
member- the field or method to annotatepool- the constant pool to intern entries into
-
-