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

Use Jstachio for code templating #65

Merged
merged 43 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6eac7c8
allow empty records
SentryMan Jan 7, 2024
ed4d471
support unnamed package records
SentryMan Jan 7, 2024
d77701b
Merge branch 'main' into empty
SentryMan Jan 7, 2024
b713d7f
defaults
SentryMan Jan 8, 2024
4521d86
Update README.md
SentryMan Jan 8, 2024
b380c83
Update README.md
SentryMan Jan 8, 2024
d9c9166
Update README.md
SentryMan Jan 8, 2024
f78e719
start
SentryMan Jan 8, 2024
cd7d4ad
done
SentryMan Jan 8, 2024
16b33b4
Merge branch 'main' into nullability
SentryMan Jan 8, 2024
fd46274
Update module-info.java
SentryMan Jan 8, 2024
7c2bd5f
Merge branch 'nullability' of https://github.com/SentryMan/avaje-reco…
SentryMan Jan 8, 2024
ae09ed3
Update RecordBuilder.java
SentryMan Jan 8, 2024
a6a316f
try checker framework
SentryMan Jan 8, 2024
fd82e31
Revert "try checker framework"
SentryMan Jan 8, 2024
9ce8fb8
get checker to work
SentryMan Jan 8, 2024
50956e6
make some progess
SentryMan Jan 8, 2024
d547e45
finally get it working
SentryMan Jan 8, 2024
990a565
null away and error prone
SentryMan Jan 8, 2024
70d71fd
Update pom.xml
SentryMan Jan 8, 2024
491d116
nullaway
SentryMan Jan 8, 2024
4a05add
Update README.md
SentryMan Jan 8, 2024
8f430a1
format
SentryMan Jan 8, 2024
de4d8bf
helpful error message
SentryMan Jan 9, 2024
eb1a17e
Merge remote-tracking branch 'upstream/main' into nullability
SentryMan Jan 9, 2024
3053401
Update ImportPrism.java
SentryMan Jan 9, 2024
202c2d9
support partial compile
SentryMan Jan 9, 2024
a738aa2
Merge branch 'main' into nullability
SentryMan Jan 13, 2024
cf89a7e
support @NullMarked
SentryMan Jan 16, 2024
76ac62e
support nullUnmarked
SentryMan Jan 16, 2024
a314998
Merge branch 'main' into nullability
SentryMan Jan 29, 2024
3d9d497
Merge branch 'main' into nullability
SentryMan Feb 22, 2024
2652118
Merge branch 'main' into nullability
SentryMan Jun 15, 2024
041f59b
Merge branch 'main' into nullability
SentryMan Jul 15, 2024
c463949
Merge branch 'main' into nullability
rbygrave Aug 30, 2024
0aec148
follow pr suggestions
SentryMan Aug 30, 2024
f5fa4ad
Merge branch 'nullability' of https://github.com/SentryMan/avaje-reco…
SentryMan Aug 30, 2024
0912aed
disable EA
SentryMan Aug 30, 2024
d447400
Update ImportPrism.java
SentryMan Aug 30, 2024
bd4439a
Use Jstachio for Templating
SentryMan Aug 30, 2024
61d7d09
Merge remote-tracking branch 'upstream/main' into jstachio
SentryMan Aug 31, 2024
870ea48
Update module-info.java
SentryMan Aug 31, 2024
df05c41
Update package-info.java
SentryMan Aug 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions avaje-record-builder-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<avaje.prisms.version>1.31</avaje.prisms.version>
<io.jstach.version>1.3.6</io.jstach.version>
</properties>

