Top Description Inners Fields Constructors Methods
org.freedesktop.dbus.utils.generator

public Class ClassBuilderInfo

extends Object
Class Inheritance
Imports
org.freedesktop.dbus.annotations.DBusInterfaceName, org.freedesktop.dbus.utils.Util, org.freedesktop.dbus.utils.bin.IdentifierMangler, java.io.File, java.lang.annotation.Annotation, java.util.*, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors

Helper to create Java class/interface files with proper formatting.
Author
hypfvieh
Since
v3.0.1 - 2018-12-22

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ClassBuilderInfo.AnnotationInfo

Contains information about annotation to place on classes, members or methods.

public static class
ClassBuilderInfo.ClassConstructor

Pojo which represents a class constructor.

public static class
ClassBuilderInfo.ClassMethod

Pojo which represents a class method.

public static enum
ClassBuilderInfo.ClassType

Enum to define either the ClassBuilderInfo is for a CLASS or an INTERFACE.

public static class
ClassBuilderInfo.MemberOrArgument

Pojo which represents a class member/field or argument.

Field Summary

Modifier and TypeField and Description
private final List<ClassBuilderInfo.AnnotationInfo>
annotations

Annotations of this class.

private final String
argumentPrefix

Prefix to prepend to method/constructor arguments.

private String
className

Name of this class.

private ClassBuilderInfo.ClassType
classType

Type of this class (interface or class).

private final List<ClassBuilderInfo.ClassConstructor>
constructors

Constructors for this class.

private String
dbusPackageName

Package name used by DBus.

private static final String
private String
extendClass

Class which this class may extend.

private final Set<String>
implementedInterfaces

Interfaces implemented by this class.

private final Set<String>
imports

Imported files for this class.

private final List<ClassBuilderInfo>
innerClasses

Inner classes inside of this class.

private final List<ClassBuilderInfo.MemberOrArgument>
members

Members/Fields of this class.

private final List<ClassBuilderInfo.ClassMethod>
methods

Methods provided by this class.

private String
packageName

Package of this class.

Constructor Summary

AccessConstructor and Description
public
ClassBuilderInfo()

Create new instance without argument prefix.

public
ClassBuilderInfo(String
prepend given prefix to all method/constructor arguments
_argumentPrefix
)

Create new instance.

Method Summary

Modifier and TypeMethod and Description
private static void
public String

Returns:

String
createClassFileContent
()

Create the Java source for the class information provided.

private List<String>
createClassFileContent(boolean
this is static inner class
_staticClass
,
Set<String>
this class needs additional imports (e.g. due to inner class)
_otherImports
)

Create the Java source for the class information provided.

public List<ClassBuilderInfo.AnnotationInfo>
public String
pack-priv static String

Returns:

classname, null if input was null
getClassName
(String
fqcn to analyze
_fqcn
)

Extract the class name from a given FQCN (fully qualified classname).

public ClassBuilderInfo.ClassType
public List<ClassBuilderInfo.ClassConstructor>
public String
public String
public String

Returns:

String, null if class name was null
getFileName
()

Create the filename with path this java class should use.

public String

Returns:

String
getFqcn
()

Creates the fully qualified classname based on the provided classname and package.

public Set<String>
public Set<String>
pack-priv static Set<String>

Returns:

set of classes required for imports
getImportsForType
(String
type described in the string format
_type
)

Get all classes that should be imported for the input type, this method works fine with generic types.

public List<ClassBuilderInfo>
public List<ClassBuilderInfo.MemberOrArgument>
public List<ClassBuilderInfo.ClassMethod>
public String
pack-priv static String

Returns:

type with simplified class names
getSimpleTypeClasses
(String
type described in the string format
_type
)

Simplify class names in the type.

private static String
maybePrefix(String _arg, String _prefix)

public void
setClassName(String _className)

public void
public void
setDbusPackageName(String _dbusPackageName)

public void
setExtendClass(String _extendClass)

public void
setPackageName(String _packageName)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

annotationsback to summary
private final List<ClassBuilderInfo.AnnotationInfo> annotations

Annotations of this class.

argumentPrefixback to summary
private final String argumentPrefix

Prefix to prepend to method/constructor arguments.

classNameback to summary
private String className

Name of this class.

classTypeback to summary
private ClassBuilderInfo.ClassType classType

Type of this class (interface or class).

constructorsback to summary
private final List<ClassBuilderInfo.ClassConstructor> constructors

