Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
756 stars 55 forks source link

support naked main / empty packages #190

Closed maxandersen closed 1 month ago

maxandersen commented 1 month ago

in Java 23 preview you can have naked main that cannot be in a package; when I try use record-builder it seem to use classname as package:

demo.java:

import io.soabase.recordbuilder.core.RecordBuilder;

@RecordBuilder
record Person(String name, int age) {};

void main() {
    System.out.println("Hello, World");
}

result in a generated class named: demoPersonBuilder.java and inside it generates:

 @Generated("io.soabase.recordbuilder.core.RecordBuilder")
    public static demo.Person Person(String name, int age) {
        return new demo.Person(name, age);
    }

which does not work/compile.

maxandersen commented 1 month ago

btw. this works:

package mypackage;

import io.soabase.recordbuilder.core.RecordBuilder;

@RecordBuilder
record Person(String name, int age) {};

class demo {
void main() {

    var fb = PersonBuilder.builder().name("John").age(20).build();
    System.out.println("Hello, World: " + fb);
}

}

but would love to remove all the unnecessary parts :)

maxandersen commented 1 month ago

might actually be a limitation of naked mains.

Funny enough I can put the records in a separate file and it works.