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

Improve debugging of GeneratedClassBuildItem #44654

Merged
merged 1 commit into from
Nov 26, 2024
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
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,39 @@ 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 +70,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
Loading