Constructors for this class.

dbusPackageNameback to summary
private String dbusPackageName

Package name used by DBus.

DEFAULT_INDENTback to summary
private static final String DEFAULT_INDENT
extendClassback to summary
private String extendClass

Class which this class may extend.

implementedInterfacesback to summary
private final Set<String> implementedInterfaces

Interfaces implemented by this class.

importsback to summary
private final Set<String> imports

Imported files for this class.

innerClassesback to summary
private final List<ClassBuilderInfo> innerClasses

Inner classes inside of this class.

membersback to summary
private final List<ClassBuilderInfo.MemberOrArgument> members

Members/Fields of this class.

methodsback to summary
private final List<ClassBuilderInfo.ClassMethod> methods

Methods provided by this class.

packageNameback to summary
private String packageName

Package of this class.

Constructor Detail

ClassBuilderInfoback to summary
public ClassBuilderInfo()

Create new instance without argument prefix.

ClassBuilderInfoback to summary
public ClassBuilderInfo(String _argumentPrefix)

Create new instance.

Parameters
_argumentPrefix:String

prepend given prefix to all method/constructor arguments

Method Detail

addEmptyLineIfNeededback to summary
private static void addEmptyLineIfNeeded(List<String> _content)
createClassFileContentback to summary
public String createClassFileContent()

Create the Java source for the class information provided.

Returns:String

String

createClassFileContentback to summary
private List<String> createClassFileContent(boolean _staticClass, Set<String> _otherImports)

Create the Java source for the class information provided.

Parameters
_staticClass:boolean

this is static inner class

_otherImports:Set<String>

this class needs additional imports (e.g. due to inner class)

getAnnotationsback to summary
public List<ClassBuilderInfo.AnnotationInfo> getAnnotations()
getClassNameback to summary
public String getClassName()
getClassNameback to summary
pack-priv static String getClassName(String _fqcn)

Extract the class name from a given FQCN (fully qualified classname).

Parameters
_fqcn:String

fqcn to analyze

Returns:String

classname, null if input was null

getClassTypeback to summary
public ClassBuilderInfo.ClassType getClassType()
getConstructorsback to summary
public List<ClassBuilderInfo.ClassConstructor> getConstructors()
getDbusPackageNameback to summary
public String getDbusPackageName()
getExtendClassback to summary
public String getExtendClass()
getFileNameback to summary
public String getFileName()

Create the filename with path this java class should use.

Returns:String

String, null if class name was null

getFqcnback to summary
public String getFqcn()

Creates the fully qualified classname based on the provided classname and package.

Returns:String

String

getImplementedInterfacesback to summary
public Set<String> getImplementedInterfaces()
getImportsback to summary
public Set<String> getImports()
getImportsForTypeback to summary
pack-priv static Set<String> getImportsForType(String _type)

Get all classes that should be imported for the input type, this method works fine with generic types. Please go to unit tests for usage examples.

Parameters
_type:String

type described in the string format

Returns:Set<String>

set of classes required for imports

getInnerClassesback to summary
public List<ClassBuilderInfo> getInnerClasses()
getMembersback to summary
public List<ClassBuilderInfo.MemberOrArgument> getMembers()
getMethodsback to summary
public List<ClassBuilderInfo.ClassMethod> getMethods()
getPackageNameback to summary
public String getPackageName()
getSimpleTypeClassesback to summary
pack-priv static String getSimpleTypeClasses(String _type)

Simplify class names in the type. Please go to unit tests for usage examples.

Parameters
_type:String

type described in the string format

Returns:String

type with simplified class names

maybePrefixback to summary
private static String maybePrefix(String _arg, String _prefix)
setClassNameback to summary
public void setClassName(String _className)
setClassTypeback to summary
public void setClassType(ClassBuilderInfo.ClassType _classType)
setDbusPackageNameback to summary
public void setDbusPackageName(String _dbusPackageName)
setExtendClassback to summary
public void setExtendClass(String _extendClass)
setPackageNameback to summary
public void setPackageName(String _packageName)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.freedesktop.dbus.utils.generator back to summary

public Class ClassBuilderInfo.AnnotationInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.freedesktop.dbus.utils.generator.ClassBuilderInfo.AnnotationInfo

Contains information about annotation to place on classes, members or methods.
Author
hypfvieh
Since
v3.2.1 - 2019-11-13

Field Summary

