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

static imports don't work with annotations #861

Open
prabhu-madanagopal opened this issue Jan 20, 2022 · 3 comments
Open

static imports don't work with annotations #861

prabhu-madanagopal opened this issue Jan 20, 2022 · 3 comments

Comments

@prabhu-madanagopal
Copy link

In MethodSpec.Builder, I have...
builder.addAnnotation(Value.Lazy.class);

In JavaFile.Builder, I have..

 JavaFile.builder(..)
                    .addStaticImport(Value.class, "Immutable", "Default", "Lazy");

static import is added, however the annotation contains the fully qualified static name....

    @Value.Lazy
    public Optional<String> get...() {
@JakeWharton
Copy link
Member

Static imports are for static functions and JavaPoet does nothing with them when handling type references. Nested types in Java use regular imports, but JavaPoet will always prefer to import the top-level type and use a semi-qualified reference instead. There is no way to force it that I can remember.

@prabhu-madanagopal
Copy link
Author

generated file contains the static import as below but the type reference in annotations don't reflect the static import, as you said.

import static org.immutables.value.Value.Lazy;
import static org.immutables.value.Value.Immutable;

@JakeWharton
Copy link
Member

Right but static imports are not for types, they're for methods. So that is working as expected.

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