<dependencies>
Expand All @@ -25,6 +26,20 @@
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jstach</groupId>
<artifactId>jstachio-annotation</artifactId>
<version>${io.jstach.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jstach</groupId>
<artifactId>jstachio-apt</artifactId>
<version>${io.jstach.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.avaje.recordbuilder.internal;

import static io.avaje.recordbuilder.internal.Templates.classTemplate;
import static java.util.stream.Collectors.joining;

import java.text.MessageFormat;
Expand All @@ -10,6 +9,8 @@
import javax.lang.model.element.RecordComponentElement;
import javax.lang.model.element.TypeElement;

import io.avaje.recordbuilder.internal.Templates.ClassTemplate;

public class ClassBodyBuilder {

private ClassBodyBuilder() {}
Expand Down Expand Up @@ -51,7 +52,7 @@ static String createClassStart(
builderFrom(components).transform(s -> numberOfComponents > 5 ? "\n " + s : s);
final String build =
build(components).transform(s -> numberOfComponents > 6 ? "\n " + s : s);
return classTemplate(
return ClassTemplate.classTemplate(
packageName,
imports,
shortName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,22 @@ String fields() {
var index = mainType.lastIndexOf(".");
var isNested = index != -1;
if (isNested) {
typename = new StringBuilder(typename).insert(index + 1, "@Nullable ").toString();
typename =
new StringBuilder(typename)
.insert(
index + 1,
APContext.typeElement(NullablePrism.PRISM_TYPE) != null ? "@Nullable " : "")
.toString();
}

builder.append(
" private %s%s %s%s;\n"
.formatted(
isNested || Utils.isNullableType(uType.mainType()) ? "" : "@Nullable ",
isNested
|| APContext.typeElement(NullablePrism.PRISM_TYPE) == null
|| Utils.isNullableType(uType.mainType())
? ""
: "@Nullable ",
typename,
element.getSimpleName(),
defaultVal));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import static io.avaje.recordbuilder.internal.APContext.getModuleInfoReader;
import static io.avaje.recordbuilder.internal.APContext.logError;
import static io.avaje.recordbuilder.internal.APContext.typeElement;
import static io.avaje.recordbuilder.internal.Templates.methodAdd;
import static io.avaje.recordbuilder.internal.Templates.methodGetter;
import static io.avaje.recordbuilder.internal.Templates.methodPut;
import static io.avaje.recordbuilder.internal.Templates.methodSetter;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;

Expand All @@ -30,6 +26,10 @@

import io.avaje.prism.GenerateAPContext;
import io.avaje.prism.GenerateUtils;
import io.avaje.recordbuilder.internal.Templates.MethodAdd;
import io.avaje.recordbuilder.internal.Templates.MethodGetter;
import io.avaje.recordbuilder.internal.Templates.MethodPut;
import io.avaje.recordbuilder.internal.Templates.MethodSetter;

@GenerateUtils
@GenerateAPContext
Expand Down Expand Up @@ -119,8 +119,7 @@ private void readElement(TypeElement type, BuilderPrism prism) {
.map(Object::toString)
.collect(joining(", "))
.transform(s -> s.isEmpty() ? s : "<" + s + ">");
writer.append(
ClassBodyBuilder.createClassStart(type, typeParams, isImported, packageName));
writer.append(ClassBodyBuilder.createClassStart(type, typeParams, isImported, packageName));

methods(writer, typeParams, shortName, components, prism);
} catch (final IOException e) {
Expand All @@ -138,17 +137,19 @@ private void methods(

for (final var element : components) {
final var type = UType.parse(element.asType());
writer.append(methodSetter(element.getSimpleName(), type.shortType(), shortName, typeParams));
writer.append(
MethodSetter.methodSetter(
element.getSimpleName(), type.shortType(), shortName, typeParams));
if (getters) {
writer.append(methodGetter(element.getSimpleName(), type, shortName));
writer.append(MethodGetter.methodGetter(element.getSimpleName(), type, shortName));
}

if (APContext.isAssignable(type.mainType(), "java.util.Collection")) {

String param0ShortType = type.param0().shortType();
Name simpleName = element.getSimpleName();
writer.append(
methodAdd(
MethodAdd.methodAdd(
simpleName.toString(), type.shortType(), shortName, param0ShortType, typeParams));
}

Expand All @@ -158,13 +159,8 @@ private void methods(
String param1ShortType = type.param1().shortType();
Name simpleName = element.getSimpleName();
writer.append(
methodPut(
simpleName.toString(),
type.shortType().transform(ProcessorUtils::trimAnnotations),
shortName,
param0ShortType,
param1ShortType,
typeParams));
MethodPut.methodPut(
simpleName.toString(), shortName, param0ShortType, param1ShortType, typeParams));
}
}
writer.append("}");
Expand Down
Loading
Loading