Modifier and TypeField and Description
private final Class<? extends Annotation>
annotationClass

Annotation class.

private final String
annotationParams

Annotation params (e.g. value = "foo", key = "bar").

Constructor Summary

AccessConstructor and Description
public
AnnotationInfo(Class<? extends Annotation> _annotationClass, String _annotationParams)

Method Summary

Modifier and TypeMethod and Description
public Class<? extends Annotation>
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationClassback to summary
private final Class<? extends Annotation> annotationClass

Annotation class.

annotationParamsback to summary
private final String annotationParams

Annotation params (e.g. value = "foo", key = "bar").

Constructor Detail

AnnotationInfoback to summary
public AnnotationInfo(Class<? extends Annotation> _annotationClass, String _annotationParams)

Method Detail

getAnnotationClassback to summary
public Class<? extends Annotation> getAnnotationClass()
getAnnotationParamsback to summary
public String getAnnotationParams()
org.freedesktop.dbus.utils.generator back to summary

public Class ClassBuilderInfo.ClassConstructor

extends Object
Class Inheritance
  • java.lang.Object
  • org.freedesktop.dbus.utils.generator.ClassBuilderInfo.ClassConstructor

Pojo which represents a class constructor.
Author
hypfvieh
Since
v3.0.1 - 2018-12-20

Field Summary

Modifier and TypeField and Description
private final List<ClassBuilderInfo.MemberOrArgument>
arguments

Map of arguments for the constructor.

private static final String
private final List<ClassBuilderInfo.MemberOrArgument>
superArguments

Map of arguments for the super-constructor.

private final List<String>
throwArguments

List of throws arguments.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
argumentsAsString(Set<String> _allImports, String _prefix)

public List<String>
generatedCode(String _indent, String _className, String _argumentPrefix, Set<String> _allImports)

public List<ClassBuilderInfo.MemberOrArgument>
public List<ClassBuilderInfo.MemberOrArgument>
public List<String>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argumentsback to summary
private final List<ClassBuilderInfo.MemberOrArgument> arguments

Map of arguments for the constructor. Key is argument name, value is argument type.

CONSTRUCTOR_TEMPLback to summary
private static final String CONSTRUCTOR_TEMPL
superArgumentsback to summary
private final List<ClassBuilderInfo.MemberOrArgument> superArguments

Map of arguments for the super-constructor. Key is argument name, value is argument type.

throwArgumentsback to summary
private final List<String> throwArguments

List of throws arguments.

Constructor Detail

ClassConstructorback to summary
public ClassConstructor()

Method Detail

argumentsAsStringback to summary
public String argumentsAsString(Set<String> _allImports, String _prefix)
generatedCodeback to summary
public List<String> generatedCode(String _indent, String _className, String _argumentPrefix, Set<String> _allImports)
getArgumentsback to summary
public List<ClassBuilderInfo.MemberOrArgument> getArguments()
getSuperArgumentsback to summary
public List<ClassBuilderInfo.MemberOrArgument> getSuperArguments()
getThrowArgumentsback to summary
public List<String> getThrowArguments()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.freedesktop.dbus.utils.generator back to summary

public Class ClassBuilderInfo.ClassMethod

extends Object
Class Inheritance
  • java.lang.Object
  • org.freedesktop.dbus.utils.generator.ClassBuilderInfo.ClassMethod

Pojo which represents a class method.
Author
hypfvieh
Since
v3.0.1 - 2018-12-20

Field Summary

Modifier and TypeField and Description
private final List<String>
annotations

List of annotations for this method.

private final List<ClassBuilderInfo.MemberOrArgument>
arguments

Arguments for this method, key is argument name, value is argument type.

private final boolean
finalMethod

True if method should be final, false otherwise.

private static final String
private final String
name

Name of this method.

private final String
returnType

Return value of the method.

Constructor Summary

AccessConstructor and Description
public
ClassMethod(String _name, String _returnType, boolean _finalMethod)

Method Summary

Modifier and TypeMethod and Description
public List<String>
generateCode(boolean _isInterface, String _argumentPrefix, String _indent, Set<String> _allImports)

public List<String>
public List<ClassBuilderInfo.MemberOrArgument>
public String
public String
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationsback to summary
private final List<String> annotations

List of annotations for this method.

argumentsback to summary
private final List<ClassBuilderInfo.MemberOrArgument> arguments

Arguments for this method, key is argument name, value is argument type.

