Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

WildcardTypeName doesn't emit annotations #959

@lsingh123

Description

@lsingh123

WildcardTypeName ignores its annotations when emitting. For example, consider the following code:

        WildcardTypeName wildcard = WildcardTypeName.subtypeOf(com.squareup.javapoet.TypeName.LONG.box())
                .annotated(List.of(AnnotationSpec.builder(Safe.class).build()));
        ParameterizedTypeName paramTypeName = ParameterizedTypeName.get(ClassName.get(Optional.class), wildcard);
        TypeSpec testTypeSpec = TypeSpec.classBuilder("PoetTestClass")
                .addField(paramTypeName, "testWildcardField", Modifier.PRIVATE)
                .build();
        JavaFile file = JavaFile.builder("com.poet.test", testTypeSpec)
                .skipJavaLangImports(true)
                .indent("    ")
                .build();
        file.writeTo(tempDir.toPath(), StandardCharsets.UTF_8);

We expect this to output:

package com.poet.test;

import java.util.Optional;

class PoetTestClass {
    private Optional<@Safe ? extends Long> testWildcardField;
}

But instead it outputs:

package com.poet.test;

import java.util.Optional;

class PoetTestClass {
    private Optional<? extends Long> testWildcardField;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions