Randgalt / record-builder

Record builder generator for Java records

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate builders for all classes in package

Randgalt opened this issue · comments

Discussed in #66

Originally posted by nikolavojicic August 30, 2021

@RecordBuilder.Include({
    ImportedRecord1.class,
    ImportedRecord2.class,
})
public class Config {}

Is it possible to pass package path(s) somehow, instead of classes, so that builders for all classes in those packages are generated?

I'm not sure how this would work exactly. Every interface in a package would be considered a Record template? That seems not very usable to me. How do you see this working @nikolavojicic?

If we have these 3 records in the package com.foo.bar:

@RecordBuilder.Include({
    ImportedRecord1.class,
    ImportedRecord2.class,
    ImportedRecord3.class
})
public class Config {}

This would have the same effect:

@RecordBuilder.Include(
    path = "com.foo.bar..*" // some regex maybe
)
public class Config {}

We use @RecordBuilder.Include mostly for records we don't "own", the best example is POJO records generated by JOOQ.
So if you have hundreds of tables it is tedious to specify each generated POJO record in Include.

Unfortunately, wildcards can't be supported. The Java's AST methods for annotation processors allow you get to get classes in a given package but that has to be specified explicitly. i.e. we can get all the records in foo.bar.baz (or a list of packages) but any records in packages below foo.bar.baz have to be specified separately - each package has to be specified. Is that still useful?

It is still useful IMO.