Added HasIndexer property to BoundAttributeDescriptor

This commit is contained in:
Ajay Bhargav Baaskaran 2017-03-21 12:06:22 -07:00
parent 9aa4048866
commit c6a35e7b26
4 changed files with 57 additions and 17 deletions

View File

@ -27,12 +27,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public string Name { get; protected set; } public string Name { get; protected set; }
public string IndexerNamePrefix { get; set; } public string IndexerNamePrefix { get; protected set; }
public string TypeName { get; protected set; } public string TypeName { get; protected set; }
public string IndexerTypeName { get; protected set; } public string IndexerTypeName { get; protected set; }
public bool HasIndexer { get; protected set; }
public string Documentation { get; protected set; } public string Documentation { get; protected set; }
public string DisplayName { get; protected set; } public string DisplayName { get; protected set; }

View File

@ -54,6 +54,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
string.Equals(descriptorX.Kind, descriptorY.Kind, StringComparison.Ordinal) && string.Equals(descriptorX.Kind, descriptorY.Kind, StringComparison.Ordinal) &&
descriptorX.IsIndexerStringProperty == descriptorY.IsIndexerStringProperty && descriptorX.IsIndexerStringProperty == descriptorY.IsIndexerStringProperty &&
descriptorX.IsEnum == descriptorY.IsEnum && descriptorX.IsEnum == descriptorY.IsEnum &&
descriptorX.HasIndexer == descriptorY.HasIndexer &&
string.Equals(descriptorX.Name, descriptorY.Name, _stringComparison) && string.Equals(descriptorX.Name, descriptorY.Name, _stringComparison) &&
string.Equals(descriptorX.IndexerNamePrefix, descriptorY.IndexerNamePrefix, _stringComparison) && string.Equals(descriptorX.IndexerNamePrefix, descriptorY.IndexerNamePrefix, _stringComparison) &&
string.Equals(descriptorX.TypeName, descriptorY.TypeName, StringComparison.Ordinal) && string.Equals(descriptorX.TypeName, descriptorY.TypeName, StringComparison.Ordinal) &&
@ -77,6 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
hashCodeCombiner.Add(descriptor.Kind); hashCodeCombiner.Add(descriptor.Kind);
hashCodeCombiner.Add(descriptor.IsIndexerStringProperty); hashCodeCombiner.Add(descriptor.IsIndexerStringProperty);
hashCodeCombiner.Add(descriptor.IsEnum); hashCodeCombiner.Add(descriptor.IsEnum);
hashCodeCombiner.Add(descriptor.HasIndexer);
hashCodeCombiner.Add(descriptor.Name, _stringComparer); hashCodeCombiner.Add(descriptor.Name, _stringComparer);
hashCodeCombiner.Add(descriptor.IndexerNamePrefix, _stringComparer); hashCodeCombiner.Add(descriptor.IndexerNamePrefix, _stringComparer);
hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal); hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal);

View File

@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
new[] { '@', '!', '<', '/', '?', '[', '>', ']', '=', '"', '\'', '*' }); new[] { '@', '!', '<', '/', '?', '[', '>', ']', '=', '"', '\'', '*' });
private bool _isEnum; private bool _isEnum;
private bool _hasIndexer;
private string _indexerValueTypeName; private string _indexerValueTypeName;
private string _name; private string _name;
private string _propertyName; private string _propertyName;
@ -88,6 +89,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{ {
_indexerNamePrefix = attributeNamePrefix; _indexerNamePrefix = attributeNamePrefix;
_indexerValueTypeName = valueTypeName; _indexerValueTypeName = valueTypeName;
_hasIndexer = true;
return this; return this;
} }
@ -136,6 +138,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
_typeName, _typeName,
_indexerNamePrefix, _indexerNamePrefix,
_indexerValueTypeName, _indexerValueTypeName,
_hasIndexer,
_documentation, _documentation,
displayName, displayName,
_metadata, _metadata,
@ -256,6 +259,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
string typeName, string typeName,
string dictionaryAttributeNamePrefix, string dictionaryAttributeNamePrefix,
string dictionaryValueTypeName, string dictionaryValueTypeName,
bool hasIndexer,
string documentation, string documentation,
string displayName, string displayName,
Dictionary<string, string> metadata, Dictionary<string, string> metadata,
@ -268,6 +272,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
TypeName = typeName; TypeName = typeName;
IndexerNamePrefix = dictionaryAttributeNamePrefix; IndexerNamePrefix = dictionaryAttributeNamePrefix;
IndexerTypeName = dictionaryValueTypeName; IndexerTypeName = dictionaryValueTypeName;
HasIndexer = hasIndexer;
Documentation = documentation; Documentation = documentation;
DisplayName = displayName; DisplayName = displayName;
Diagnostics = new List<RazorDiagnostic>(diagnostics); Diagnostics = new List<RazorDiagnostic>(diagnostics);

View File

