Refactor record to class and vice versa
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Description
NetBeans should assist in changing records to classes and classes to records.
It already provides a hint to convert some classes to an interface, for example an empty class like
```java
public class Empty {
}
```
can be converted to
```java
public interface Empty {
}
```
with two clicks.
A record like
```java
public record R(String name) {
}
```
should be converted to something like
```java
public class R {
private String name;
public R(final String name) {
this.name = name;
}
public String name() {
return name;
}
}
```
and a class
```java
public class C {
private String name;
public C(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
```
to
```java
public record C(String name) {
public String getName() {
return name;
}
}
```
Unfortunately classes and records have different naming conventions for getters, but that can be addressed in further refactoring steps.
### Use case/motivation
Sometimes I start with a class or a record and later the other type seems to be more appropriate, but it is tedious to do the conversion by hand.
### Related issues
Currently the refactoring action „Move inner to outer level“ converts records to classes, but I don’t think it should do that and it’s broken anyway (#7044, #6139).
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Review the existing class-to-interface hint and the “Move inner to outer level” refactoring, along with related issues #7044 and #6139. Done means NetBeans can offer record-to-class and class-to-record conversions while preserving the demonstrated members; clarify behavior and tests before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100