finalMethodback to summary
private final boolean finalMethod

True if method should be final, false otherwise.

METHOD_TEMPLback to summary
private static final String METHOD_TEMPL
nameback to summary
private final String name

Name of this method.

returnTypeback to summary
private final String returnType

Return value of the method.

Constructor Detail

ClassMethodback to summary
public ClassMethod(String _name, String _returnType, boolean _finalMethod)

Method Detail

generateCodeback to summary
public List<String> generateCode(boolean _isInterface, String _argumentPrefix, String _indent, Set<String> _allImports)
getAnnotationsback to summary
public List<String> getAnnotations()
getArgumentsback to summary
public List<ClassBuilderInfo.MemberOrArgument> getArguments()
getNameback to summary
public String getName()
getReturnTypeback to summary
public String getReturnType()
isFinalMethodback to summary
public boolean isFinalMethod()
org.freedesktop.dbus.utils.generator back to summary

public final Enum ClassBuilderInfo.ClassType

extends Enum<ClassBuilderInfo.ClassType>
Class Inheritance

Enum to define either the ClassBuilderInfo is for a CLASS or an INTERFACE.
Author
hypfvieh
Since
v3.0.1 - 2018-12-20

Field Summary

Modifier and TypeField and Description
public static final ClassBuilderInfo.ClassType
public static final ClassBuilderInfo.ClassType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ClassBuilderInfo.ClassType
public static ClassBuilderInfo.ClassType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLASSback to summary
public static final ClassBuilderInfo.ClassType CLASS
INTERFACEback to summary
public static final ClassBuilderInfo.ClassType INTERFACE

Constructor Detail

ClassTypeback to summary
private ClassType()

Method Detail

valueOfback to summary
public static ClassBuilderInfo.ClassType valueOf(String name)
valuesback to summary
public static ClassBuilderInfo.ClassType[] values()
org.freedesktop.dbus.utils.generator back to summary

public Class ClassBuilderInfo.MemberOrArgument

extends Object
Class Inheritance
  • java.lang.Object
  • org.freedesktop.dbus.utils.generator.ClassBuilderInfo.MemberOrArgument

Pojo which represents a class member/field or argument.
Author
hypfvieh
Since
v3.0.1 - 2018-12-20

Field Summary

Modifier and TypeField and Description
private final List<String>
annotations

List of annotations for this member.

private final boolean
finalArg

True to force this member to be final, false otherwise.

private final List<String>
generics

List of classes/types or placeholders put into diamond operators to use as generics.

private static final String
private final String
name

Name of member/field.

private static final String
private final String
type

Type of member/field (e.g. String, int...).

Constructor Summary

AccessConstructor and Description
public
MemberOrArgument(String _name, String _type, boolean _finalMember)

public

Method Summary

Modifier and TypeMethod and Description
public String
asOneLineString(Set<String> _allImports, String _prefix, boolean _includeAnnotations)

public List<String>
generateCode(String _indent, String _prefix, Set<String> _allImports)

public List<String>
public String
getFullType(Set<String> _allImports)

public List<String>
public String
public String
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

annotationsback to summary
private final List<String> annotations

List of annotations for this member.

finalArgback to summary
private final boolean finalArg

True to force this member to be final, false otherwise.

genericsback to summary
private final List<String> generics

List of classes/types or placeholders put into diamond operators to use as generics.

GETTER_TEMPLback to summary
private static final String GETTER_TEMPL
nameback to summary
private final String name

Name of member/field.

SETTER_TEMPLback to summary
private static final String SETTER_TEMPL
typeback to summary
private final String type

Type of member/field (e.g. String, int...).

Constructor Detail

MemberOrArgumentback to summary
public MemberOrArgument(String _name, String _type, boolean _finalMember)
MemberOrArgumentback to summary
public MemberOrArgument(String _name, String _type)

Method Detail

asOneLineStringback to summary
public String asOneLineString(Set<String> _allImports, String _prefix, boolean _includeAnnotations)
generateCodeback to summary
public List<String> generateCode(String _indent, String _prefix, Set<String> _allImports)
getAnnotationsback to summary
public List<String> getAnnotations()
getFullTypeback to summary
public String getFullType(Set<String> _allImports)
getGenericsback to summary
public List<String> getGenerics()
getNameback to summary
public String getName()
getTypeback to summary
public String getType()
isFinalArgback to summary
public boolean isFinalArg()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override