Skip to content

Commit

Permalink
Fix Parameterized is hidden by withFullyQualifiedName (openrewrit…
Browse files Browse the repository at this point in the history
…e#4245)

* Fix `Parametrized` is hidden by `withFullyQualifiedName`

Signed-off-by: Oleh Dokuka <[email protected]>

* Use referential check

Signed-off-by: OlegDokuka <[email protected]>

---------

Signed-off-by: Oleh Dokuka <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
  • Loading branch information
OlegDokuka authored Jun 13, 2024
1 parent 1a7b14f commit 41b5d9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,12 @@ public String getFullyQualifiedName() {

@Override
public FullyQualified withFullyQualifiedName(String fullyQualifiedName) {
return type.withFullyQualifiedName(fullyQualifiedName);
FullyQualified qualified = type.withFullyQualifiedName(fullyQualifiedName);
if (type == qualified) {
return this;
}

return new Parameterized(managedReference, qualified, typeParameters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ void parameterized(String name) {
assertThat(TypeUtils.toString(type)).isEqualTo(name);
}

@ParameterizedTest
@ValueSource(strings = {
"java.util.List<java.lang.String>",
"java.util.Map<java.lang.String, java.lang.Integer>",
"java.util.List<? extends java.lang.Object>",
"java.util.List<? super java.lang.Integer>",
"java.util.List<java.util.List<? super java.lang.Integer>>",
})
void parameterizedWithModifierShouldNeverHideParametrizedType(String name) {
TemplateParameterParser parser = new TemplateParameterParser(new CommonTokenStream(new TemplateParameterLexer(
CharStreams.fromString(name))));
JavaType type = TypeParameter.toFullyQualifiedName(parser.type());

JavaType.Parameterized pType = (JavaType.Parameterized) type;
assertThat(pType.withFullyQualifiedName("test")).isInstanceOf(JavaType.Parameterized.class);
assertThat(pType.withFullyQualifiedName("test")).isNotSameAs(pType);
assertThat(pType.withFullyQualifiedName(pType.getFullyQualifiedName())).isSameAs(pType);
}

@ParameterizedTest
@ValueSource(strings = {
"java.util.List<?>",
Expand Down

0 comments on commit 41b5d9f

Please sign in to comment.