Top Fields Constructors Methods
io.vertx.codegen

public Class Helper

extends Object
Class Inheritance
Imports
io.vertx.codegen.annotations.GenIgnore, io.vertx.codegen.type.ClassKind, javax.annotation.processing.ProcessingEnvironment, javax.lang.model.element.*, javax.lang.model.type.*, javax.lang.model.util.Elements, .Types, java.io.File, java.lang.annotation.Annotation, java.lang.reflect.GenericDeclaration, .Method, .ParameterizedType, .Type, java.util.*, java.util.function.Function, .Predicate, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, .Stream

Author
Tim Fox

Field Summary

Modifier and TypeField and Description
pack-priv static final Function<Element, Stream<ExecutableElement>>
private static final Set<String>
public static final Function<Element, Stream<VariableElement>>
public static final Function<Element, Stream<ExecutableElement>>
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static <T> Function<Object, Stream<T>>
cast(Class<T> type)

pack-priv static void
checkUnderModule(Model model, String annotation)

public static String
public static String
pack-priv static void
public static ClassKind
public static ClassKind
getAnnotatedDataObjectDeserialisationType(Elements elementUtils, Types typeUtils, TypeElement dataObjectElt)

public static TypeElement

Returns:

the element type or null if none exists
getElementTypeOf
(Element
the element
elt
)

Return the element type of the specified element.

public static String
getJavadocTag(String comment, String tagName)

public static String
public static String
public static Method
getReflectMethod(ProcessingEnvironment env, ExecutableElement modelMethod)

Like getReflectMethod(ClassLoader, ExecutableElement) but using the processing environment context.

public static Method

Returns:

the method or null if not found
getReflectMethod
(ClassLoader loader, ExecutableElement
the model method element
modelMethod
)

Returns a Method corresponding to the methodElt parameter.

public static String
public static String
indentString(String str, String indent)

pack-priv static <T> Function<Object, Stream<T>>
instanceOf(Class<T> type)

public static boolean
public static boolean
private static AnnotationMirror
isFluent(DeclaredType annotationType, Elements elementUtils, Types typeUtils, TypeElement declaring, ExecutableElement method, TypeMirror type)

public static boolean

Returns:

Return true if the elt is annotated with @GenIgnore.
isGenIgnore
(Element
the element to check
elt
)

private static boolean
matchesConstructor(Element elt, String memberName, Predicate<ExecutableElement> parametersMatcher)

private static boolean
matchesField(Element elt, String memberName)

private static boolean
matchesMethod(Element elt, String memberName, Predicate<ExecutableElement> parametersMatcher)

public static String

Returns:

the normalized property name
normalizePropertyName
(String
the property name
propertyName
)

Normalize a property name:

  • the first char will always be a lower case
  • if the first char is an upper case, any following upper case char will be lower cased unless it is followed by a lower case char
public static String

Returns:

the normalized string
normalizeWhitespaces
(String
the string to normalize
s
)

Trim and normalize the whitespaces in a string: any cluster of more than one whitespace char is replaced by a space char, then the string is trimmed.

private static Predicate<ExecutableElement>

Returns:

the matcher
parametersMatcher
(Types typeUtils, String[]
the parameter type names
parameterSignature
)

Return a matcher for parameters, given the parameter type signature of an executable element.

public static String
removeTags(String comment)

public static Set<DeclaredType>

Returns:

the set of ancestors
resolveAncestorTypes
(TypeElement
the type element to resolve
typeElt
,
boolean withSuper, boolean withInterfaces)

Resolve the set of all the ancestors declared types of a given type element.

private static void
resolveAncestorTypes(TypeElement typeElt, Set<DeclaredType> ancestors, boolean withSuper, boolean withInterfaces)

public static AnnotationMirror

Returns:

the annotation if resolved otherwise null
resolveMethodAnnotation
(Class<? extends Annotation>
the annotation type,
annotationType
,
Elements
element utils
elementUtils
,
Types
type utils
typeUtils
,
TypeElement
the element declaring the method
declaring
,
ExecutableElement
the method to start the resolution from
method
)

Resolve a method annotation, this method scan the specified method, if the annotation is not found it will also scan the methods this method overrides and return the annotation when it is found.

public static AnnotationMirror

Returns:

the annotation if resolved otherwise null
resolveMethodAnnotation
(DeclaredType
the annotation type,
annotationType
,
Elements
element utils
elementUtils
,
Types
type utils
typeUtils
,
TypeElement
the element declaring the method
declaring
,
ExecutableElement
the method to start the resolution from
method
)

Resolve a method annotation, this method scan the specified method, if the annotation is not found it will also scan the methods this method overrides and return the annotation when it is found.

public static Element

Returns:

the resolved element
resolveSignature
(Elements
the element utils
elementUtils
,
Types
the type utils
typeUtils
,
TypeElement
the declaring element, may be null
declaringElt
,
String
the signature to resolve
signature
)

Resolves a documentation signature, null can be returned if no element can be resolved.

