Skip to content

Commit

Permalink
Merge pull request #15526 from Youssef1313/xaml-gen-misc-cleanup
Browse files Browse the repository at this point in the history
refactor: Small cleanup to xaml generator
  • Loading branch information
jeromelaban authored Mar 4, 2024
2 parents 5aa0244 + 0a4a509 commit e3f64bd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static IEnumerable<INamedTypeSymbol> GetAllInterfaces(this ITypeSymbol? s
}
}

public static ISymbol? GetMemberInlcudingBaseTypes(this INamespaceOrTypeSymbol symbol, string memberName)
public static ISymbol? GetMemberIncludingBaseTypes(this INamespaceOrTypeSymbol symbol, string memberName)
{
if (symbol is INamespaceSymbol)
{
Expand All @@ -286,15 +286,15 @@ public static IEnumerable<INamedTypeSymbol> GetAllInterfaces(this ITypeSymbol? s
return null;
}

public static ISymbol? GetMemberInlcudingBaseTypes<TArg>(this INamespaceOrTypeSymbol symbol, TArg arg, Func<ISymbol, TArg, bool> predicate)
public static ISymbol? GetMemberIncludingBaseTypes<TArg>(this INamespaceOrTypeSymbol symbol, TArg arg, Func<ISymbol, TArg, bool> predicate)
{
if (symbol is INamespaceSymbol)
{
foreach (var candicate in symbol.GetMembers())
foreach (var candidate in symbol.GetMembers())
{
if (predicate(candicate, arg))
if (predicate(candidate, arg))
{
return candicate;
return candidate;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public override void VisitElementAccessExpression(ElementAccessExpressionSyntax
var expectedIndexerParameterType = index is LiteralExpressionSyntax indexLiteral && indexLiteral.IsKind(SyntaxKind.StringLiteralExpression)
? SpecialType.System_String
: SpecialType.System_Int32;
var indexer = lastType.GetMemberInlcudingBaseTypes(expectedIndexerParameterType, (m, arg) => m is IPropertySymbol { IsIndexer: true } p && p.Parameters[0].Type.SpecialType == arg);
var indexer = lastType.GetMemberIncludingBaseTypes(expectedIndexerParameterType, (m, arg) => m is IPropertySymbol { IsIndexer: true } p && p.Parameters[0].Type.SpecialType == arg);
if (indexer is not null)
{
_lastAccessed = (indexer, IsTopLevelContext: false);
Expand Down Expand Up @@ -424,7 +424,7 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
_ => throw new Exception($"Unexpected _lastAccessed symbol '{_lastAccessed.Symbol?.Kind}'."),
};

var member = previousType.GetMemberInlcudingBaseTypes(node.Identifier.ValueText);
var member = previousType.GetMemberIncludingBaseTypes(node.Identifier.ValueText);
if (member is null)
{
Failed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal partial class XamlCodeGeneration
private readonly string _projectFullPath;
private readonly bool _xamlResourcesTrimming;
private readonly bool _isUnoHead;
private bool _shouldWriteErrorOnInvalidXaml;
private readonly bool _shouldWriteErrorOnInvalidXaml;
private readonly RoslynMetadataHelper _metadataHelper;

/// <summary>
Expand Down Expand Up @@ -441,7 +441,6 @@ public List<KeyValuePair<string, SourceText>> Generate()
defaultLanguage: _defaultLanguage,
shouldWriteErrorOnInvalidXaml: _shouldWriteErrorOnInvalidXaml,
isWasm: _isWasm,
isDebug: _isDebug,
isHotReloadEnabled: _isHotReloadEnabled,
isInsideMainAssembly: isInsideMainAssembly,
isDesignTimeBuild: _isDesignTimeBuild,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ private INamedTypeSymbol GetType(XamlType type)
private static string GetTrimmedNamespace(string nsNamespace)
{
var nsName = nsNamespace.TrimStart("using:");

if (nsName.StartsWith("clr-namespace:", StringComparison.Ordinal))
{
nsName = nsName.Split(';')[0].TrimStart("clr-namespace:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ internal partial class XamlFileGenerator
private readonly bool _isUiAutomationMappingEnabled;
private readonly Dictionary<string, string[]> _uiAutomationMappings;
private readonly string _defaultLanguage;
private readonly bool _isDebug;
private readonly bool _isHotReloadEnabled;
private readonly bool _isInsideMainAssembly;
private readonly bool _isDesignTimeBuild;
Expand Down Expand Up @@ -198,7 +197,6 @@ public XamlFileGenerator(
string defaultLanguage,
bool shouldWriteErrorOnInvalidXaml,
bool isWasm,
bool isDebug,
bool isHotReloadEnabled,
bool isDesignTimeBuild,
bool isInsideMainAssembly,
Expand All @@ -224,7 +222,6 @@ public XamlFileGenerator(
_isUiAutomationMappingEnabled = isUiAutomationMappingEnabled;
_uiAutomationMappings = uiAutomationMappings;
_defaultLanguage = defaultLanguage.IsNullOrEmpty() ? "en-US" : defaultLanguage;
_isDebug = isDebug;
_isHotReloadEnabled = isHotReloadEnabled;
_isInsideMainAssembly = isInsideMainAssembly;
_isDesignTimeBuild = isDesignTimeBuild;
Expand Down Expand Up @@ -2172,8 +2169,8 @@ private bool HasDescendantsWith(XamlObjectDefinition xamlObjectDefinition, Func<
INamedTypeSymbol? findType;
if (ns != xamlType.PreferredXamlNamespace)
{
// If GetTrimmedNamespace returned a different string, it's either a "using:"-prefixed
// or "clr-namespace:"-prefixed namespace. In those cases, we'll have `baseTypeString` as
// If GetTrimmedNamespace returned a different string, it's a "using:"-prefixed namespace.
// In this case, we'll have `baseTypeString` as
// the fully qualified type name.
// In this case, we go through this code path as it's much more efficient than FindType.
var baseTypeString = $"{ns}.{xamlType.Name}";
Expand Down

0 comments on commit e3f64bd

Please sign in to comment.