private async Task AttributeInformationAsync(string source, List <bool> expected) { Document document = CreateDocument(source); SemanticModel semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false); var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false); List <bool> actual = new List <bool>(); var pxContext = new PXContext(semanticModel.Compilation, CodeAnalysisSettings.Default); var properties = syntaxRoot.DescendantNodes().OfType <PropertyDeclarationSyntax>(); foreach (var property in properties) { var typeSymbol = semanticModel.GetDeclaredSymbol(property); var attributes = typeSymbol.GetAttributes(); foreach (var attribute in attributes) { var attributeInformation = new Acuminator.Utilities.Roslyn.PXFieldAttributes.AttributeInformation(pxContext); var defaultAttribute = pxContext.AttributeTypes.PXDefaultAttribute; actual.Add(attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, defaultAttribute)); } } Assert.Equal(expected, actual); }
private async Task IsDBFieldPropertyAsync(string source, List <bool> expected, string[] code = null) { Document document = CreateDocument(source, externalCode: code); SemanticModel semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false); var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false); List <bool> actual = new List <bool>(capacity: expected.Capacity); var pxContext = new PXContext(semanticModel.Compilation, CodeAnalysisSettings.Default); var attributeInformation = new Acuminator.Utilities.Roslyn.PXFieldAttributes.AttributeInformation(pxContext); IEnumerable <PropertyDeclarationSyntax> properties = syntaxRoot.DescendantNodes() .OfType <PropertyDeclarationSyntax>() .Where(a => !a.AttributeLists.IsNullOrEmpty()); foreach (PropertyDeclarationSyntax property in properties) { IPropertySymbol propertySymbol = semanticModel.GetDeclaredSymbol(property); actual.Add((propertySymbol != null)? attributeInformation.ContainsBoundAttributes(propertySymbol.GetAttributes()): false); } actual.Should().BeEquivalentTo(expected); }
private async Task IsBoundAttributeAsync(string source, List <BoundType> expected) { Document document = CreateDocument(source); SemanticModel semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false); var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false); List <BoundType> actual = new List <BoundType>(); var pxContext = new PXContext(semanticModel.Compilation); var properties = syntaxRoot.DescendantNodes().OfType <PropertyDeclarationSyntax>(); var attributeInformation = new Acuminator.Utilities.Roslyn.PXFieldAttributes.AttributeInformation(pxContext); foreach (var property in properties) { var typeSymbol = semanticModel.GetDeclaredSymbol(property); var attributes = typeSymbol.GetAttributes(); foreach (var attribute in attributes) { actual.Add(attributeInformation.IsBoundAttribute(attribute)); } } Assert.Equal(expected, actual); }
private async Task ListOfParentsAsync(string source, List <List <string> > expected, bool expand = false) { Document document = CreateDocument(source); SemanticModel semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false); var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false); var pxContext = new PXContext(semanticModel.Compilation, CodeAnalysisSettings.Default); var expectedSymbols = ConvertStringsToITypeSymbols(expected, semanticModel); var properties = syntaxRoot.DescendantNodes().OfType <PropertyDeclarationSyntax>(); List <HashSet <ITypeSymbol> > result = new List <HashSet <ITypeSymbol> >(); var attributeInformation = new Acuminator.Utilities.Roslyn.PXFieldAttributes.AttributeInformation(pxContext); foreach (var property in properties) { var typeSymbol = semanticModel.GetDeclaredSymbol(property); if (typeSymbol == null) { continue; } var attributes = typeSymbol.GetAttributes(); foreach (var attribute in attributes) { var fullAttributesSet = attributeInformation.GetAcumaticaAttributesFullList(attribute.AttributeClass, expand).ToHashSet(); if (fullAttributesSet.Count > 0) { result.Add(fullAttributesSet); } } } Assert.Equal(expectedSymbols, result); }
public FieldTypeAttributesRegister(PXContext pxContext) { pxContext.ThrowOnNull(nameof(pxContext)); _context = pxContext; _attributeInformation = new AttributeInformation(_context); var unboundFieldAttributes = GetUnboundTypeAttributes(_context); UnboundTypeAttributes = unboundFieldAttributes.ToImmutableHashSet(); var boundFieldAttributes = GetBoundTypeAttributes(_context); BoundTypeAttributes = boundFieldAttributes.ToImmutableHashSet(); var specialAttributes = GetSpecialAttributes(_context); SpecialAttributes = specialAttributes.ToImmutableHashSet(); AllTypeAttributes = unboundFieldAttributes.Concat(boundFieldAttributes) .Concat(specialAttributes) .ToImmutableHashSet(); CorrespondingSimpleTypes = GetCorrespondingSimpleTypes(_context).ToImmutableDictionary(); }