@@ -726,11 +726,33 @@ class AstCreator(filename: String, javaParserAst: CompilationUnit, global: Globa
726726 private def astForFieldVariable (v : VariableDeclarator , fieldDeclaration : FieldDeclaration ): Ast = {
727727 // TODO: Should be able to find expected type here
728728 val annotations = fieldDeclaration.getAnnotations
729- val typeFullName =
730- typeInfoCalc
731- .fullName(v.getType)
732- .orElse(scopeStack.lookupVariableType(v.getTypeAsString, wildcardFallback = true ))
733- .getOrElse(s " ${Defines .UnresolvedNamespace }. ${v.getTypeAsString}" )
729+
730+ // variable can be declared with generic type, so we need to get rid of the <> part of it to get the package information
731+ // and append the <> when forming the typeFullName again
732+ // Ex - private Consumer<String, Integer> consumer;
733+ // From Consumer<String, Integer> we need to get to Consumer so splitting it by '<' and then combining with '<' to
734+ // form typeFullName as Consumer<String, Integer>
735+
736+ val typeFullNameWithoutGenericSplit = typeInfoCalc
737+ .fullName(v.getType)
738+ .orElse(scopeStack.lookupVariableType(v.getTypeAsString, wildcardFallback = true ))
739+ .getOrElse(s " ${Defines .UnresolvedNamespace }. ${v.getTypeAsString}" )
740+ val typeFullName = {
741+ // Check if the typeFullName is unresolved and if it has generic information to resolve the typeFullName
742+ if (
743+ typeFullNameWithoutGenericSplit
744+ .contains(Defines .UnresolvedNamespace ) && v.getTypeAsString.contains(Defines .LeftAngularBracket )
745+ ) {
746+ val splitByLeftAngular = v.getTypeAsString.split(Defines .LeftAngularBracket )
747+ scopeStack.lookupVariableType(splitByLeftAngular.head, wildcardFallback = true ) match {
748+ case Some (fullName) =>
749+ fullName + splitByLeftAngular
750+ .slice(1 , splitByLeftAngular.size)
751+ .mkString(Defines .LeftAngularBracket , Defines .LeftAngularBracket , " " )
752+ case None => typeFullNameWithoutGenericSplit
753+ }
754+ } else typeFullNameWithoutGenericSplit
755+ }
734756 val name = v.getName.toString
735757 val node = memberNode(v, name, s " $typeFullName $name" , typeFullName)
736758 val memberAst = Ast (node)
0 commit comments