private Description findShadowedTypes ( Tree tree , List < ? extends TypeParameterTree > typeParameters , VisitorState state ) { Env < AttrContext > env = Enter . instance ( state . context ) . getEnv ( ASTHelpers . getSymbol ( state . findEnclosing ( ClassTree . class ) ) ) ; Symtab symtab = state . getSymtab ( ) ; PackageSymbol javaLang = symtab . enterPackage ( symtab . java_base , Names . instance ( state . context ) . java_lang ) ; Iterable < Symbol > enclosingTypes = typesInEnclosingScope ( env , javaLang ) ; List < Symbol > shadowedTypes = typeParameters . stream ( ) . map ( param -> Iterables . tryFind ( enclosingTypes , sym -> sym . getSimpleName ( ) . equals ( ASTHelpers . getType ( param ) . tsym . getSimpleName ( ) ) ) . orNull ( ) ) . filter ( Objects :: nonNull ) . collect ( ImmutableList . toImmutableList ( ) ) ; if ( shadowedTypes . isEmpty ( ) ) { return Description . NO_MATCH ; } Description . Builder descBuilder = buildDescription ( tree ) ; descBuilder . setMessage ( buildMessage ( shadowedTypes ) ) ; Set < String > visibleNames = Streams . stream ( Iterables . concat ( env . info . getLocalElements ( ) , enclosingTypes ) ) . map ( sym -> sym . getSimpleName ( ) . toString ( ) ) . collect ( ImmutableSet . toImmutableSet ( ) ) ; SuggestedFix . Builder fixBuilder = SuggestedFix . builder ( ) ; shadowedTypes . stream ( ) . filter ( tv -> TypeParameterNamingClassification . classify ( tv . name . toString ( ) ) . isValidName ( ) ) . map ( tv -> TypeParameterShadowing . renameTypeVariable ( TypeParameterShadowing . typeParameterInList ( typeParameters , tv ) , tree , TypeParameterShadowing . replacementTypeVarName ( tv . name , visibleNames ) , state ) ) . forEach ( fixBuilder :: merge ) ; descBuilder . addFix ( fixBuilder . build ( ) ) ; return descBuilder . build ( ) ; }
Iterate through a list of type parameters looking for type names shadowed by any of them .