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

Support Parameterized Types in Methods #116

Closed

Conversation

Sgitario
Copy link

This pull request handles the support of parameterized types when creating methods. Example:

public List<String> methodName() {
}

Where List<String> is a parameterized type.

In order to do this, we need to amend the signature of the method as the descriptor does not support it (it says class not found when trying to declare Ljava.util.List<Ljava.lang.String;>;).

In order to resolve this, we have added a wrapper type ParameterizedClass where we can specify the wrapper type and the param types. Usage:

MethodCreator method = creator.getMethodCreator("methodName", new ParameterizedClass(List.class, String.class));

This pull request partially resolves: #66 (which is intended to be for classes too)
Moreover, these changes are inspired by the changes in quarkusio/quarkus#26074 (that there will be deprecated once gizmo dependency is bumped).

I've verified these changes in Quarkus upstream too (reverting the changes of the mentioned Quarkus pull request) and it worked fine.

This pull request handles the support of parameterized types when creating methods. Example:
```java
public List<String> methodName() {
}
```

Where `List<String>` is a parameterized type. 

In order to do this, we need to amend the `signature` of the method as the descriptor does not support it (it says class not found when trying to declare `Ljava.util.List<Ljava.lang.String;>;`). 

In order to resolve this, we have added a wrapper type `ParameterizedClass` where we can specify the wrapper type and the param types. Usage:

```
MethodCreator method = creator.getMethodCreator("methodName", new ParameterizedClass(List.class, String.class));
```

This pull request partially resolves: quarkusio#66 (which is intended to be for classes too)
Moreover, these changes are inspired by the changes in quarkusio/quarkus#26074 (that there will be deprecated once gizmo dependency is bumped).

I've verified these changes in Quarkus upstream too (reverting the changes of the mentioned Quarkus pull request) and it worked fine.
@mkouba
Copy link
Contributor

mkouba commented Jan 5, 2023

So the MethodCreator implements the SignatureElement and allows you to set the method signature. I think that it would be more convenient to provide a signature util method that would accept jandex org.jboss.jandex.Type params.
Maybe something like:

public static String signatureFrom(Type returnType, String methodName, Type[] parameters) {
  // ...
}

declated on the io.quarkus.gizmo.SignatureElement.

Also it seems that ParameterizedClass does not support nested params, or?

@mkouba
Copy link
Contributor

mkouba commented Jan 5, 2023

FTR I'm working on a pull request that introduces a SignatureBuilder API (inspired by ideas/work from @Ladicek).

@Sgitario
Copy link
Author

Sgitario commented Jan 9, 2023

Ok, closing.

@Sgitario Sgitario closed this Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify the handling of parameterized types
2 participants