Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion jsonb-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>avaje jsonb generator</name>
<description>annotation processor generating source code json adapters for avaje-jsonb</description>
<properties>
<avaje.prisms.version>2.0-RC1</avaje.prisms.version>
<avaje.prisms.version>2.0-RC2</avaje.prisms.version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ final class AdapterName {
String originPackage = APContext.elements().getPackageOf(beanReader.beanType()).getQualifiedName().toString();
var name = shortName(beanReader.beanType());
shortName = name.substring(0, name.length() - 1);
if (beanReader.isPkgPrivate()) {
if (beanReader.isPkgPrivate() || "".equals(originPackage)) {
this.adapterPackage = originPackage;
} else if ("".equals(originPackage)) {
this.adapterPackage = "jsonb";
} else {
this.adapterPackage = ProcessingContext.isImported(beanReader.beanType()) ? originPackage + ".jsonb" : originPackage;
}
this.fullName = adapterPackage + "." + shortName + "JsonAdapter";
this.fullName =
adapterPackage.isBlank()
? shortName + "JsonAdapter"
: adapterPackage + "." + shortName + "JsonAdapter";
}

private String shortName(TypeElement origin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ String fullName(boolean pkgPrivate) {
var everyType = new ArrayList<>(allTypes);
everyType.addAll(factoryTypes);
String topPackage = TopPackage.of(everyType);
if (!pkgPrivate && !topPackage.endsWith(".jsonb")) {
var defaultPackage =
!topPackage.contains(".")
&& APContext.getProjectModuleElement().isUnnamed()
&& APContext.elements().getPackageElement(topPackage) == null;
if (!defaultPackage && !pkgPrivate && !topPackage.endsWith(".jsonb")) {
topPackage += ".jsonb";
}
if (pkgPrivate) {

if (defaultPackage) {
fullName = "GeneratedJsonComponent";
} else if (pkgPrivate) {
fullName = topPackage + "." + name(topPackage) + "JsonComponent";
} else if (APContext.isTestCompilation()) {
fullName = topPackage + ".TestJsonComponent";
Expand Down Expand Up @@ -128,4 +135,4 @@ private static String camelCase(String name) {
private static boolean toUpperOn(char aChar) {
return aChar == ' ' || aChar == '-' || aChar == '_';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ private void writeImports() {
}

private void writePackage() {
writer.append("package %s;", adapterPackage).eol().eol();
if (!adapterPackage.isBlank()) {
writer.append("package %s;", adapterPackage).eol().eol();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class SimpleComponentWriter {

void initialise(boolean pkgPrivate) throws IOException {
fullName = metaData.fullName(pkgPrivate);
packageName = Util.packageOf(fullName);
packageName = "GeneratedJsonComponent".equals(fullName) ? "" : ProcessorUtils.packageOf(fullName);
if (fileObject == null) {
fileObject = createSourceFile(fullName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class TopPackage {

private String topPackage = "";
private String topPackage;

static String of(Collection<String> values) {
return new TopPackage(values).value();
Expand All @@ -16,7 +16,7 @@ private String value() {

private TopPackage(Collection<String> values) {
for (String pkg : values) {
topPackage = Util.commonParent(topPackage, pkg);
topPackage = ProcessorUtils.commonParent(topPackage, pkg);
}
}
}
28 changes: 1 addition & 27 deletions jsonb-generator/src/main/java/io/avaje/jsonb/generator/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ && importDifferentPackage(type, packageName)
}

private static boolean importDifferentPackage(String type, String packageName) {
return type.replace(packageName + '.', "").indexOf('.') > 0;
return packageName.isBlank() || type.replace(packageName + '.', "").indexOf('.') > 0;
}

private static boolean importJavaLangSubpackage(String type) {
Expand All @@ -50,11 +50,6 @@ private static String trimArrayBrackets(String type) {
return type.replaceAll("[^\\n\\r\\t $*_;\\w.]", "");
}

static String packageOf(String cls) {
int pos = cls.lastIndexOf('.');
return pos == -1 ? "" : cls.substring(0, pos);
}

static String shortName(String fullType) {
int p = fullType.lastIndexOf('.');
if (p == -1) {
Expand Down Expand Up @@ -111,27 +106,6 @@ private static String cutAnnotations(String input) {
return cutAnnotations(result);
}

/** Return the common parent package. */
static String commonParent(String currentTop, String aPackage) {
if (aPackage == null) return currentTop;
if (currentTop.isBlank()) return packageOf(aPackage);
if (aPackage.startsWith(currentTop)) {
return currentTop;
}
int next;
do {
next = currentTop.lastIndexOf('.');
if (next > -1) {
currentTop = currentTop.substring(0, next);
if (aPackage.startsWith(currentTop)) {
return currentTop;
}
}
} while (next > -1);

return currentTop;
}

static String initCap(String input) {
if (input.length() < 2) {
return input.toUpperCase();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<properties>
<surefire.useModulePath>false</surefire.useModulePath>
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose>
<spi.version>2.13</spi.version>
<spi.version>2.14-RC1</spi.version>
<project.build.outputTimestamp>2025-12-01T15:29:52Z</project.build.outputTimestamp>
</properties>

Expand Down