private static TypeElement
resolveTypeElement(Elements elementUtils, TypeElement declaringElt, String typeName)

public static TypeMirror

Returns:

the type parameterizing the type parameter
resolveTypeParameter
(Types
the type utils
typeUtils
,
DeclaredType
the sub type for which the type parameter is parameterized
subType
,
TypeParameterElement
the type parameter to resolve
typeParam
)

Return the type of a type parameter element of a given type element when that type parameter element is parameterized by a sub type, directly or indirectly.

public static <T> Type

Returns:

the type parameterizing the type parameter
resolveTypeParameter
(Type
the sub type for which the type parameter is parameterized
type
,
TypeVariable<Class<T>>
the type parameter to resolve
typeParam
)

Return the type of a type parameter element of a given type element when that type parameter element is parameterized by a sub type, directly or indirectly.

pack-priv static String

Returns:

the string representation
toString
(TypeMirror
the type mirror
mirror
)

Compute the string representation of a type mirror.

pack-priv static void
toString(TypeMirror
the type mirror
mirror
,
StringBuilder
the buffer appended with the string representation
buffer
)

Compute the string representation of a type mirror.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CASTback to summary
pack-priv static final Function<Element, Stream<ExecutableElement>> CAST
dataObjectTypesback to summary
private static final Set<String> dataObjectTypes
FILTER_FIELDback to summary
public static final Function<Element, Stream<VariableElement>> FILTER_FIELD
FILTER_METHODback to summary
public static final Function<Element, Stream<ExecutableElement>> FILTER_METHOD
SIGNATURE_PATTERNback to summary
private static final Pattern SIGNATURE_PATTERN
WHITESPACE_CLUSTER_PATTERNback to summary
private static final Pattern WHITESPACE_CLUSTER_PATTERN

Constructor Detail

Helperback to summary
public Helper()

Method Detail

castback to summary
pack-priv static <T> Function<Object, Stream<T>> cast(Class<T> type)
checkUnderModuleback to summary
pack-priv static void checkUnderModule(Model model, String annotation)
convertCamelCaseToUnderscoresback to summary
public static String convertCamelCaseToUnderscores(String str)
decapitaliseFirstLetterback to summary
public static String decapitaliseFirstLetter(String str)
ensureParentDirback to summary
pack-priv static void ensureParentDir(File f)
getAnnotatedDataObjectAnnotatedSerializationTypeback to summary
public static ClassKind getAnnotatedDataObjectAnnotatedSerializationType(Elements elementUtils, TypeElement dataObjectElt)
getAnnotatedDataObjectDeserialisationTypeback to summary
public static ClassKind getAnnotatedDataObjectDeserialisationType(Elements elementUtils, Types typeUtils, TypeElement dataObjectElt)
getElementTypeOfback to summary
public static TypeElement getElementTypeOf(Element elt)

Return the element type of the specified element.

Parameters
elt:Element

the element

Returns:TypeElement

the element type or null if none exists

getJavadocTagback to summary
public static String getJavadocTag(String comment, String tagName)
getNonGenericTypeback to summary
public static String getNonGenericType(String type)
getPackageNameback to summary
public static String getPackageName(String type)
getReflectMethodback to summary
public static Method getReflectMethod(ProcessingEnvironment env, ExecutableElement modelMethod)

Like getReflectMethod(ClassLoader, ExecutableElement) but using the processing environment context.

getReflectMethodback to summary
public static Method getReflectMethod(ClassLoader loader, ExecutableElement modelMethod)

Returns a Method corresponding to the methodElt parameter. Obviously this work only when the corresponding method is available on the classpath using java lang reflection.

Parameters
modelMethod:ExecutableElement

the model method element

Returns:Method

the method or null if not found

getSimpleNameback to summary
public static String getSimpleName(String type)
indentStringback to summary
public static String indentString(String str, String indent)
instanceOfback to summary
pack-priv static <T> Function<Object, Stream<T>> instanceOf(Class<T> type)
isAbstractClassOrInterfaceback to summary
public static boolean isAbstractClassOrInterface(TypeElement element)
isConcreteClassback to summary
public static boolean isConcreteClass(TypeElement element)
isFluentback to summary
private static AnnotationMirror isFluent(DeclaredType annotationType, Elements elementUtils, Types typeUtils, TypeElement declaring, ExecutableElement method, TypeMirror type)
isGenIgnoreback to summary
public static boolean isGenIgnore(Element elt)
Parameters
elt:Element

the element to check

Returns:boolean

Return true if the elt is annotated with @GenIgnore.

matchesConstructorback to summary
private static boolean matchesConstructor(Element elt, String memberName, Predicate<ExecutableElement> parametersMatcher)
matchesFieldback to summary
private static boolean matchesField(Element elt, String memberName)
matchesMethodback to summary
private static boolean matchesMethod(Element elt, String memberName, Predicate<ExecutableElement> parametersMatcher)
normalizePropertyNameback to summary
public static String normalizePropertyName(String propertyName)

