Package io.github.chrimle.classforge
Class AbstractBuilder<T extends Builder<T>>
java.lang.Object
io.github.chrimle.classforge.AbstractBuilder<T>
- All Implemented Interfaces:
Builder<T>
- Direct Known Subclasses:
ClassBuilder
,EnumBuilder
public abstract sealed class AbstractBuilder<T extends Builder<T>>
extends Object
implements Builder<T>
permits ClassBuilder, EnumBuilder
Abstract class for building and generating Java classes.
- Since:
- 0.1.0
- Author:
- Chrimle
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.chrimle.classforge.Builder
Builder.VersionPlacement
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
TheclassName
of the currently uncommitted class.protected String
Thedirectory
of the currently uncommitted class.protected String
ThepackageName
of the currently uncommitted class.The collection of previously committed classes.protected SemVer
ThesemVer
of the previously committed class.protected Builder.VersionPlacement
TheversionPlacement
of the currently uncommitted class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncommit()
Commits the currently uncommitted changes as a new class.commit
(SemVer.Change change) Commits the currently uncommitted changes as a new class.protected SemVer.Change
Determines theSemVer.Change
for the currently uncommitted changes.protected void
generateClassFile
(SemVer semVer) Generates a.java
class file for the currently uncommitted class.protected abstract String
generateFileContent
(SemVer semVer) Generates the complete file contents for a.java
file for the currently uncommitted class.protected String
resolveEffectivePackageName
(SemVer semVer) Resolves the effective package name for the currently uncommitted class.protected String
resolveFullyQualifiedClassName
(SemVer semVer) Resolves the Fully Qualified Class Name (FQCN) for the currently uncommitted class.protected abstract T
self()
Returns this asAbstractBuilder
.Sets thesemVer
of the currently uncommitted class.setVersionPlacement
(Builder.VersionPlacement versionPlacement) Sets theversionPlacement
of the currently uncommitted class.updateClassName
(String className) Updates theclassName
of the currently uncommitted class.updateDirectory
(String directory) Updates thedirectory
of the currently uncommitted class.updatePackageName
(String packageName) Updates thepackageName
of the currently uncommitted class.protected void
Validates additionalPredicate
s for determining the validity of the currently uncommitted class.
-
Field Details
-
reservedClassNames
The collection of previously committed classes. -
semVer
ThesemVer
of the previously committed class. Starts at0.0.0
. -
versionPlacement
TheversionPlacement
of the currently uncommitted class. -
directory
Thedirectory
of the currently uncommitted class. -
packageName
ThepackageName
of the currently uncommitted class. -
className
TheclassName
of the currently uncommitted class.
-
-
Constructor Details
-
AbstractBuilder
public AbstractBuilder()
-
-
Method Details
-
setSemVer
Sets thesemVer
of the currently uncommitted class.NOTE: the
semVer
will be updated when committing the changes. -
setVersionPlacement
Sets theversionPlacement
of the currently uncommitted class.Default:
Builder.VersionPlacement.NONE
.- Specified by:
setVersionPlacement
in interfaceBuilder<T extends Builder<T>>
- Parameters:
versionPlacement
- for the class.- Returns:
- this
Builder
.
-
updateDirectory
Updates thedirectory
of the currently uncommitted class.- Specified by:
updateDirectory
in interfaceBuilder<T extends Builder<T>>
- Parameters:
directory
- of the class.- Returns:
- this
Builder
.
-
updatePackageName
Updates thepackageName
of the currently uncommitted class.- Specified by:
updatePackageName
in interfaceBuilder<T extends Builder<T>>
- Parameters:
packageName
- of the class.- Returns:
- this
Builder
.
-
updateClassName
Updates theclassName
of the currently uncommitted class.- Specified by:
updateClassName
in interfaceBuilder<T extends Builder<T>>
- Parameters:
className
- of the class.- Returns:
- this
Builder
.
-
commit
Commits the currently uncommitted changes as a new class. ThesemVer
of the new class will be set automatically. -
commit
Commits the currently uncommitted changes as a new class. ThesemVer
of the new class will be set according to the givenchange
. -
determineSemVerChange
Determines theSemVer.Change
for the currently uncommitted changes.- Returns:
- the
Change
.
-
self
Returns this asAbstractBuilder
.- Returns:
- this.
-
validateAdditionalPredicates
protected void validateAdditionalPredicates()Validates additionalPredicate
s for determining the validity of the currently uncommitted class. -
generateFileContent
Generates the complete file contents for a.java
file for the currently uncommitted class.- Parameters:
semVer
- for the new class.- Returns:
- the file contents as a
String
.
-
generateClassFile
Generates a.java
class file for the currently uncommitted class.- Parameters:
semVer
- for the new class.
-
resolveFullyQualifiedClassName
Resolves the Fully Qualified Class Name (FQCN) for the currently uncommitted class.Example:
module.sub_module.ExampleClass
orAnotherExampleClass
.- Parameters:
semVer
- for the new class.- Returns:
- the FQCN.
-
resolveEffectivePackageName
Resolves the effective package name for the currently uncommitted class.- Parameters:
semVer
- for the class.- Returns:
- the effective package name.
-