Skip to content
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

Refactor record to class and vice versa #7762

Open
maffe opened this issue Sep 17, 2024 · 0 comments
Open

Refactor record to class and vice versa #7762

maffe opened this issue Sep 17, 2024 · 0 comments
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:feature A feature request

Comments

@maffe
Copy link

maffe commented Sep 17, 2024

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

public class Empty {
}

can be converted to

public interface Empty {
}

with two clicks.

A record like

public record R(String name) {
}

should be converted to something like

public class R {

    private String name;

    public R(final String name) {
        this.name = name;
    }

    public String name() {
        return name;
    }
}

and a class

public class C {

    private String name;

    public C(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

to

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

@maffe maffe added kind:feature A feature request needs:triage Requires attention from one of the committers labels Sep 17, 2024
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints and removed needs:triage Requires attention from one of the committers labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:feature A feature request
Projects
None yet
Development

No branches or pull requests

2 participants