Skip to content

Commit

Permalink
Improve debugging of GeneratedClassBuildItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Nov 25, 2024
1 parent 296ffde commit b8740cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public final class GeneratedClassBuildItem extends MultiBuildItem {

final boolean applicationClass;
final String name;
String binaryName;
String internalName;
final byte[] classData;
final String source;

Expand All @@ -27,10 +29,38 @@ public boolean isApplicationClass() {
return applicationClass;
}

/**
* {@return a name for this class}
* @deprecated This method may return the binary name, the internal name, or a hybrid thereof and should not be
* used. Use {@link #binaryName()} or {@link #internalName()} instead.
*/
@Deprecated(forRemoval = true)
public String getName() {
return name;
}

/**
* {@return the <em>binary name</em> of the class, which is delimited by <code>.</code> characters}
*/
public String binaryName() {
String binaryName = this.binaryName;
if (binaryName == null) {
binaryName = this.binaryName = name.replace('/', '.');
}
return binaryName;
}

/**
* {@return the <em>internal name</em> of the class, which is delimited by <code>/</code> characters}
*/
public String internalName() {
String internalName = this.internalName;
if (internalName == null) {
internalName = this.internalName = name.replace('.', '/');
}
return internalName;
}

public byte[] getClassData() {
return classData;
}
Expand All @@ -39,4 +69,7 @@ public String getSource() {
return source;
}

public String toString() {
return "GeneratedClassBuildItem[" + binaryName() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ boolean isKafkaConnector(List<ConnectorManagedChannelBuildItem> list, boolean in
});

assertThat(generated)
.extracting(GeneratedClassBuildItem::getName)
.extracting(GeneratedClassBuildItem::internalName)
.allSatisfy(s -> assertThat(generatedNames).satisfiesOnlyOnce(c -> c.apply(s)));

assertThat(reflective)
.flatExtracting(ReflectiveClassBuildItem::getClassNames)
.extracting(n -> n.replace('/', '.'))
.allSatisfy(s -> assertThat(reflectiveNames).satisfiesOnlyOnce(c -> c.apply(s)));
} finally {
// must not leak the lazily-initialized Config instance associated to the system classloader
Expand Down

0 comments on commit b8740cc

Please sign in to comment.