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

Gizmo2: add convenient default methods to ClassOutput #221

Merged
merged 1 commit into from
Mar 11, 2025
Merged
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
23 changes: 23 additions & 0 deletions src/main/java/io/quarkus/gizmo2/ClassOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
* A container for created classes with a specific output strategy.
*/
public interface ClassOutput {

/**
* Add a new class.
*
* @param name the fully qualified (dot-separated) binary class name
* @param builder the
* @return the descriptor
*/
default ClassDesc class_(String name, Consumer<ClassCreator> builder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for asking out of the blue, but I was wondering if we should go with things like createClass instead of class_? Now maybe this is coming from the Class File API but it's not very pretty?

Note that this might be a completely stupid question as I haven't looked at the API in depth but I think it's probably now or never to ask this question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not stupid at all. We should think about a good strategy because it's not only class that is reserved and cannot be used "as is". I have to admit that I like the concise underscore suffix strategy but I agree that it does not feel very "Java"-like.

return class_(ClassDesc.of(name), builder);
}

/**
* Add a new class.
*
Expand All @@ -19,6 +31,17 @@ public interface ClassOutput {
*/
ClassDesc class_(ClassDesc desc, Consumer<ClassCreator> builder);

/**
* Add a new interface.
*
* @param name the fully qualified (dot-separated) binary class name
* @param builder the
* @return the descriptor
*/
default ClassDesc interface_(String name, Consumer<InterfaceCreator> builder) {
return interface_(ClassDesc.of(name), builder);
}

/**
* Add a new interface.
*
Expand Down