-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create add method for initialized collections (#4)
* Remove unused var * Adding builder classes * Add GeneratorFactory * Handle addToCollection
- Loading branch information
1 parent
0839006
commit 97b236f
Showing
15 changed files
with
417 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/junkfactory/innerbuilder/generators/BuilderClassGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.junkfactory.innerbuilder.generators; | ||
|
||
import com.intellij.psi.PsiMethod; | ||
import com.intellij.psi.PsiModifier; | ||
import com.intellij.psi.util.PsiUtil; | ||
|
||
class BuilderClassGenerator extends AbstractGenerator { | ||
|
||
private final BuilderClassParams builderClassParams; | ||
private final Runnable fieldsGenerator; | ||
private final Runnable methodsGenerator; | ||
|
||
BuilderClassGenerator(GeneratorFactory generatorFactory, | ||
GeneratorParams generatorParams, | ||
BuilderClassParams builderClassParams) { | ||
super(generatorFactory, generatorParams); | ||
this.builderClassParams = builderClassParams; | ||
this.fieldsGenerator = generatorFactory.createBuilderFieldsGenerator(generatorParams, builderClassParams); | ||
this.methodsGenerator = generatorFactory.createBuilderMethodsGenerator(generatorParams, builderClassParams); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
//builder constructor | ||
var builderClass = builderClassParams.builderClass(); | ||
var builderConstructor = generateBuilderConstructor(); | ||
addMethod(builderClass, null, builderConstructor, false); | ||
|
||
fieldsGenerator.run(); | ||
methodsGenerator.run(); | ||
} | ||
|
||
private PsiMethod generateBuilderConstructor() { | ||
var builderConstructor = generatorParams.psi().factory().createConstructor(BUILDER_CLASS_NAME); | ||
PsiUtil.setModifierProperty(builderConstructor, PsiModifier.PRIVATE, true); | ||
return builderConstructor; | ||
} | ||
|
||
} |
Oops, something went wrong.