Normalize a property name:

  • the first char will always be a lower case
  • if the first char is an upper case, any following upper case char will be lower cased unless it is followed by a lower case char
For instance:
  • foo -> foo
  • Foo -> foo
  • URL -> url
  • URLFactory -> urlFactory
Parameters
propertyName:String

the property name

Returns:String

the normalized property name

normalizeWhitespacesback to summary
public static String normalizeWhitespaces(String s)

Trim and normalize the whitespaces in a string: any cluster of more than one whitespace char is replaced by a space char, then the string is trimmed.

Parameters
s:String

the string to normalize

Returns:String

the normalized string

parametersMatcherback to summary
private static Predicate<ExecutableElement> parametersMatcher(Types typeUtils, String[] parameterSignature)

Return a matcher for parameters, given the parameter type signature of an executable element. The parameter signature is a list of parameter types formatted as a signature, i.e all types are raw, or primitive, or arrays. Unqualified types are resolved against the import of the specified compilationUnitTree argument.

Parameters
parameterSignature:String[]

the parameter type names

Returns:Predicate<ExecutableElement>

the matcher

removeTagsback to summary
public static String removeTags(String comment)
resolveAncestorTypesback to summary
public static Set<DeclaredType> resolveAncestorTypes(TypeElement typeElt, boolean withSuper, boolean withInterfaces)

Resolve the set of all the ancestors declared types of a given type element.

Parameters
typeElt:TypeElement

the type element to resolve

Returns:Set<DeclaredType>

the set of ancestors

resolveAncestorTypesback to summary
private static void resolveAncestorTypes(TypeElement typeElt, Set<DeclaredType> ancestors, boolean withSuper, boolean withInterfaces)
resolveMethodAnnotationback to summary
public static AnnotationMirror resolveMethodAnnotation(Class<? extends Annotation> annotationType, Elements elementUtils, Types typeUtils, TypeElement declaring, ExecutableElement method)

Resolve a method annotation, this method scan the specified method, if the annotation is not found it will also scan the methods this method overrides and return the annotation when it is found.

Parameters
annotationType:Class<? extends Annotation>

the annotation type,

elementUtils:Elements

element utils

typeUtils:Types

type utils

declaring:TypeElement

the element declaring the method

method:ExecutableElement

the method to start the resolution from

Returns:AnnotationMirror

the annotation if resolved otherwise null

resolveMethodAnnotationback to summary
public static AnnotationMirror resolveMethodAnnotation(DeclaredType annotationType, Elements elementUtils, Types typeUtils, TypeElement declaring, ExecutableElement method)

Resolve a method annotation, this method scan the specified method, if the annotation is not found it will also scan the methods this method overrides and return the annotation when it is found.

Parameters
annotationType:DeclaredType

the annotation type,

elementUtils:Elements

element utils

typeUtils:Types

type utils

declaring:TypeElement

the element declaring the method

method:ExecutableElement

the method to start the resolution from

Returns:AnnotationMirror

the annotation if resolved otherwise null

resolveSignatureback to summary
public static Element resolveSignature(Elements elementUtils, Types typeUtils, TypeElement declaringElt, String signature)

Resolves a documentation signature, null can be returned if no element can be resolved.

Parameters
elementUtils:Elements

the element utils

typeUtils:Types

the type utils

declaringElt:TypeElement

the declaring element, may be null

signature:String

the signature to resolve

Returns:Element

the resolved element

resolveTypeElementback to summary
private static TypeElement resolveTypeElement(Elements elementUtils, TypeElement declaringElt, String typeName)
resolveTypeParameterback to summary
public static TypeMirror resolveTypeParameter(Types typeUtils, DeclaredType subType, TypeParameterElement typeParam)

Return the type of a type parameter element of a given type element when that type parameter element is parameterized by a sub type, directly or indirectly. When the type parameter cannot be resolved, null is returned.

Parameters
typeUtils:Types

the type utils

subType:DeclaredType

the sub type for which the type parameter is parameterized

typeParam:TypeParameterElement

the type parameter to resolve

Returns:TypeMirror

the type parameterizing the type parameter

resolveTypeParameterback to summary
public static <T> Type resolveTypeParameter(Type type, TypeVariable<Class<T>> typeParam)

Return the type of a type parameter element of a given type element when that type parameter element is parameterized by a sub type, directly or indirectly. When the type parameter cannot be resolve, null is returned.

Parameters
type:Type

the sub type for which the type parameter is parameterized

typeParam:TypeVariable<Class<T>>

the type parameter to resolve

Returns:Type

the type parameterizing the type parameter

toStringback to summary
pack-priv static String toString(TypeMirror mirror)

Compute the string representation of a type mirror.

Parameters
mirror:TypeMirror

the type mirror

Returns:String

the string representation

toStringback to summary
pack-priv static void toString(TypeMirror mirror, StringBuilder buffer)

Compute the string representation of a type mirror.

Parameters
mirror:TypeMirror

the type mirror

buffer:StringBuilder

the buffer appended with the string representation