[ https://issues.apache.org/jira/browse/BEAM-13429?focusedWorklogId=708383&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-708383 ]
ASF GitHub Bot logged work on BEAM-13429: ----------------------------------------- Author: ASF GitHub Bot Created on: 13/Jan/22 15:00 Start Date: 13/Jan/22 15:00 Worklog Time Spent: 10m Work Description: daria-malkova commented on a change in pull request #16482: URL: https://github.com/apache/beam/pull/16482#discussion_r784039723 ########## File path: playground/backend/internal/preparers/java_preparators.go ########## @@ -40,47 +38,85 @@ const ( publicClassNamePattern = "public class (.*?) [{|implements(.*)]" ) -// GetJavaPreparators returns preparation methods that should be applied to Java code -func GetJavaPreparators(filePath string) *[]Preparator { - removePublicClassPreparator := Preparator{ +//JavaPreparersBuilder facet of PreparersBuilder +type JavaPreparersBuilder struct { + PreparersBuilder +} + +//JavaPreparers chains to type *PreparersBuilder and returns a *JavaPreparersBuilder +func (builder *PreparersBuilder) JavaPreparers() *JavaPreparersBuilder { + return &JavaPreparersBuilder{*builder} +} + +//WithPublicClassRemover adds preparer to remove public class +func (builder *JavaPreparersBuilder) WithPublicClassRemover() *JavaPreparersBuilder { + removePublicClassPreparer := Preparer{ Prepare: removePublicClassModifier, - Args: []interface{}{filePath, classWithPublicModifierPattern, classWithoutPublicModifierPattern}, + Args: []interface{}{builder.filePath, classWithPublicModifierPattern, classWithoutPublicModifierPattern}, } - changePackagePreparator := Preparator{ + builder.AddPreparer(removePublicClassPreparer) + return builder +} + +//WithPackageChanger adds preparer to change package +func (builder *JavaPreparersBuilder) WithPackageChanger() *JavaPreparersBuilder { + changePackagePreparer := Preparer{ Prepare: changePackage, - Args: []interface{}{filePath, packagePattern, importStringPattern}, + Args: []interface{}{builder.filePath, packagePattern, importStringPattern}, } - removePackagePreparator := Preparator{ + builder.AddPreparer(changePackagePreparer) + return builder +} + +//WithPackageRemover adds preparer to remove package +func (builder *JavaPreparersBuilder) WithPackageRemover() *JavaPreparersBuilder { + removePackagePreparer := Preparer{ Prepare: removePackage, - Args: []interface{}{filePath, packagePattern, newLinePattern}, + Args: []interface{}{builder.filePath, packagePattern, newLinePattern}, } - unitTestFileNameChanger := Preparator{ + builder.AddPreparer(removePackagePreparer) + return builder +} + +//WithFileNameChanger adds preparer to remove package +func (builder *JavaPreparersBuilder) WithFileNameChanger() *JavaPreparersBuilder { + unitTestFileNameChanger := Preparer{ Prepare: changeJavaTestFileName, - Args: []interface{}{filePath}, + Args: []interface{}{builder.filePath}, + } + builder.AddPreparer(unitTestFileNameChanger) + return builder +} + +// GetJavaPreparers returns preparation methods that should be applied to Java code +func GetJavaPreparers(builder *PreparersBuilder, isUnitTest bool, isKata bool) { + if !isUnitTest && !isKata { + builder.JavaPreparers(). + WithPublicClassRemover(). + WithPackageChanger() + } + if isUnitTest { + builder.JavaPreparers(). + WithPackageChanger(). + WithFileNameChanger() + } + if isKata { + builder.JavaPreparers(). + WithPublicClassRemover(). + WithPackageRemover() } - return &[]Preparator{removePublicClassPreparator, changePackagePreparator, removePackagePreparator, unitTestFileNameChanger} } //changePackage changes the 'package' to 'import' and the last directory in the package value to '*' func changePackage(args ...interface{}) error { - validationResults := args[3].(*sync.Map) - isKata, ok := validationResults.Load(validators.KatasValidatorName) - if ok && isKata.(bool) { - return nil - } err := replace(args...) return err } //removePackage remove the package line in the katas. func removePackage(args ...interface{}) error { - validationResults := args[3].(*sync.Map) - isKata, ok := validationResults.Load(validators.KatasValidatorName) - if ok && isKata.(bool) { - err := replace(args...) - return err - } - return nil + err := replace(args...) + return err } Review comment: Removed ########## File path: playground/backend/internal/preparers/java_preparators_test.go ########## @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 708383) Time Spent: 1h 40m (was: 1.5h) > [Playground] Improve preparators by the introducing of builder > --------------------------------------------------------------- > > Key: BEAM-13429 > URL: https://issues.apache.org/jira/browse/BEAM-13429 > Project: Beam > Issue Type: Improvement > Components: beam-playground > Reporter: Daria Malkova > Assignee: Daria Malkova > Priority: P3 > Labels: beam-playground-backend, beam-playground-sprint-6, > beam-playground-sprint-7 > Time Spent: 1h 40m > Remaining Estimate: 0h > > Investigate and implement (if need) a usage of a builder for preparators to > construct the necessary builders for each SDK/unit-test/not-unit-test -- This message was sent by Atlassian Jira (v8.20.1#820001)