Skip to content

Recipe UseLombokSetter deletes setter if annotations are present #5015

@janmaterne

Description

@janmaterne

What version of OpenRewrite are you using?

rewrite-maven-plugin : 6.1.0
rewrite-migrate-java : 3.2.0

How are you running OpenRewrite?

Standalone Maven project

		<profile>
			<id>rewrite</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.openrewrite.maven</groupId>
						<artifactId>rewrite-maven-plugin</artifactId>
						<version>6.1.0</version>
						<executions>
							<execution>
								<goals>
									<goal>run</goal>
								</goals>
								<phase>verify</phase>
							</execution>
						</executions>
						<configuration>
							<exportDatatables>true</exportDatatables>
							<activeRecipes>
								<recipe>org.openrewrite.java.migrate.lombok.UseLombokGetter</recipe>
								<recipe>org.openrewrite.java.migrate.lombok.UseLombokSetter</recipe>
							</activeRecipes>
						</configuration>
						<dependencies>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-migrate-java</artifactId>
								<version>3.2.0</version>
							</dependency>
						</dependencies>
					</plugin>

What is the smallest, simplest way to reproduce the problem?

Example is using Lombok + Spring.

@Service
@Slf4j
public class MyService {

	@Getter
	private String configuration;
	@Getter
	private MyRepository repository;

	@Value("${spring.application.name}")
	public void setConfiguration(String configuration) {
		this.configuration = configuration;
	}

	@Autowired
	public void setRepository(MyRepository repository) {
		this.repository = repository;
	}
}

What did you expect to see?

@Service
@Slf4j
public class MyService {

	@Getter
	@Setter
	@Value("${spring.application.name}")
	private String configuration;
	@Getter
	@Setter
	@Autowired
	private MyRepository repository;
}

What did you see instead?

@Service
@Slf4j
public class MyService {

	@Getter
	@Setter
	private String configuration;
	@Getter
	@Setter
	private MyRepository repository;
}

The recipe deletes the setter method but it also deletes given annotations.
The recipe should delete the setter if an annotation is present or moves the annotation to the field - if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions