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

Creates invalid imports when defining array for ClassName instance #119

Open
Thorinwasher opened this issue Nov 11, 2024 · 1 comment
Open

Comments

@Thorinwasher
Copy link

Thorinwasher commented Nov 11, 2024

What happened?

I'm generating code that uses arrays in parameters / return types for methods. When compiling these, the classes for those are not defined. I therefore use the ClassName class to define this. The main problem I'm experiencing is that the imports become messed up if I try to add [] after the class name, it can for example looks like this:

import org.mockbukkit.integrationtester.resource.ResourcePackInfoLikeMirror[];

So to say, the array specifier becomes included into the import, which makes the project not compile.

What did you want to happen?

Either make it possible to programatically specify arrays for ClassName instances, or remove the [] qualifier from the simplified name when generating imports.

Contribution

I can make a pr for this if necessary.

@ayush-finix
Copy link

I can't really test since you don't have an example, but are you sure you're not supposed to use ArrayTypeName.get for the places where you want to use it? I see this

public static ClassName get(Class<?> clazz) {
    checkNotNull(clazz, "clazz == null");
    checkArgument(!clazz.isPrimitive(), "primitive types cannot be represented as a ClassName");
    checkArgument(!void.class.equals(clazz), "'void' type cannot be represented as a ClassName");
    checkArgument(!clazz.isArray(), "array types cannot be represented as a ClassName");

in class name which kinda makes me feel like you can't actually use a direct array type in class name.

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

No branches or pull requests

2 participants