Skip to content

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Apr 14, 2025

  • the API to create annotations no longer leaks the ClassFile API
  • add the ClassVersion enum

Fixes #331
Fixes #332

@Ladicek Ladicek added the 2.x Issue applies to Gizmo 2.x label Apr 14, 2025
@Ladicek
Copy link
Contributor Author

Ladicek commented Apr 14, 2025

Probably best to review commits in isolation, even though the second one is quite small.

@Ladicek Ladicek moved this to In Progress in WG - Gizmo 2 Apr 14, 2025
this.number = number;
}

public int number() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public int number() {
/**
* {@return the Java version as an integer}
*/
public int number() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, removed the method.


public void withVersion(final ClassVersion version) {
checkNotNullParam("version", version);
this.version = ClassFileFormatVersion.valueOf("RELEASE_" + version.number());
Copy link
Member

Choose a reason for hiding this comment

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

This is a little grisly. :-)

Maybe it would be slightly cleaner to use an enum switch expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would actually allow removing the number() method from ClassVersion, which makes a lot of sense. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 232 to 236
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = AnnotationCreator.class.getClassLoader();
}
clazz = (Class<S>) Class.forName(annotationClass, false, cl);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should consider requiring that a Class<S> be passed in instead of trying to do class loader magic. TCCL is almost certainly the wrong one to use at any rate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that, I was just thinking that the variant that accepts the annotation element as a method reference is supposed to be most user friendly and hence should figure out the nested annotation class on its own.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally yes, but in practice I can't think of a totally safe/totally correct way to do it automatically. The lambda instance does not seem to have a concrete generic type, so we can't probe it that way. AFAICT we can't know for sure what class loader originated the type of the nested annotation.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I'm being silly. We can examine the method on the enclosing annotation type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, good point! I'll try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Ladicek added 2 commits April 14, 2025 16:41
The methods to add nested annotation[s] no longer attempt to load the class
of the nested annotation from a classloader. Instead, they take it from
the return type of the annotation element.

Additionally, the annotation creation API now allows creating annotations
based on a `ClassDesc` description of the annotation type, not only based
on the `Class<? extends Annotation>` description.
This is our public API for specifying the desired class file version.
The `ClassFileFormatVersion` enum from the ClassFile API no longer
leaks from the Gizmo public API.
@Ladicek Ladicek force-pushed the hide-some-classfile-api branch from 7638669 to 2417a87 Compare April 14, 2025 14:43
@Ladicek Ladicek changed the title hide some ClassFile api hide some ClassFile API Apr 14, 2025
@dmlloyd dmlloyd merged commit 23b5542 into quarkusio:main Apr 14, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in WG - Gizmo 2 Apr 14, 2025
@Ladicek Ladicek deleted the hide-some-classfile-api branch April 15, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue applies to Gizmo 2.x
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

avoid leaking the ClassFile API for specifying class version avoid leaking the ClassFile API for annotation creation
2 participants