@@ -34,69 +34,6 @@ public static bool IsMemberEligibleForTranspile(this IFieldDeclaration field, IS
3434 }
3535
3636
37- /// <summary>
38- /// Finds type declaration.
39- /// </summary>
40- /// <param name="compilation">Compilation object</param>
41- /// <param name="typeAccess">Required type</param>
42- /// <returns>Required type if found.</returns>
43- public static ITypeDeclaration FindTypeDeclaration ( this Compilation compilation , AX . ST . Semantic . Model . ISemanticTypeAccess ? typeAccess )
44- {
45- // This is to resolve fully qualified type name when the type cannot be determined propeprly form the semantic tree.
46- // TODO: This workaround should be removed once we can properly use project dependencies in the stc.
47- if ( typeAccess == null )
48- {
49- return null ;
50- }
51-
52- var fullyQualified = compilation . GetSemanticTree ( ) . Types . DistinctBy ( p => p . FullyQualifiedName ) . Where ( p => p . FullyQualifiedName == typeAccess . Type . FullyQualifiedName ) . FirstOrDefault ( ) ;
53-
54- if ( fullyQualified != null )
55- {
56- return fullyQualified ;
57- }
58-
59- var candidates = compilation . GetSemanticTree ( ) . Types . DistinctBy ( p => p . FullyQualifiedName ) . Where ( p => p . Name == typeAccess . TypeSymbol . Name ) ;
60- if ( candidates . Count ( ) == 1 )
61- {
62- return candidates . First ( ) ;
63- }
64-
65- if ( candidates . Count ( ) == 0 )
66- {
67- Log . Logger . Warning ( $ "Type '{ typeAccess ? . ToString ( ) } ' not found in the semantic tree.") ;
68- }
69-
70- if ( candidates . Count ( ) > 1 )
71- {
72- Log . Logger . Warning ( $ "Multiple types found for '{ typeAccess ? . ToString ( ) } ' in the semantic tree. You may need to fully qualify the declaration.") ;
73- }
74-
75- return null ;
76- }
77-
78- /// <summary>
79- /// Determines fully qualified name of the declaration.
80- /// </summary>
81- /// <param name="declaration">Field declaration</param>
82- /// <param name="compilation">Compilation object.</param>
83- /// <returns>Fully qualified name of the declaration.</returns>
84- public static string ? DetermineFullyQualifiedName ( this IFieldDeclaration declaration , Compilation compilation )
85- {
86- return compilation . FindTypeDeclaration ( declaration . TypeAccess ) ? . FullyQualifiedName ;
87- }
88-
89- /// <summary>
90- /// Determines fully qualified name of the declaration.
91- /// </summary>
92- /// <param name="declaration">Variable declaration</param>
93- /// <param name="compilation">Compilation object.</param>
94- /// <returns>Fully qualified name of the declaration.</returns>
95- public static string ? DetermineFullyQualifiedName ( this IVariableDeclaration declaration , Compilation compilation )
96- {
97- return compilation . FindTypeDeclaration ( declaration . TypeAccess ) ? . FullyQualifiedName ;
98- }
99-
10037 private static bool IsToBeOmitted ( this IStorageDeclaration fieldDeclaration , ISourceBuilder sourceBuilder , string coBuilder )
10138 {
10239
@@ -152,7 +89,8 @@ public static bool IsEligibleForTranspile(this IFieldDeclaration fieldDeclaratio
15289 type is IStringTypeDeclaration ||
15390 type is IStructuredTypeDeclaration ||
15491 type is INamedValueTypeDeclaration ||
155- sourceBuilder . Compilation . FindTypeDeclaration ( fieldDeclaration . TypeAccess ) != null ) ;
92+ sourceBuilder . Compilation . GetSemanticTree ( ) . Types . Any ( p =>
93+ p . FullyQualifiedName == type . FullyQualifiedName ) ) ;
15694
15795 if ( ! isEligible )
15896 {
@@ -179,7 +117,8 @@ public static bool IsEligibleForTranspile(this IVariableDeclaration variableDecl
179117 type is IStringTypeDeclaration ||
180118 type is IStructuredTypeDeclaration ||
181119 type is INamedValueTypeDeclaration ||
182- sourceBuilder . Compilation . FindTypeDeclaration ( variableDeclaration . TypeAccess ) != null ) ;
120+ sourceBuilder . Compilation . GetSemanticTree ( ) . Types . Any ( p =>
121+ p . FullyQualifiedName == type . FullyQualifiedName ) ) ;
183122
184123 if ( ! isEligible )
185124 {
@@ -208,7 +147,8 @@ public static bool IsEligibleForTranspile(this IArrayTypeDeclaration arrayTypeDe
208147 arrayTypeDeclaration . ElementTypeAccess . Type is IStringTypeDeclaration ||
209148 arrayTypeDeclaration . ElementTypeAccess . Type is IStructuredTypeDeclaration ||
210149 arrayTypeDeclaration . ElementTypeAccess . Type is INamedValueTypeDeclaration ||
211- sourceBuilder . Compilation . FindTypeDeclaration ( arrayTypeDeclaration . ElementTypeAccess ) != null ) ;
150+ sourceBuilder . Compilation . GetSemanticTree ( ) . Types . Any ( p =>
151+ p . FullyQualifiedName == arrayTypeDeclaration . ElementTypeAccess . Type . FullyQualifiedName ) ) ;
212152
213153 return isEligibleType && singleDimensionalArray ;
214154
0 commit comments