public void InternalFourParameterConstructorSetsAllData() { MemberDeclarationSyntax decl = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(decl.SyntaxTree); SemanticModel semanticModel = compilation.Compilation.GetSemanticModel(decl.SyntaxTree, true); ISymbol symbol = semanticModel.GetDeclaredSymbol(decl) !; Location location = decl.GetLocation(); ITypeData[] containingTypes = symbol.GetContainingTypes(compilation).ToArray(); INamespaceSymbol[] containingNamespaces = symbol.GetContainingNamespaces().ToArray(); ImmutableArray <AttributeData> attributes = symbol.GetAttributes(); Data.MemberData data = new(decl, compilation, symbol, semanticModel, containingTypes, containingNamespaces, attributes); Assert.True( data.SemanticModel is not null && data.SemanticModel.SyntaxTree.IsEquivalentTo(semanticModel.SyntaxTree) && data.Symbol is not null && SymbolEqualityComparer.Default.Equals(data.Symbol, symbol) && data.Location is not null && data.Location == location && data.Declaration is not null && data.Declaration.IsEquivalentTo(decl) && data.ParentCompilation is not null && data.ParentCompilation == compilation && data._containingTypes is not null & data._containingTypes == containingTypes && !data._attributes.IsDefault && data._attributes == attributes && data._containingNamespaces is not null && data._containingNamespaces == containingNamespaces ); }
/// <summary> /// Initializes a new instance of the <see cref="TypeData"/> class. /// </summary> /// <param name="declaration"><see cref="BaseTypeDeclarationSyntax"/> this <see cref="TypeData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="TypeData"/>.</param> /// <param name="symbol"><see cref="INamedTypeSymbol"/> this <see cref="TypeData"/> represents.</param> /// <param name="semanticModel"><see cref="SemanticModel"/> of the <paramref name="declaration"/>.</param> /// <param name="partialDeclarations">A collection of <see cref="TypeDeclarationSyntax"/> that represent the partial declarations of the target <paramref name="symbol"/>.</param> /// <param name="modifiers">A collection of all modifiers applied to the <paramref name="symbol"/>.</param> /// <param name="containingTypes">A collection of <see cref="ITypeData"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="containingNamespaces">A collection of <see cref="INamespaceSymbol"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="attributes">A collection of <see cref="AttributeData"/>s representing the <paramref name="symbol"/> attributes.</param> protected internal TypeData( BaseTypeDeclarationSyntax declaration, ICompilationData compilation, INamedTypeSymbol symbol, SemanticModel semanticModel, IEnumerable <BaseTypeDeclarationSyntax>?partialDeclarations = null, IEnumerable <SyntaxToken>?modifiers = null, IEnumerable <ITypeData>?containingTypes = null, IEnumerable <INamespaceSymbol>?containingNamespaces = null, IEnumerable <AttributeData>?attributes = null ) : base( declaration, compilation, symbol, semanticModel, containingTypes, containingNamespaces, attributes ) { _partialDeclarations = partialDeclarations?.OfType <TypeDeclarationSyntax>().ToArray(); if (modifiers is not null) { _modifiers = modifiers.ToArray(); } }
/// <summary> /// Returns new instance of <see cref="IMemberData"/> associated with the specified <paramref name="member"/>. /// </summary> /// <param name="member"><see cref="MemberDeclarationSyntax"/> to get the data of.</param> /// <param name="compilation">Current <see cref="ICompilationData"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="member"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/>.</exception> public static IMemberData GetMemberData(this MemberDeclarationSyntax member, ICompilationData compilation) { if (member is null) { throw new ArgumentNullException(nameof(member)); } if (compilation is null) { throw new ArgumentNullException(nameof(compilation)); } return(member switch { ClassDeclarationSyntax => new ClassData((ClassDeclarationSyntax)member, compilation), StructDeclarationSyntax => new StructData((StructDeclarationSyntax)member, compilation), InterfaceDeclarationSyntax => new InterfaceData((InterfaceDeclarationSyntax)member, compilation), RecordDeclarationSyntax => new RecordData((RecordDeclarationSyntax)member, compilation), EnumDeclarationSyntax => new EnumData((EnumDeclarationSyntax)member, compilation), BaseTypeDeclarationSyntax => new TypeData((BaseTypeDeclarationSyntax)member, compilation), MethodDeclarationSyntax => new MethodData((MethodDeclarationSyntax)member, compilation), FieldDeclarationSyntax => new FieldData((FieldDeclarationSyntax)member, compilation), PropertyDeclarationSyntax => new PropertyData((PropertyDeclarationSyntax)member, compilation), EventDeclarationSyntax => new EventData((EventDeclarationSyntax)member, compilation), EventFieldDeclarationSyntax => new EventData((EventFieldDeclarationSyntax)member, compilation), DelegateDeclarationSyntax => new DelegateData((DelegateDeclarationSyntax)member, compilation), _ => new MemberData(member, compilation), });
/// <summary> /// Initializes a new instance of the <see cref="FieldData"/> class. /// </summary> /// <param name="declaration"><see cref="FieldDeclarationSyntax"/> this <see cref="FieldData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="FieldData"/>.</param> /// <param name="index">Index of this field in the <paramref name="declaration"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> /// <exception cref="IndexOutOfRangeException"> /// <paramref name="index"/> was out of range. /// </exception> public FieldData(FieldDeclarationSyntax declaration, ICompilationData compilation, int index = 0) : this( declaration, compilation, GetSemanticModel(compilation, declaration), GetVariable(declaration, index)) { Index = index; }
public void ParentCompilationIsProperlySetAfterConstructor() { MemberDeclarationSyntax member = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(member.SyntaxTree); Data.MemberData data = new(member, compilation); Assert.True(data.ParentCompilation is not null && data.ParentCompilation == compilation); }
public void NameReturnsSymbolName() { MemberDeclarationSyntax member = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(member.SyntaxTree); Data.MemberData data = new(member, compilation); Assert.True(data.Symbol is not null && data.Name == data.Symbol.Name); }
public void SemanticModelReturnsValidSemanticModel() { MemberDeclarationSyntax member = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(member.SyntaxTree); SemanticModel semanticModel = compilation.Compilation.GetSemanticModel(member.SyntaxTree, true); Data.MemberData data = new(member, compilation); Assert.True(data.SemanticModel is not null && data.SemanticModel.SyntaxTree.IsEquivalentTo(semanticModel.SyntaxTree)); }
public void SymbolReturnsValidSymbol() { MemberDeclarationSyntax member = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(member.SyntaxTree); SemanticModel semanticModel = compilation.Compilation.GetSemanticModel(member.SyntaxTree, true); ISymbol symbol = semanticModel.GetDeclaredSymbol(member) !; Data.MemberData data = new(member, compilation); Assert.True(data.Symbol is not null && SymbolEqualityComparer.Default.Equals(symbol, data.Symbol)); }
internal MemberData(ISymbol symbol, ICompilationData compilation) { if (symbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is not MemberDeclarationSyntax decl) { throw Exc_NoSyntaxReference(symbol); } Symbol = symbol; Declaration = decl; SemanticModel = compilation.Compilation.GetSemanticModel(decl.SyntaxTree); ParentCompilation = compilation; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyData"/> class. /// </summary> /// <param name="declaration"><see cref="PropertyDeclarationSyntax"/> this <see cref="PropertyData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="PropertyData"/>.</param> /// <param name="symbol"><see cref="IPropertySymbol"/> this <see cref="PropertyData"/> represents.</param> /// <param name="semanticModel"><see cref="SemanticModel"/> of the <paramref name="declaration"/>.</param> /// <param name="containingTypes">A collection of <see cref="ITypeData"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="containingNamespaces">A collection of <see cref="INamespaceSymbol"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="attributes">A collection of <see cref="AttributeData"/>s representing the <paramref name="symbol"/> attributes.</param> protected internal PropertyData( PropertyDeclarationSyntax declaration, ICompilationData compilation, IPropertySymbol symbol, SemanticModel semanticModel, IEnumerable <ITypeData>?containingTypes = null, IEnumerable <INamespaceSymbol>?containingNamespaces = null, IEnumerable <AttributeData>?attributes = null ) : base( declaration, compilation, symbol, semanticModel, containingTypes, containingNamespaces, attributes ) { }
public void InternalTwoParameterConstructorSetsAllData() { MemberDeclarationSyntax decl = CreateValidDeclaration(); ICompilationData compilation = CreateValidCompilationData(decl.SyntaxTree); SemanticModel semanticModel = compilation.Compilation.GetSemanticModel(decl.SyntaxTree, true); ISymbol symbol = semanticModel.GetDeclaredSymbol(decl) !; Location location = decl.GetLocation(); Data.MemberData data = new(symbol, compilation); Assert.True( data.SemanticModel is not null && data.SemanticModel.SyntaxTree.IsEquivalentTo(semanticModel.SyntaxTree) && data.Symbol is not null && SymbolEqualityComparer.Default.Equals(data.Symbol, symbol) && data.Location is not null && data.Location == location && data.Declaration is not null && data.Declaration.IsEquivalentTo(decl) && data.ParentCompilation is not null && data.ParentCompilation == compilation ); }
/// <summary> /// Initializes a new instance of the <see cref="MemberData"/> class. /// </summary> /// <param name="declaration"><see cref="MemberDeclarationSyntax"/> this <see cref="MemberData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="MemberData"/>.</param> /// <param name="symbol"><see cref="ISymbol"/> this <see cref="MemberData"/> represents.</param> /// <param name="semanticModel"><see cref="SemanticModel"/> of the <paramref name="declaration"/>.</param> /// <param name="containingTypes">A collection of <see cref="ITypeData"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="containingNamespaces">A collection of <see cref="INamespaceSymbol"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="attributes">A collection of <see cref="AttributeData"/>s representing the <paramref name="symbol"/> attributes.</param> protected internal MemberData( MemberDeclarationSyntax declaration, ICompilationData compilation, ISymbol symbol, SemanticModel semanticModel, IEnumerable <ITypeData>?containingTypes = null, IEnumerable <INamespaceSymbol>?containingNamespaces = null, IEnumerable <AttributeData>?attributes = null ) { Declaration = declaration; ParentCompilation = compilation; Symbol = symbol; SemanticModel = semanticModel; _containingTypes = containingTypes?.ToArray(); _containingNamespaces = containingNamespaces?.ToArray(); if (attributes is not null) { _attributes = attributes.ToImmutableArray(); } }
/// <summary> /// Initializes a new instance of the <see cref="EnumData"/> class. /// </summary> /// <param name="declaration"><see cref="EnumDeclarationSyntax"/> this <see cref="EnumData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="EnumData"/>.</param> /// <param name="symbol"><see cref="INamedTypeSymbol"/> this <see cref="EnumData"/> represents.</param> /// <param name="semanticModel"><see cref="SemanticModel"/> of the <paramref name="declaration"/>.</param> /// <param name="modifiers">A collection of all modifiers applied to the <paramref name="symbol"/>.</param> /// <param name="containingTypes">A collection of <see cref="ITypeData"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="containingNamespaces">A collection of <see cref="INamespaceSymbol"/>s the <paramref name="symbol"/> is contained within.</param> /// <param name="attributes">A collection of <see cref="AttributeData"/>s representing the <paramref name="symbol"/> attributes.</param> protected internal EnumData( EnumDeclarationSyntax declaration, ICompilationData compilation, INamedTypeSymbol symbol, SemanticModel semanticModel, IEnumerable <SyntaxToken>?modifiers = null, IEnumerable <ITypeData>?containingTypes = null, IEnumerable <INamespaceSymbol>?containingNamespaces = null, IEnumerable <AttributeData>?attributes = null ) : base( declaration, compilation, symbol, semanticModel, null, modifiers, containingTypes, containingNamespaces, attributes ) { }
internal PropertyData(IPropertySymbol symbol, ICompilationData compilation) : base(symbol, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="PropertyData"/> class. /// </summary> /// <param name="declaration"><see cref="PropertyDeclarationSyntax"/> this <see cref="PropertyData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="PropertyData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public PropertyData(PropertyDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
internal DelegateData(INamedTypeSymbol symbol, ICompilationData compilation) : base(symbol, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="DelegateData"/> class. /// </summary> /// <param name="declaration"><see cref="DelegateDeclarationSyntax"/> this <see cref="DelegateData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="DelegateData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public DelegateData(DelegateDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
internal StructData(INamedTypeSymbol symbol, ICompilationData compilation) : base(symbol, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="StructData"/> class. /// </summary> /// <param name="declaration"><see cref="StructDeclarationSyntax"/> this <see cref="StructData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="StructData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public StructData(StructDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
internal ClassData(INamedTypeSymbol symbol, ICompilationData compilation) : base(symbol, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="EnumData"/> class. /// </summary> /// <param name="declaration"><see cref="EnumDeclarationSyntax"/> this <see cref="EnumData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="EnumData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public EnumData(EnumDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="ClassData"/> class. /// </summary> /// <param name="declaration"><see cref="ClassDeclarationSyntax"/> this <see cref="ClassData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="ClassData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public ClassData(ClassDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="TypeData{TDeclaration}"/> class. /// </summary> /// <param name="declaration"><see cref="TypeDeclarationSyntax"/> this <see cref="TypeData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="TypeData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public TypeData(TDeclaration declaration, ICompilationData compilation) : base(declaration, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="RecordData"/> class. /// </summary> /// <param name="declaration"><see cref="RecordDeclarationSyntax"/> this <see cref="RecordData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="RecordData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public RecordData(RecordDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
internal RecordData(INamedTypeSymbol symbol, ICompilationData compilation) : base(symbol, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="FieldData"/> class. /// </summary> /// <param name="symbol"><see cref="IFieldSymbol"/> this <see cref="FieldData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="FieldData"/>.</param> internal FieldData(IFieldSymbol symbol, ICompilationData compilation) : base( GetFieldDeclarationFromSymbol( symbol, compilation, out SemanticModel semanticModel,
/// <summary> /// Initializes a new instance of the <see cref="MemberData"/> class. /// </summary> /// <param name="declaration"><see cref="MemberDeclarationSyntax"/> this <see cref="MemberData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="MemberData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// Specified <paramref name="declaration"/> doesn't represent any symbols. /// </exception> public MemberData(MemberDeclarationSyntax declaration, ICompilationData compilation) { (SemanticModel, Symbol) = AnalysisUtilities.GetSymbolAndSemanticModel(declaration, compilation); Declaration = declaration; ParentCompilation = compilation; }
/// <summary> /// Initializes a new instance of the <see cref="EventData"/> class. /// </summary> /// <param name="declaration"><see cref="EventDeclarationSyntax"/> this <see cref="DelegateData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="DelegateData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public EventData(EventDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }
/// <summary> /// Initializes a new instance of the <see cref="EventData"/> class. /// </summary> /// <param name="symbol"><see cref="IEventSymbol"/> this <see cref="EventData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="EventData"/>.</param> internal EventData(IEventSymbol symbol, ICompilationData compilation) : base( GetFieldOrProperty( symbol, compilation, out SemanticModel semanticModel,
/// <summary> /// Initializes a new instance of the <see cref="TypeData"/> class. /// </summary> /// <param name="declaration"><see cref="BaseTypeDeclarationSyntax"/> this <see cref="TypeData"/> represents.</param> /// <param name="compilation">Parent <see cref="ICompilationData"/> of this <see cref="TypeData"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="declaration"/> is <see langword="null"/>. -or- <paramref name="compilation"/> is <see langword="null"/> /// </exception> public TypeData(BaseTypeDeclarationSyntax declaration, ICompilationData compilation) : base(declaration, compilation) { }