@ -1732,8 +1732,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
var dictionaryNamespace = typeof(IDictionary<,>).FullName; var dictionaryNamespace = typeof(IDictionary<,>).FullName;
dictionaryNamespace = dictionaryNamespace.Substring(0, dictionaryNamespace.IndexOf('`')); dictionaryNamespace = dictionaryNamespace.Substring(0, dictionaryNamespace.IndexOf('`'));
// tagTelperType, expectedAttributeDescriptors // tagHelperType, expectedAttributeDescriptors, expectedDiagnostics
return new TheoryData<Type, IEnumerable<BoundAttributeDescriptor>> return new TheoryData<Type, IEnumerable<BoundAttributeDescriptor>, IEnumerable<RazorDiagnostic>>
{ {
{ {
typeof(DefaultValidHtmlAttributePrefix), typeof(DefaultValidHtmlAttributePrefix),
@ -1745,7 +1745,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>") .TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("dictionary-property-", typeof(string).FullName) .AsDictionary("dictionary-property-", typeof(string).FullName)
.Build() .Build()
} },
Enumerable.Empty<RazorDiagnostic>()
}, },
{ {
typeof(SingleValidHtmlAttributePrefix), typeof(SingleValidHtmlAttributePrefix),
@ -1757,7 +1758,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>") .TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("valid-name-", typeof(string).FullName) .AsDictionary("valid-name-", typeof(string).FullName)
.Build() .Build()
} },
Enumerable.Empty<RazorDiagnostic>()
}, },
{ {
typeof(MultipleValidHtmlAttributePrefix), typeof(MultipleValidHtmlAttributePrefix),
@ -1808,7 +1810,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>") .TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("valid-prefix6", typeof(string).FullName) .AsDictionary("valid-prefix6", typeof(string).FullName)
.Build() .Build()
} },
Enumerable.Empty<RazorDiagnostic>()
}, },
{ {
typeof(SingleInvalidHtmlAttributePrefix), typeof(SingleInvalidHtmlAttributePrefix),
@ -1818,11 +1821,16 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.Name("valid-name") .Name("valid-name")
.PropertyName(nameof(SingleInvalidHtmlAttributePrefix.StringProperty)) .PropertyName(nameof(SingleInvalidHtmlAttributePrefix.StringProperty))
.TypeName(typeof(string).FullName) .TypeName(typeof(string).FullName)
.AddDiagnostic( .AddDiagnostic(RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( typeof(SingleInvalidHtmlAttributePrefix).FullName,
typeof(SingleInvalidHtmlAttributePrefix).FullName, nameof(SingleInvalidHtmlAttributePrefix.StringProperty)))
nameof(SingleInvalidHtmlAttributePrefix.StringProperty)))
.Build(), .Build(),
},
new[]
{
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(SingleInvalidHtmlAttributePrefix).FullName,
nameof(SingleInvalidHtmlAttributePrefix.StringProperty))
} }
}, },
{ {
@ -1841,7 +1849,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix2-", typeof(string).FullName) .AsDictionary("valid-prefix2-", typeof(string).FullName)
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntProperty))) nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntProperty)))
.Build(), .Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName) ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1850,7 +1858,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{typeof(IReadOnlyDictionary<,>).Namespace}.IReadOnlyDictionary<System.String, System.Object>") .TypeName($"{typeof(IReadOnlyDictionary<,>).Namespace}.IReadOnlyDictionary<System.String, System.Object>")
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.ReadOnlyDictionaryProperty))) nameof(MultipleInvalidHtmlAttributePrefix.ReadOnlyDictionaryProperty)))
.Build(), .Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName) ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1859,7 +1867,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName(typeof(int).FullName) .TypeName(typeof(int).FullName)
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.IntProperty))) nameof(MultipleInvalidHtmlAttributePrefix.IntProperty)))
.Build(), .Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName) ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1869,7 +1877,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix5-", typeof(string).FullName) .AsDictionary("valid-prefix5-", typeof(string).FullName)
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntSubclassProperty))) nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntSubclassProperty)))
.Build(), .Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName) ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1878,7 +1886,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix6", typeof(string).FullName) .AsDictionary("valid-prefix6", typeof(string).FullName)
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryAttributePrefix))) nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryAttributePrefix)))
.Build(), .Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName) ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1887,9 +1895,30 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("invalid-name7-", typeof(object).FullName) .AsDictionary("invalid-name7-", typeof(object).FullName)
.AddDiagnostic( .AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNull( RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName, typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryPropertyWithAttributeName))) nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryPropertyWithAttributeName)))
.Build(), .Build(),
},
new[]
{
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.ReadOnlyDictionaryProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.IntProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntSubclassProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryAttributePrefix)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryPropertyWithAttributeName)),
} }
}, },
}; };
@ -1900,7 +1929,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
[MemberData(nameof(TagHelperWithPrefixData))] [MemberData(nameof(TagHelperWithPrefixData))]
public void CreateDescriptor_WithPrefixes_ReturnsExpectedAttributeDescriptors( public void CreateDescriptor_WithPrefixes_ReturnsExpectedAttributeDescriptors(
Type tagHelperType, Type tagHelperType,
IEnumerable<BoundAttributeDescriptor> expectedAttributeDescriptors) IEnumerable<BoundAttributeDescriptor> expectedAttributeDescriptors,
IEnumerable<RazorDiagnostic> expectedDiagnostics)
{ {
// Arrange // Arrange
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false); var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
@ -1914,6 +1944,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
expectedAttributeDescriptors, expectedAttributeDescriptors,
descriptor.BoundAttributes, descriptor.BoundAttributes,
BoundAttributeDescriptorComparer.CaseSensitive); BoundAttributeDescriptorComparer.CaseSensitive);
Assert.Equal(expectedDiagnostics, descriptor.GetAllDiagnostics());
} }
public static TheoryData HtmlConversionData public static TheoryData HtmlConversionData