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
Add support for raw (opaque String) parameter list #760
Comments
What do you think of the following? public final CodeBlock opaqueParameters;
public MethodSpec.Builder addOpaqueParameters(CodeBlock block) {
this.opaqueParameters.add(block);
return this;
} |
I'm opposed to such an API because it means we need to support it for return types, field types, and then many other places we support types. Additionally, you still need to process the opaque type to emit imports correctly in which case you could just build a proper TypeName. How do you handle imports with these? |
Just like with Note: JavaCC users declare imports manually. In other words, the parameter list comes to me in a source form (== plain Java-like string). Full type grammar is non-trivial (there are annotations, comments, etc), and I don't really need that for my use case. JavaCC does not need to process/analyze arguments either. The contents of the method would be a mix of user-provided and machine-generated code. I want machine-generated code to be structured (e.g. to avoid unclosed braces), so I want to use JavaPoet for that.
types != parameters There's a workaround for types: For instance, |
It looks like the impacted cases are the ones that have lists of items.
Note: for |
You should be able to solve this by post-processing generated code, e.g. generate a placeholder |
Oh, if you mean that as a workaround, then thanks. It might be helpful indeed. For the time being (e.g. while the issue is under consideration), I've copy-pasted JavaPoet to my source tree and added |
One more |
That doesn't really fit into the model that JavaPoet wants to create though
…On Sat, Feb 1, 2020, 5:42 PM Vladimir Sitnikov ***@***.***> wrote:
One more opaque case: TypeSpec body. In other words, if half of the
TypeSpec exists as a string, then it should be possible to append it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#760?email_source=notifications&email_token=AAAQIEO3WKZVCOUDYZR7YCDRAX3FJA5CNFSM4KLYQKQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRIPDI#issuecomment-581076877>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQIELDQWYRTITPTVLZEXTRAX3FJANCNFSM4KLYQKQA>
.
|
Agree, I wouldn't want this kind of API to be a part of core JavaPoet. Closing. |
Hi,
MethodSpec.Builder#addParameter(com.squareup.javapoet.ParameterSpec)
is nice when parameter types are known.However, I have a use case when parameters are not really known.
In other words, I want to create a method, and I want to use a simple string for arguments.
For instance:
The use case is code generation in javacc/javacc#140
For historical reasons, JavaCC does not really parse user-provided argument types.
For instance, SQL grammar contains the following:
In practice, JavaCC's code generator does not care much of the return type and argument type.
It turns out JavaPoet allows to use raw (opaque) string for return type:
ClassName.get("", "List<any type>")
.However, there's no way to declare a method without knowing the structure of its parameters :(
The text was updated successfully, but these errors were encountered: