Skip to content

Register SourceCodeWriters as beans #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jarlehansen
Copy link
Contributor

@jarlehansen jarlehansen commented Sep 25, 2024

Currently it is difficult to customize how the source code is written, since the KotlinSourceCodeWriter, JavaSourceCodeWriter and GroovySourceCodeWriter is created inline, inside the ProjectGenerationConfiguration. For example:

@Bean
public MainSourceCodeProjectContributor<KotlinTypeDeclaration, KotlinCompilationUnit, KotlinSourceCode> mainKotlinSourceCodeProjectContributor(
		ObjectProvider<MainApplicationTypeCustomizer<?>> mainApplicationTypeCustomizers,
		ObjectProvider<MainCompilationUnitCustomizer<?, ?>> mainCompilationUnitCustomizers,
		ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers) {
	return new MainSourceCodeProjectContributor<>(this.description, KotlinSourceCode::new,
			new KotlinSourceCodeWriter(this.description.getLanguage(), this.indentingWriterFactory),
			mainApplicationTypeCustomizers, mainCompilationUnitCustomizers, mainSourceCodeCustomizers);
}

The change in this PR is to simply change the SourceCodeWriters into beans. This has two benefits. 1) It is easy to override if you need something custom when writing the source code, and 2) we can reused the instance for Main and Test.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 25, 2024
@mhalbritter mhalbritter added type: enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 25, 2024
@mhalbritter mhalbritter self-assigned this Sep 25, 2024
@mhalbritter
Copy link
Contributor

Thanks @jarlehansen and congratulations on your first contribution!

@mhalbritter mhalbritter changed the title Make it possible to customize the SourceCodeWriters Register SourceCodeWriters as beans Sep 25, 2024
@mhalbritter mhalbritter added this to the 0.22.0 milestone Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants