Skip to content

Commit

Permalink
Merge pull request #1271 from mlichtblau/master
Browse files Browse the repository at this point in the history
Fix isGenerified to work with anonymous subclasses using the enclosing methods type parameter
  • Loading branch information
raphw committed Jun 22, 2022
2 parents 2cdedb9 + 3979f55 commit 2b3ee03
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Expand Up @@ -88,6 +88,7 @@ public interface TypeVariableSource extends ModifierReviewable.OfAbstraction {
* <ul>
* <li>A type declares type variables or is an inner class of a type with a generic declaration.</li>
* <li>A method declares at least one type variable.</li>
* <li>A type is an inner anonymous class of a method with a generic declaration</li>
* </ul>
*
* @return {@code true} if this type code element has a generic declaration.
Expand Down
Expand Up @@ -8060,7 +8060,11 @@ public boolean isGenerified() {
return false;
}
TypeDescription declaringType = getDeclaringType();
return declaringType != null && declaringType.isGenerified();
if (declaringType != null && declaringType.isGenerified()) {
return true;
}
MethodDescription.InDefinedShape enclosingMethod = getEnclosingMethod();
return enclosingMethod != null && enclosingMethod.isGenerified();
}

/**
Expand Down
Expand Up @@ -666,6 +666,7 @@ public void testIsGenerified() throws Exception {
assertThat(describe(GenericSample.Nested.class).isGenerified(), is(false));
assertThat(describe(GenericSample.NestedInterface.class).isGenerified(), is(false));
assertThat(describe(Object.class).isGenerified(), is(false));
assertThat(describe(getAnonymousGenericSample().getClass()).isGenerified(), is(true));
}

@Test
Expand Down Expand Up @@ -1034,6 +1035,12 @@ interface NestedInterface {
}
}

private <T> GenericSample<T> getAnonymousGenericSample() {
return new GenericSample<T>() {
/* empty */
};
}

private static class Type$With$Dollar {
/* */
}
Expand Down

0 comments on commit 2b3ee03

Please sign in to comment.