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

Don't resolve parameterized types for RAW_TYPES mode #1604

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,14 @@ abstract class Substitutor implements Visitor<Generic> {
*/
public Generic onParameterizedType(Generic parameterizedType) {
Generic ownerType = parameterizedType.getOwnerType();
List<Generic> typeArguments = new ArrayList<Generic>(parameterizedType.getTypeArguments().size());
for (Generic typeArgument : parameterizedType.getTypeArguments()) {
typeArguments.add(typeArgument.accept(this));
List<Generic> typeArguments;
if (TypeDescription.AbstractBase.RAW_TYPES) {
typeArguments = Collections.emptyList();
} else {
typeArguments = new ArrayList<>(parameterizedType.getTypeArguments().size());
for (Generic typeArgument : parameterizedType.getTypeArguments()) {
typeArguments.add(typeArgument.accept(this));
}
}
return new OfParameterizedType.Latent(parameterizedType.asRawType().accept(this).asErasure(),
ownerType == null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.bytebuddy.description.type;

import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

public class TypeDescriptionGenericVisitorSubstitutorForTypeVariableBindingWithRawTypesTest {

@Mock
private TypeDescription.Generic visitedType, parameterizedType, rawType;

@Test
@SuppressWarnings("unchecked")
public void testParameterizedTypeWithRawTypes() throws Exception {
System.setProperty(TypeDefinition.RAW_TYPES_PROPERTY, "true");
MockitoAnnotations.initMocks(this);

when(parameterizedType.asRawType()).thenReturn(rawType);
when(rawType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(rawType);
when(parameterizedType.getTypeArguments()).thenReturn(new TypeList.Generic.Explicit(TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(Object.class)));
TypeDescription.Generic result = new TypeDescription.Generic.Visitor.Substitutor.ForTypeVariableBinding(visitedType).onParameterizedType(parameterizedType);

assertThat(result.getTypeArguments(), CoreMatchers.<TypeList.Generic>is(new TypeList.Generic.Explicit()));
}
}
Loading