diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SyntaxTreeRootTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SyntaxTreeRootTests.cs index f6f2c249263768973a345c9e74f39b8d4361cab5..b67f856b94bc07344bfc3ebcd0870dae13d89c23 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SyntaxTreeRootTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SyntaxTreeRootTests.cs @@ -104,7 +104,7 @@ public void SyntaxNodeSyntaxTreeReturnsOriginalSyntaxTree() private void CheckTree(SyntaxTree tree) { -#if false +#if false // https://github.com/dotnet/roslyn/issues/4453 CheckAllMembers( tree, new Dictionary> diff --git a/src/Compilers/Test/Utilities/Core2/CSReflectionBasedKindProvider.cs b/src/Compilers/Test/Utilities/Core2/CSReflectionBasedKindProvider.cs deleted file mode 100644 index b2cba39d487510f564b753d4f813c0b1dacaf42d..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/CSReflectionBasedKindProvider.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class CSReflectionBasedKindProvider : ISyntaxNodeKindProvider - { - private const string CS_DLL = "Microsoft.CodeAnalysis.CSharp.dll"; - private const string CS_KIND_TYPE = "Roslyn.Compilers.CSharp.SyntaxKind"; - private Type _CSKindType; - private readonly string _folder; - - public CSReflectionBasedKindProvider(string folder) - { - _folder = Path.GetFullPath(folder); - GetKindTypes(); - } - - private void GetKindTypes() - { - if (_CSKindType == null) - { - var asm = Assembly.LoadFrom(Path.Combine(_folder, CS_DLL)); - _CSKindType = asm.GetType(CS_KIND_TYPE); - } - } - - private string GetKind(object o) - { - string kind = (string)o.GetType().GetProperty("Kind").GetValue(o, new object[] { }); - return Enum.Parse(_CSKindType, kind).ToString(); - } - - public string Kind(object node) - { - return GetKind(node); - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/CompilerTestUtilities2.csproj b/src/Compilers/Test/Utilities/Core2/CompilerTestUtilities2.csproj index 15a0f4fbde31b19dc7eae8c3de864a362edf6ac0..4b4549d0dc6ce6933fb1b3d8405aba48191eba69 100644 --- a/src/Compilers/Test/Utilities/Core2/CompilerTestUtilities2.csproj +++ b/src/Compilers/Test/Utilities/Core2/CompilerTestUtilities2.csproj @@ -103,13 +103,6 @@ - - AbstractAnalyzerAssemblyLoader.cs - - - SimpleAnalyzerAssemblyLoader.cs - - @@ -124,33 +117,12 @@ - - - - - Form - - - ProgressDialog.cs - - - - - - - - - - - ProgressDialog.cs - - @@ -159,4 +131,4 @@ - + \ No newline at end of file diff --git a/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs b/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs index ad16defb89e7ef79f5a023484187458a41637617..53ac365b565263821fb22f4ef442d8e83139b977 100644 --- a/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs +++ b/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs @@ -27,12 +27,7 @@ public abstract class TestDiagnosticAnalyzer : DiagnosticAnal private static ImmutableArray GetAllEnumValues() { - return ImmutableArray.Empty.AddRange(typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static).Select(f => (T)f.GetRawConstantValue())); - } - - protected static IEnumerable GetAbstractMemberNames(Type abstractType) - { - return abstractType.GetMembers().Where(m => !(m is MethodInfo) || !((MethodInfo)m).IsSpecialName).Select(m => m.Name); + return ImmutableArray.CreateRange(Enum.GetValues(typeof(T)).Cast()); } protected abstract void OnAbstractMember(string abstractMemberName, SyntaxNode node = null, ISymbol symbol = null, [CallerMemberName]string callerName = null); diff --git a/src/Compilers/Test/Utilities/Core2/NodeHelpers.cs b/src/Compilers/Test/Utilities/Core2/NodeHelpers.cs index a18604d4c8e0aabe585d732062d558dbbf42ed79..f54fcf6ed1cf6e97a7a0274a73c1d26498f2387c 100644 --- a/src/Compilers/Test/Utilities/Core2/NodeHelpers.cs +++ b/src/Compilers/Test/Utilities/Core2/NodeHelpers.cs @@ -144,7 +144,7 @@ public static NodeInfo GetNodeInfo(this SyntaxNode node) { var typeObject = node.GetType(); var nodeClassName = typeObject.Name; - var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); + var properties = typeObject.GetTypeInfo().DeclaredProperties; return new NodeInfo(typeObject.Name, ( from p in properties where IsField(p) @@ -155,7 +155,7 @@ public static NodeInfo GetNodeInfo(this SyntaxToken token) { var typeObject = token.GetType(); var nodeClassName = typeObject.Name; - var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); + var properties = typeObject.GetTypeInfo().DeclaredProperties; return new NodeInfo(typeObject.Name, ( from p in properties where IsField(p) @@ -166,7 +166,7 @@ public static NodeInfo GetNodeInfo(this SyntaxTrivia trivia) { var typeObject = trivia.GetType(); var nodeClassName = typeObject.Name; - var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); + var properties = typeObject.GetTypeInfo().DeclaredProperties; return new NodeInfo(typeObject.Name, ( from p in properties where IsField(p) @@ -177,7 +177,18 @@ where IsField(p) private static bool IsField(PropertyInfo prop) { var typeObject = prop.PropertyType; - if (typeObject == typeof(int) || typeObject == typeof(uint) || typeObject == typeof(long) || typeObject == typeof(ulong) || typeObject == typeof(bool) || typeObject == typeof(string) || typeObject == typeof(float) || typeObject == typeof(double) || typeObject == typeof(char) || typeObject == typeof(DateTime) || typeObject == typeof(decimal) || typeObject.IsEnum) + if (typeObject == typeof(int) || + typeObject == typeof(uint) || + typeObject == typeof(long) || + typeObject == typeof(ulong) || + typeObject == typeof(bool) || + typeObject == typeof(string) || + typeObject == typeof(float) || + typeObject == typeof(double) || + typeObject == typeof(char) || + typeObject == typeof(DateTime) || + typeObject == typeof(decimal) || + typeObject.GetTypeInfo().IsEnum) { return true; } diff --git a/src/Compilers/Test/Utilities/Core2/NodeInfo.cs b/src/Compilers/Test/Utilities/Core2/NodeInfo.cs index b0a34c909f8908f7f4277d7e8c675eb2dcbd9566..f00dd831e2c65401b3cbd864fe916b3b3cfa0730 100644 --- a/src/Compilers/Test/Utilities/Core2/NodeInfo.cs +++ b/src/Compilers/Test/Utilities/Core2/NodeInfo.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Reflection; -using Microsoft.CodeAnalysis.Text; +using System; namespace Microsoft.CodeAnalysis.Test.Utilities { diff --git a/src/Compilers/Test/Utilities/Core2/NodeRules.cs b/src/Compilers/Test/Utilities/Core2/NodeRules.cs deleted file mode 100644 index 71ba90987048254260b2efc51427e69cd0a76356..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/NodeRules.cs +++ /dev/null @@ -1,781 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Linq; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class NodeRules - { - [NonTerminalRuleAttribute(Name = "ParentSpanForNonTerminal", Group = "Span")] - public bool ParentSpanForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (nonTerminal.Parent != null) - { - if (nonTerminal.SpanStart < nonTerminal.Parent.SpanStart || nonTerminal.Span.End > nonTerminal.Parent.Span.End) - { - retVal = false; - errorText = "Span of this non-terminal is not within Span of its parent"; - } - else if (nonTerminal.FullSpan.Start < nonTerminal.Parent.FullSpan.Start || nonTerminal.FullSpan.End > nonTerminal.Parent.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this non-terminal is not within FullSpan of its parent"; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "ParentSpanForToken", Group = "Span")] - public bool ParentSpanForToken(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.SpanStart < token.Parent.SpanStart || token.Span.End > token.Parent.Span.End) - { - retVal = false; - errorText = "Span of this token is not within Span of its parent"; - } - else if (token.FullSpan.Start < token.Parent.FullSpan.Start || token.FullSpan.End > token.Parent.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this token is not within FullSpan of its parent"; - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "FirstChildSpan", Group = "Span")] - public bool FirstChildSpan(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var firstChild = nonTerminal.ChildNodesAndTokens().First(); - if (nonTerminal.SpanStart != firstChild.SpanStart) - { - retVal = false; - errorText = "Start Span of first child of this non-terminal does not coincide with start Span of this non-terminal"; - } - else if (nonTerminal.FullSpan.Start != firstChild.FullSpan.Start) - { - retVal = false; - errorText = "Start FullSpan of first child of this non-terminal does not coincide with start FullSpan of this non-terminal"; - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "LastChildSpan", Group = "Span")] - public bool LastChildSpan(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var lastChild = nonTerminal.ChildNodesAndTokens().Last(); - if (nonTerminal.Span.End != lastChild.Span.End) - { - retVal = false; - errorText = "End Span of last child of this non-terminal does not coincide with end Span of this non-terminal"; - } - else if (nonTerminal.FullSpan.End != lastChild.FullSpan.End) - { - retVal = false; - errorText = "End FullSpan of last child of this non-terminal does not coincide with end FullSpan of this non-terminal"; - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "ChildSpanWidth", Group = "Span")] - public bool ChildSpanWidth(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var total = 0; - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - total = child.FullSpan.Length; - } - - if (nonTerminal.FullSpan.Length != total) - { - retVal = false; - errorText = "FullSpan width of this non-terminal (" + nonTerminal.FullSpan.Length + ") does not match sum of FullSpan widths of its children (" + total + ")"; - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "ChildSiblingSpan", Group = "Span")] - public bool ChildSiblingSpan(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var curStart = -1; - var prvEnd = -1; - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - curStart = child.SpanStart; - if (prvEnd == -1) - { - prvEnd = curStart; - } - - if (curStart < prvEnd) - { - retVal = false; - errorText = "Start Span of a child of this non-terminal is less than the end Span of this child's preceding sibling"; - continue; - } - - prvEnd = child.Span.End; - } - - if (retVal) - { - curStart = -1; - prvEnd = -1; - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - curStart = child.FullSpan.Start; - if (prvEnd == -1) - { - prvEnd = curStart; - } - - if (curStart != prvEnd) - { - retVal = false; - errorText = "FullSpan of a child of this non-terminal is not adjacent to the FullSpan of this child's preceding sibling"; - continue; - } - - prvEnd = child.FullSpan.End; - } - } - - return retVal; - } - - [TriviaRuleAttribute(Name = "TriviaSpan", Group = "Span")] - public bool TriviaSpan(SyntaxTrivia trivia, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (!((trivia.SpanStart <= trivia.Token.SpanStart || trivia.SpanStart >= trivia.Token.Span.End) && (trivia.Span.End >= trivia.Token.Span.End || trivia.Span.End <= trivia.Token.SpanStart))) - { - retVal = false; - errorText = "Span of this trivia is within Span of its parent token"; - } - else if (!((trivia.FullSpan.Start <= trivia.Token.SpanStart || trivia.FullSpan.Start >= trivia.Token.Span.End) && (trivia.FullSpan.End >= trivia.Token.Span.End || trivia.FullSpan.End <= trivia.Token.SpanStart))) - { - retVal = false; - errorText = "FullSpan of this trivia is within Span of its parent token"; - } - else if (trivia.SpanStart < trivia.Token.FullSpan.Start || trivia.Span.End > trivia.Token.FullSpan.End) - { - retVal = false; - errorText = "Span of this trivia is not within FullSpan of its parent token"; - } - else if (trivia.FullSpan.Start < trivia.Token.FullSpan.Start || trivia.FullSpan.End > trivia.Token.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this trivia is not within FullSpan of its parent token"; - } - - return retVal; - } - - [TokenRuleAttribute(Name = "FirstLeadingTriviaSpan", Group = "Span")] - public bool FirstLeadingTriviaSpan(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.LeadingTrivia.Any()) - { - var firstLeadingTrivia = token.LeadingTrivia.First(); - if (token.FullSpan.Start != firstLeadingTrivia.FullSpan.Start) - { - retVal = false; - errorText = "Start FullSpan of first leading trivia of this token does not coincide with start FullSpan of this token"; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "LastTrailingTriviaSpan", Group = "Span")] - public bool LastTrailingTriviaSpan(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.TrailingTrivia.Any()) - { - var lastTrailingTrivia = token.TrailingTrivia.Last(); - if (token.FullSpan.End != lastTrailingTrivia.FullSpan.End) - { - retVal = false; - errorText = "End FullSpan of last trailing trivia of this token does not coincide with end FullSpan of this token"; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "LastLeadingTriviaSpan", Group = "Span")] - public bool LastLeadingTriviaSpan(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.LeadingTrivia.Any()) - { - var lastLeadingTrivia = token.LeadingTrivia.Last(); - if (!lastLeadingTrivia.HasStructure) - { - //Example where structured trivia can violate this rule - - //Leading #end region trivia on the } token has last child with trailing EndOfLineTrivia. - //namespace EVTInterop002_Server - //{ - //#region region - //#endregion - //} - if (token.SpanStart != lastLeadingTrivia.Span.End) - { - retVal = false; - errorText = "End Span of last leading trivia of this token does not coincide with start Span of this token"; - } - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "FirstTrailingTriviaSpan", Group = "Span")] - public bool FirstTrailingTriviaSpan(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.TrailingTrivia.Any()) - { - var firstTrailingTrivia = token.TrailingTrivia.First(); - if (!firstTrailingTrivia.HasStructure) - { - //Example where structured trivia can violate this rule - - //Trailing /** (multiline xml doc comment) trivia on the } token has children with their own leading DocumentationCommentExteriorTrivia. - //class c1 - //{ - //}/** - //* - //**/ - if (token.Span.End != firstTrailingTrivia.SpanStart) - { - retVal = false; - errorText = "Start Span of first trailing trivia of this token does not coincide with end Span of this token"; - } - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "TriviaSpanWidth", Group = "Span")] - public bool TriviaSpanWidth(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.LeadingTrivia.Any() || token.TrailingTrivia.Any()) - { - var total = 0; - foreach (var leadingTrivia in token.LeadingTrivia) - { - total = leadingTrivia.FullSpan.Length; - } - - foreach (var trailingTrivia in token.TrailingTrivia) - { - total = trailingTrivia.FullSpan.Length; - } - - if (token.FullSpan.Length != (total + token.Span.Length)) - { - retVal = false; - errorText = "FullSpan width of this token (" + token.FullSpan.Length + ") does not match Span width of this token (" + token.Span.Length + ") + sum of FullSpan widths of all leading and trailing trivia of this token (" + total + ")"; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "TriviaSiblingSpan", Group = "Span")] - public bool TriviaSiblingSpan(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var curStart = -1; - var prvEnd = -1; - foreach (var leadingTrivia in token.LeadingTrivia) - { - curStart = leadingTrivia.FullSpan.Start; - if (prvEnd == -1) - { - prvEnd = curStart; - } - - if (curStart != prvEnd) - { - retVal = false; - errorText = "FullSpan of a leading trivia of this token is not adjacent to the FullSpan of this leading trivia's preceding sibling"; - continue; - } - - prvEnd = leadingTrivia.FullSpan.End; - } - - if (retVal) - { - curStart = -1; - prvEnd = -1; - foreach (var trailingTrivia in token.TrailingTrivia) - { - curStart = trailingTrivia.FullSpan.Start; - if (prvEnd == -1) - { - prvEnd = curStart; - } - - if (curStart != prvEnd) - { - retVal = false; - errorText = "FullSpan of a trailing trivia of this token is not adjacent to the FullSpan of this trailing trivia's preceding sibling"; - continue; - } - - prvEnd = trailingTrivia.FullSpan.End; - } - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "SpanAndFullSpanForNonTerminal", Group = "Span")] - public bool SpanAndFullSpanForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (nonTerminal.ChildNodesAndTokens().Any()) - { - if (nonTerminal.FullSpan.Start > nonTerminal.SpanStart || nonTerminal.Span.End > nonTerminal.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this non-terminal does not enclose its Span"; - } - } - else - { - retVal = false; - errorText = "A non-terminal must have at least one child"; - } - - return retVal; - } - - [TokenRuleAttribute(Name = "SpanAndFullSpanForToken", Group = "Span")] - public bool SpanAndFullSpanForToken(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.LeadingTrivia.Any() || token.TrailingTrivia.Any()) - { - if (token.FullSpan.Start > token.SpanStart || token.Span.End > token.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this token does not enclose Span of this token"; - } - } - else - { - if (token.Span != token.FullSpan) - { - retVal = false; - errorText = "Span and FullSpan for this token do not match - but they should because this token has no leading or trailing trivia"; - } - } - - return retVal; - } - - [TriviaRuleAttribute(Name = "SpanAndFullSpanForTrivia", Group = "Span")] - public bool SpanAndFullSpanForTrivia(SyntaxTrivia trivia, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (trivia.HasStructure) - { - if (trivia.FullSpan.Start > trivia.SpanStart || trivia.Span.End > trivia.FullSpan.End) - { - retVal = false; - errorText = "FullSpan of this structured trivia does not enclose Span of this trivia"; - } - } - else - { - if (trivia.Span != trivia.FullSpan) - { - retVal = false; - errorText = "Span and FullSpan for this non-structured trivia do not match"; - } - } - - return retVal; - } - - /* #End Region - */ - /* #Region "Structure" - */ - [NonTerminalRuleAttribute(Name = "ParentForNonTerminal", Group = "Structure")] - public bool ParentForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (nonTerminal.Parent == null) - { - if (!nonTerminal.IsStructuredTrivia && nonTerminal.GetKind() != "CompilationUnit") - { - retVal = false; - errorText = "This non-terminal has a null parent"; - } - } - else - { - if (nonTerminal.IsStructuredTrivia) - { - retVal = false; - errorText = "This structured trivia has a non-null parent"; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "ParentForToken", Group = "Structure")] - public bool ParentForToken(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.Parent == null) - { - retVal = false; - errorText = "This token has a null parent"; - } - - return retVal; - } - - [TriviaRuleAttribute(Name = "TriviaStructure", Group = "Structure")] - public bool TriviaStructure(SyntaxTrivia trivia, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (trivia.HasStructure) - { - if (trivia.GetStructure() == null) - { - retVal = false; - errorText = "This structured trivia has null structure"; - } - else if (!trivia.GetStructure().IsStructuredTrivia) - { - retVal = false; - errorText = "This structured trivia's structure has IsStructuredTrivia set to 'False'"; - } - } - else if (!trivia.HasStructure & trivia.GetStructure() != null) - { - retVal = false; - errorText = "This non-structured trivia has non-null structure"; - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "ParentAndChildrenForNonTerminal", Group = "Structure")] - public bool ParentAndChildrenForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - if (child.Parent != nonTerminal) - { - retVal = false; - errorText = "A child of this non-terminal does not have this non-terminal set as its parent"; - continue; - } - } - - return retVal; - } - - [TokenRuleAttribute(Name = "ParentAndChildrenForToken", Group = "Structure")] - public bool ParentAndChildrenForToken(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - foreach (var leadingTrivia in token.LeadingTrivia) - { - if (leadingTrivia.Token != token) - { - retVal = false; - errorText = "A leading trivia of this token does not have this token set as its parent"; - continue; - } - } - - if (retVal) - { - foreach (var trailingTrivia in token.TrailingTrivia) - { - if (trailingTrivia.Token != token) - { - retVal = false; - errorText = "A trailing trivia of this token does not have this token set as its parent"; - continue; - } - } - } - - return retVal; - } - - /* #End Region - */ - /* #Region "Misc" - */ - //SEE BUG 867280 - [NonTerminalRuleAttribute(Name = "ZeroWidthOrMissingNonTerminals", Group = "Misc")] - public bool ZeroWidthOrMissingNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (nonTerminal.ContainsDiagnostics || tree.GetDiagnostics().Any()) - { - if (nonTerminal.IsMissing) - { - if (nonTerminal.Span.Length == 0) - { - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - if (child.IsNode && !child.AsNode().IsMissing) - { - retVal = false; - errorText = "This missing non-terminal has a non-missing child non-terminal"; - continue; - } - else if (child.IsToken && !child.AsToken().IsMissing) - { - retVal = false; - errorText = "This missing non-terminal has a non-missing child token"; - continue; - } - } - } - else - { - retVal = false; - errorText = "Missing non-terminals should have 0 Span width"; - } - } - else if (nonTerminal.Span.Length == 0) - { - var kind = nonTerminal.GetKind(); - if (!(kind == "OmittedArgument" || kind.Contains("Bad") || - (kind == "CompilationUnit" && - nonTerminal.ChildNodesAndTokens().Count == 1 && - nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken"))) - { - //Ignore BadStatement and BadDirective (these can only be present if tree has errors). - //Ignore case where code file is empty or file only includes trivia - in this case - //root node will have a single child ('EndOfFileToken') which has 0 width. - retVal = false; - errorText = "Non-terminals with 0 Span width should have IsMissing set to 'True'"; - } - } - } - else - { - if (nonTerminal.IsMissing) - { - retVal = false; - errorText = "A tree with 0 errors should not contain missing non-terminals"; - } - else if (nonTerminal.Span.Length == 0) - { - var kind = nonTerminal.GetKind(); - if (!(kind == "OmittedArgument" || (kind == "CompilationUnit" && nonTerminal.ChildNodesAndTokens().Count == 1 && nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken"))) - { - //Ignore case where code file is empty or file only includes trivia - in this case - //root node will have a single child ('EndOfFileToken') which has 0 width. - retVal = false; - errorText = "A tree with 0 errors should not contain non-terminals with 0 width"; - } - } - } - - return retVal; - } - - //SEE BUG 867280 - [TokenRuleAttribute(Name = "ZeroWidthOrMissingTokens", Group = "Misc")] - public bool ZeroWidthOrMissingTokens(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (token.ContainsDiagnostics || tree.GetDiagnostics().Any()) - { - if (token.IsMissing) - { - if (token.Span.Length == 0) - { - if (token.LeadingTrivia.Any() || token.TrailingTrivia.Any()) - { - var atleastOneSkippedTrivia = ( - from leadingTrivia in token.LeadingTrivia - let kind = leadingTrivia.GetKind() - where kind == "SkippedTextTrivia" || kind == "SkippedTokens" - select new - { - leadingTrivia, - kind - } - - ).Any(); - if (!atleastOneSkippedTrivia) - { - atleastOneSkippedTrivia = ( - from trailingTrivia in token.TrailingTrivia - let kind = trailingTrivia.GetKind() - where kind == "SkippedTextTrivia" || kind == "SkippedTokens" - select new - { - trailingTrivia, - kind - } - - ).Any(); - if (!atleastOneSkippedTrivia) - { - retVal = false; - errorText = "Missing tokens should have at least one trivia with kind SkippedTextTrivia OR SkippedTokens"; - } - } - } - } - else - { - retVal = false; - errorText = "Missing tokens should have 0 Span width"; - } - } - else if (token.Span.Length == 0) - { - var kind = token.GetKind(); - if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken" || kind.Contains("Bad"))) - { - //BadToken only appears in error trees for C#. - retVal = false; - errorText = "Tokens with 0 Span width should have IsMissing set to 'True'"; - } - } - } - else - { - if (token.IsMissing) - { - retVal = false; - errorText = "A tree with 0 errors should not contain missing tokens"; - } - else if (token.Span.Length == 0) - { - var kind = token.GetKind(); - if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken")) - { - //EmptyToken can be present even in non-error cases in VB (it is used for OmittedArgument). - retVal = false; - errorText = "A tree with 0 errors should not contain tokens with 0 width"; - } - } - } - - return retVal; - } - - [NonTerminalRuleAttribute(Name = "BadNonTerminals", Group = "Misc")] - public bool BadNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var kind = nonTerminal.GetKind(); - if (tree.GetDiagnostics().Any()) - { - if (kind.Contains("Bad")) - { - if (tree.GetDiagnostics(nonTerminal).Any()) - { - } - else - { - retVal = false; - errorText = "Bad non-terminals should have at least one error on them"; - } - } - } - else if (kind.Contains("Bad")) - { - retVal = false; - errorText = "A tree with 0 errors should not contain Bad non-terminals"; - } - - return retVal; - } - - [TokenRuleAttribute(Name = "BadTokens", Group = "Misc")] - public bool BadTokens(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var kind = token.GetKind(); - if (tree.GetDiagnostics().Any()) - { - if (kind.Contains("Bad")) - { - if (tree.GetDiagnostics(token).Any()) - { - } - else - { - retVal = false; - errorText = "Bad tokens should have at least one error on them"; - } - } - } - else if (kind.Contains("Bad")) - { - retVal = false; - errorText = "A tree with 0 errors should not contain Bad tokens"; - } - - return retVal; - } - - //SEE BUG 867280 - [TriviaRuleAttribute(Name = "ZeroWidthTrivia", Group = "Misc")] - public bool ZeroWidthTrivia(SyntaxTrivia trivia, SyntaxTree tree, ref string errorText) - { - var retVal = true; - if (trivia.Span.Length == 0 || trivia.FullSpan.Length == 0) - { - retVal = false; - errorText = "Trivia should never have 0 Span or FullSpan width"; - } - - return retVal; - } - - //SEE BUG 865832 - [TokenRuleAttribute(Name = "WhiteSpaceInTokens", Group = "Misc")] - public bool WhiteSpaceInTokens(SyntaxToken token, SyntaxTree tree, ref string errorText) - { - var retVal = true; - var kind = token.GetKind(); - if (kind != "StatementTerminatorToken" && kind != "DateLiteralToken" && kind != "StringLiteralToken" && kind != "CharacterLiteralToken" && kind != "XmlTextLiteralToken" && kind != "XmlAttributeDataToken" && kind != "XmlCommentDataToken" && kind != "XmlCDataToken" && kind != "XmlProcessingInstructionDataToken" && kind != "XmlTextLiteralNewLineToken" && kind != "LessThanEqualsToken" && kind != "GreaterThanEqualsToken" && kind != "LessThanGreaterThanToken" && kind != "ColonEqualsToken" && kind != "CaretEqualsToken" && kind != "AsteriskEqualsToken" && kind != "PlusEqualsToken" && kind != "MinusEqualsToken" && kind != "SlashEqualsToken" && kind != "BackslashEqualsToken" && kind != "LessThanLessThanToken" && kind != "GreaterThanGreaterThanToken" && kind != "LessThanLessThanEqualsToken" && kind != "GreaterThanGreaterThanEqualsToken" && kind != "AmpersandEqualsToken") - { - var text = token.ToString(); - if ((text.Contains(" ") || text.Contains('\t') || text.Contains('\r') || text.Contains('\n') || text.Contains("\r\n"))) - { - retVal = false; - errorText = "The text of this token should not contain any whitespace"; - } - } - - return retVal; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/NonTerminalRuleAttribute.cs b/src/Compilers/Test/Utilities/Core2/NonTerminalRuleAttribute.cs deleted file mode 100644 index de36f78f450ff47c4130eda3e8e57bef72f1bc61..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/NonTerminalRuleAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class NonTerminalRuleAttribute : Attribute - { - public string Name - { - get; - set; - } - - public string Group - { - get; - set; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/ParseHelpers.cs b/src/Compilers/Test/Utilities/Core2/ParseHelpers.cs deleted file mode 100644 index 44bc32b6e742912a684703be1897db91a96bdeae..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/ParseHelpers.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class ParseHelpers - { - private const string CS_PARSER_DLL = "Microsoft.CodeAnalysis.CSharp.dll"; - private const string VB_PARSER_DLL = "Microsoft.CodeAnalysis.VisualBasic.dll"; - private const string CS_SYNTAX_TREE_TYPE = "Roslyn.Compilers.CSharp.CSharpSyntaxTree"; - private const string VB_SYNTAX_TREE_TYPE = "Roslyn.Compilers.VisualBasic.VisualBasicSyntaxTree"; - private const string CS_OPTIONS_TYPE = "Roslyn.Compilers.CSharp.ParseOptions"; - private const string VB_OPTIONS_TYPE = "Roslyn.Compilers.VisualBasic.ParseOptions"; - private const string SYNTAX_TREE_PARSE_METHOD = "ParseCompilationUnit"; - private const string CS_LANG_VERSION_OPTION_TYPE = "Roslyn.Compilers.CSharp.LanguageVersion"; - private const string CODE_KIND_OPTION = "Roslyn.Compilers.SourceCodeKind"; -#if false - private Type m_CSParserType = null; - private Type m_VBParserType = null; -#endif - private Type _CSSyntaxTreeType; - private Type _visualBasicSyntaxTreeType; - private object _CSOptions; - private object _VBOptions; - private readonly string _CSFileName = "Default.cs"; - private readonly string _VBFileName = "Default.vb"; - private object _codeKind; - public SyntaxTree ParseCSTree(string code, string folder) - { - if (_CSSyntaxTreeType == null) - { - var asm = Assembly.LoadFrom(Path.Combine(folder, CS_PARSER_DLL)); - _CSSyntaxTreeType = asm.GetType(CS_SYNTAX_TREE_TYPE); - var csLangVersionOption = Enum.Parse(asm.GetType(CS_LANG_VERSION_OPTION_TYPE), "CSharp4"); - _codeKind = Enum.Parse(asm.GetType(CODE_KIND_OPTION), "Regular"); - _CSOptions = Activator.CreateInstance(asm.GetType(CS_OPTIONS_TYPE), csLangVersionOption, null, false, _codeKind); - } - - SyntaxTree syntaxTree = (SyntaxTree)_CSSyntaxTreeType.InvokeMember(SYNTAX_TREE_PARSE_METHOD, BindingFlags.InvokeMethod, null, null, new[] - { - code, _CSFileName, _CSOptions - } - - ); - return syntaxTree; - } - - public SyntaxTree ParseVBTree(string code, string folder) - { - if (_visualBasicSyntaxTreeType == null) - { - var asm = Assembly.LoadFrom(Path.Combine(folder, VB_PARSER_DLL)); - _visualBasicSyntaxTreeType = asm.GetType(VB_SYNTAX_TREE_TYPE); - _codeKind = Enum.Parse(asm.GetType(CODE_KIND_OPTION), "Regular"); - _VBOptions = Activator.CreateInstance(asm.GetType(VB_OPTIONS_TYPE), null, false, _codeKind); - } - - SyntaxTree syntaxTree = (SyntaxTree)_visualBasicSyntaxTreeType.InvokeMember(SYNTAX_TREE_PARSE_METHOD, BindingFlags.InvokeMethod, null, null, new[] - { - code, _VBFileName, _VBOptions - } - - ); - return syntaxTree; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/ProgressDialog.Designer.cs b/src/Compilers/Test/Utilities/Core2/ProgressDialog.Designer.cs deleted file mode 100644 index c584b8066bea2e622d6f75a81e68306bb5dab07f..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/ProgressDialog.Designer.cs +++ /dev/null @@ -1,61 +0,0 @@ - -using System.Diagnostics; -using System.Drawing; -using System.Windows.Forms; -using Microsoft.CodeAnalysis.Text; -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - partial class ProgressDialog : Form - { - [DebuggerNonUserCode()] - private void InitializeComponent() - { - this.Label1 = new Label(); - this.Label2 = new Label(); - this.ProgressBar1 = new ProgressBar(); - this.SuspendLayout(); - // - //Label1 - // - this.Label1.AutoSize = true; - this.Label1.Location = new Point(12, 50); - this.Label1.Name = "Label1"; - this.Label1.Size = new Size(60, 13); - this.Label1.TabIndex = 0; - this.Label1.Text = "Processed:"; - // - //Label2 - // - this.Label2.AutoSize = true; - this.Label2.Location = new Point(78, 50); - this.Label2.Name = "Label2"; - this.Label2.Size = new Size(39, 13); - this.Label2.TabIndex = 1; - this.Label2.Text = "Label2"; - // - //ProgressBar1 - // - this.ProgressBar1.Location = new Point(12, 14); - this.ProgressBar1.Name = "ProgressBar1"; - this.ProgressBar1.Size = new Size(211, 24); - this.ProgressBar1.TabIndex = 2; - // - //ProgressDialog - // - this.AutoScaleDimensions = new SizeF(6, 13); - this.AutoScaleMode = AutoScaleMode.Font; - this.ClientSize = new Size(235, 75); - this.Controls.Add(this.ProgressBar1); - this.Controls.Add(this.Label2); - this.Controls.Add(this.Label1); - this.Name = "ProgressDialog"; - this.Text = "Progress..."; - this.ResumeLayout(false); - this.PerformLayout(); - } - - internal Label Label1; - internal Label Label2; - internal ProgressBar ProgressBar1; - } -} \ No newline at end of file diff --git a/src/Compilers/Test/Utilities/Core2/ProgressDialog.cs b/src/Compilers/Test/Utilities/Core2/ProgressDialog.cs deleted file mode 100644 index 5dd80c0116bf4d3e03abf3a90b13d2cd25d3c66b..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/ProgressDialog.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Windows.Forms; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public partial class ProgressDialog - { - public ProgressDialog() - { - InitializeComponent(); - } - - public int Maximum - { - get; - set; - } - - private void ProgressDialog_Load(object sender, EventArgs e) - { - Label2.Text = "0"; - ProgressBar1.Maximum = Maximum; - } - - public void Increment() - { - Label2.Text = "1"; - ProgressBar1.Increment(1); - Application.DoEvents(); - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/ProgressDialog.resx b/src/Compilers/Test/Utilities/Core2/ProgressDialog.resx deleted file mode 100644 index e3a02db88a042c271e4cfcb4383fb3222c891223..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/ProgressDialog.resx +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - diff --git a/src/Compilers/Test/Utilities/Core2/SourceCodeValidator.cs b/src/Compilers/Test/Utilities/Core2/SourceCodeValidator.cs deleted file mode 100644 index 464ce5d9b0c3a06f1876d46d2793bec1ae5da47a..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/SourceCodeValidator.cs +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Text; -using System.Threading; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class SourceCodeValidator - { - protected const int ParserTimeout = 1 * 600000; - protected const int TreeValidatorTimeout = 1 * 600000; - protected readonly Rule ExceptionRule = new Rule() - { - Name = "ExceptionThrown" - }; - - private readonly string[] _searchPatterns; - private readonly IParser _parser; - private readonly TreeValidator _treeValidator; - protected readonly List m_failures; - - public event Action FileFound; - public event Action TransformCode; - - public SourceCodeValidator(IParser parser, string[] searchPatterns, ISyntaxNodeKindProvider nodeKindProvider, bool enableAllRules) - { - _parser = parser; - _searchPatterns = searchPatterns; - _treeValidator = new TreeValidator(nodeKindProvider); - m_failures = new List(); - if (!enableAllRules) - { - _treeValidator.UnregisterAllRules(); - } - } - - public ReadOnlyCollection Failures - { - get - { - return new ReadOnlyCollection(m_failures); - } - } - - public void RegisterRule(TreeRuleDelegate test, string name, string group) - { - _treeValidator.RegisterRule(test, name, group); - } - - public void RegisterRule(NonTerminalRuleDelegate test, string name, string group) - { - _treeValidator.RegisterRule(test, name, group); - } - - public void RegisterRule(TokenRuleDelegate test, string name, string group) - { - _treeValidator.RegisterRule(test, name, group); - } - - public void RegisterRule(TriviaRuleDelegate test, string name, string group) - { - _treeValidator.RegisterRule(test, name, group); - } - - public void UnRegisterRule(string name) - { - _treeValidator.UnregisterRule(name); - } - - protected bool ValidateCode(string code, ref SyntaxTree outTree, string filePath = "") - { - var isValid = false; - ParameterizedThreadStart exceptionWrapper = (object obj) => - { - ThreadStart wrapped = (ThreadStart)obj; - try - { - wrapped.Invoke(); - } - catch (Exception ex) - { - isValid = false; - m_failures.Add(new Failure(filePath, ExceptionRule, null, ex.ToString(), null)); - } - } - - ; - var codeBuilder = new StringBuilder(code); - TransformCode(codeBuilder); - code = codeBuilder.ToString(); - SyntaxTree tree = null; - var parserThread = new Thread(exceptionWrapper); - parserThread.Start((ThreadStart)(() => - { - tree = _parser.Parse(code); - })); - if (!parserThread.Join(ParserTimeout)) - { - throw new TimeoutException("Parsing timed out. Current timeout is " + ParserTimeout / 1000 + " seconds."); - } - - outTree = tree; - if (outTree != null) - { - var treeValidatorThread = new Thread(exceptionWrapper); - treeValidatorThread.Start((ThreadStart)(() => - { - isValid = _treeValidator.Validate(tree, code, filePath, m_failures); - })); - if (!treeValidatorThread.Join(TreeValidatorTimeout)) - { - throw new TimeoutException("Tree validation timed out. Current timeout is " + TreeValidatorTimeout / 1000 + " seconds."); - } - } - - return isValid; - } - - public virtual bool ValidateFile(string filePath) - { - SyntaxTree tree = null; - return ValidateCode(File.ReadAllText(filePath), ref tree, filePath); - } - - public bool ValidateAllFiles(string dirPath) - { - var isValid = true; - var dirHelper = new DirectoryHelper(dirPath); - dirHelper.FileFound += (string filePath) => - { - FileFound(filePath); - isValid = isValid & ValidateFile(filePath); - } - - ; - dirHelper.IterateFiles(_searchPatterns); - return isValid; - } - - public bool ValidateAllFiles(IEnumerable fileList) - { - var isValid = true; - foreach (var f in fileList) - { - FileFound(f); - isValid = isValid & ValidateFile(f); - } - - return isValid; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/SpeculativeSemanticModelTestsBase.cs b/src/Compilers/Test/Utilities/Core2/SpeculativeSemanticModelTestsBase.cs index f22443fce86f7b6b6ff3e7d68e999c9d664672da..c9b06de61e967e575648ed431204e386ab4740a4 100644 --- a/src/Compilers/Test/Utilities/Core2/SpeculativeSemanticModelTestsBase.cs +++ b/src/Compilers/Test/Utilities/Core2/SpeculativeSemanticModelTestsBase.cs @@ -11,6 +11,7 @@ namespace Microsoft.CodeAnalysis.UnitTests { public class SpeculativeSemanticModelTestsBase { +#if false // https://github.com/dotnet/roslyn/issues/4453 protected void CheckAllMembers(T instance, IDictionary> valueProviders, IDictionary expectedExceptions) { foreach (var m in typeof(T).GetMembers()) @@ -46,8 +47,10 @@ protected void CheckAllMembers(T instance, IDictionary> va } } } +#endif } + internal static class DictionaryExtensions { public static TValue GetValueOrDefault(this IDictionary dictionary, TKey key) diff --git a/src/Compilers/Test/Utilities/Core2/TokenRuleAttribute.cs b/src/Compilers/Test/Utilities/Core2/TokenRuleAttribute.cs deleted file mode 100644 index c18ac0a019f33cc70557268a5e8407d241584458..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/TokenRuleAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class TokenRuleAttribute : Attribute - { - public string Name - { - get; - set; - } - - public string Group - { - get; - set; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/TreeRuleAttribute.cs b/src/Compilers/Test/Utilities/Core2/TreeRuleAttribute.cs deleted file mode 100644 index 9d02505bc398c70f593e2ef952c95ea9ba92780a..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/TreeRuleAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class TreeRuleAttribute : Attribute - { - public string Name - { - get; - set; - } - - public string Group - { - get; - set; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/TreeRules.cs b/src/Compilers/Test/Utilities/Core2/TreeRules.cs deleted file mode 100644 index e6bee56dd961a9052ca2d0f58fe4de271617ea39..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/TreeRules.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Linq; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class TreeRules - { - [TreeRule(Name = "RoundTrip", Group = "RoundTrip")] - private bool RoundTrip(SyntaxTree tree, string codeText, string filename, ref string errorText) - { - var retVal = true; - if (tree.GetRoot().ToFullString() != codeText) - { - retVal = false; - errorText = "FullText for tree parsed from '" + filename + "' does match actual text"; - } - - return retVal; - } - [TreeRule(Name = "TreeFullSpan", Group = "Span")] - - private bool TreeFullSpan(SyntaxTree tree, string codeText, string filename, ref string errorText) - { - var retVal = true; - if (tree.GetRoot().FullSpan.Length != codeText.Length) - { - retVal = false; - errorText = "FullSpan width of tree (" + tree.GetRoot().FullSpan.Length + ") does not match length of the code (" + codeText.Length + ")"; - } - - return retVal; - } - [TreeRule(Name = "NullsAndCollections", Group = "RoundTrip")] - - private bool NullsAndCollections(SyntaxTree tree, string codeText, string filename, ref string errorText) - { - var retVal = true; - if (tree.GetDiagnostics() == null) - { - retVal = false; - errorText = "Diagnostics collection for this tree is null"; - } - else if (( - from e in tree.GetDiagnostics() - where e == null - select e).Any()) - { - retVal = false; - errorText = "Diagnostics collection for this tree contains a null element"; - } - else if (tree.GetRoot().DescendantTokens() == null) - { - retVal = false; - errorText = "Tokens collection for this tree is null"; - } - - return retVal; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/TreeValidator.cs b/src/Compilers/Test/Utilities/Core2/TreeValidator.cs deleted file mode 100644 index c514f0dac5a01136b941d3e1dedd8152acd006dd..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/TreeValidator.cs +++ /dev/null @@ -1,648 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public delegate bool TreeRuleDelegate(SyntaxTree tree, string codeText, string filename, ref string errorText); - public delegate bool NonTerminalRuleDelegate(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText); - public delegate bool TokenRuleDelegate(SyntaxToken token, SyntaxTree tree, ref string errorText); - public delegate bool TriviaRuleDelegate(SyntaxTrivia trivia, SyntaxTree tree, ref string errorText); - public delegate void ErrorHandlerDelegate(string error, Rule rule); - - public class Failure - { - private string _file; - public string File - { - get - { - if (_file == null) - { - _file = string.Empty; - } - - return _file; - } - } - - private readonly Rule _rule; - public Rule Rule - { - get - { - return _rule; - } - } - - private string _errorText; - public string ErrorText - { - get - { - if (_errorText == null) - { - _errorText = string.Empty; - } - - return _errorText; - } - } - - private Location _location; - public Location Location - { - get - { - if (_location == null) - { - _location = FailureLocation.Default; - } - - return _location; - } - } - - private string _nodeKind; - public string NodeKind - { - get - { - if (_nodeKind == null) - { - _nodeKind = string.Empty; - } - - return _nodeKind; - } - } - - public override string ToString() - { - var retVal = !string.IsNullOrEmpty(this.File) ? this.File + " " : null; - if (this.Location.IsInSource) - { - retVal = this.Location.SourceSpan.ToString() + ": "; - } - - retVal = this.Rule.Name + ": " + this.NodeKind + ": " + this.ErrorText; - return retVal; - } - - public Failure(string file, Rule rule, string nodeKind, string errorText, Location location) - { - _file = file; - _rule = rule; - _nodeKind = nodeKind; - _errorText = errorText; - _location = location; - } - } - - /* #End Region - */ - /* #Region "Rule" - */ - public class Rule - { - public string Name - { - get; - set; - } - - public string Group - { - get; - set; - } - } - - /* #End Region - */ - public class TreeValidator - { - /* #Region "Rules" - */ - private class TreeRule : Rule - { - public TreeRuleDelegate Test - { - get; - set; - } - } - - private class NonTerminalRule : Rule - { - public NonTerminalRuleDelegate Test - { - get; - set; - } - } - - private class TokenRule : Rule - { - public TokenRuleDelegate Test - { - get; - set; - } - } - - private class TriviaRule : Rule - { - public TriviaRuleDelegate Test - { - get; - set; - } - } - - private readonly Dictionary _treeRules = new Dictionary(); - private readonly Dictionary _nonTerminalRules = new Dictionary(); - private readonly Dictionary _tokenRules = new Dictionary(); - private readonly Dictionary _triviaRules = new Dictionary(); - private event ErrorHandlerDelegate ValidationFailed; - - public TreeValidator(ISyntaxNodeKindProvider nodeKindProvider) - { - NodeHelpers.KindProvider = nodeKindProvider; - RegisterRules(); - } - - /* #Region "Register" - */ - private void RegisterRules() - { - RegisterRules(Assembly.GetExecutingAssembly()); - } - - private void RegisterRules(Assembly assembly) - { - if (assembly != null) - { - foreach (var t in assembly.GetTypes()) - { - foreach (var m in t.GetMethods()) - { - if (m.IsStatic && !m.IsAbstract && !m.IsConstructor && !m.IsGenericMethod && m.ReturnType == typeof(bool) && - (m.GetParameters()[0].ParameterType == typeof(SyntaxTree) || - m.GetParameters()[0].ParameterType == typeof(SyntaxNode) || - m.GetParameters()[0].ParameterType == typeof(SyntaxToken) || - m.GetParameters()[0].ParameterType == typeof(SyntaxTrivia))) - { - var method = m; - var attrs = method.GetCustomAttributes(false); - if (attrs != null && attrs.Length == 1) - { - if (attrs[0] is TreeRuleAttribute) - { - var attr = (TreeRuleAttribute)attrs[0]; - RegisterRule(new TreeRule() - { - Test = (TreeRuleDelegate)Delegate.CreateDelegate(typeof(TreeRuleDelegate), method), - Name = attr.Name, - Group = attr.Group - } - - ); - } - else if (attrs[0] is NonTerminalRuleAttribute) - { - var attr = (NonTerminalRuleAttribute)attrs[0]; - RegisterRule(new NonTerminalRule() - { - Test = (NonTerminalRuleDelegate)Delegate.CreateDelegate(typeof(NonTerminalRuleDelegate), method), - Name = attr.Name, - Group = attr.Group - } - - ); - } - else if (attrs[0] is TokenRuleAttribute) - { - var attr = (TokenRuleAttribute)attrs[0]; - RegisterRule(new TokenRule() - { - Test = (TokenRuleDelegate)Delegate.CreateDelegate(typeof(TokenRuleDelegate), method), - Name = attr.Name, - Group = attr.Group - } - - ); - } - else if (attrs[0] is TriviaRuleAttribute) - { - var attr = (TriviaRuleAttribute)attrs[0]; - RegisterRule(new TriviaRule() - { - Test = (TriviaRuleDelegate)Delegate.CreateDelegate(typeof(TriviaRuleDelegate), method), - Name = attr.Name, - Group = attr.Group - } - - ); - } - } - } - } - } - } - } - - public void RegisterRules(string path) - { - if (!string.IsNullOrEmpty(path)) - { - RegisterRules(Assembly.LoadFrom(path)); - } - } - - private void RegisterRule(TreeRule rule) - { - if (rule != null) - { - _treeRules[rule.Name] = rule; - } - } - - private void RegisterRule(NonTerminalRule rule) - { - if (rule != null) - { - _nonTerminalRules[rule.Name] = rule; - } - } - - private void RegisterRule(TokenRule rule) - { - if (rule != null) - { - _tokenRules[rule.Name] = rule; - } - } - - private void RegisterRule(TriviaRule rule) - { - if (rule != null) - { - _triviaRules[rule.Name] = rule; - } - } - - public void RegisterErrorHandler(ErrorHandlerDelegate errorHandler) - { - if (errorHandler != null) - { - ValidationFailed += errorHandler; - } - } - - public void RegisterRule(TreeRuleDelegate test, string name, string group) - { - if (test != null && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(group)) - { - RegisterRule(new TreeRule() - { - Test = test, - Name = name, - Group = group - } - - ); - } - } - - public void RegisterRule(NonTerminalRuleDelegate test, string name, string group) - { - if (test != null && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(group)) - { - RegisterRule(new NonTerminalRule() - { - Test = test, - Name = name, - Group = group - } - - ); - } - } - - public void RegisterRule(TokenRuleDelegate test, string name, string group) - { - if (test != null && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(group)) - { - RegisterRule(new TokenRule() - { - Test = test, - Name = name, - Group = group - } - - ); - } - } - - public void RegisterRule(TriviaRuleDelegate test, string name, string group) - { - if (test != null && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(group)) - { - RegisterRule(new TriviaRule() - { - Test = test, - Name = name, - Group = group - } - - ); - } - } - - /* #End Region - */ - /* #Region "UnRegister" - */ - public void UnregisterRule(string ruleName) - { - if (!string.IsNullOrEmpty(ruleName)) - { - if (_treeRules.ContainsKey(ruleName)) - { - _treeRules.Remove(ruleName); - } - - if (_nonTerminalRules.ContainsKey(ruleName)) - { - _nonTerminalRules.Remove(ruleName); - } - - if (_tokenRules.ContainsKey(ruleName)) - { - _tokenRules.Remove(ruleName); - } - - if (_triviaRules.ContainsKey(ruleName)) - { - _triviaRules.Remove(ruleName); - } - } - } - - public void UnregisterRuleGroup(string group) - { - if (!string.IsNullOrEmpty(group)) - { - foreach (var r in _treeRules) - { - if (r.Value.Group == group) - { - _treeRules.Remove(r.Value.Name); - } - } - - foreach (var r in _nonTerminalRules) - { - if (r.Value.Group == group) - { - _nonTerminalRules.Remove(r.Value.Name); - } - } - - foreach (var r in _tokenRules) - { - if (r.Value.Group == group) - { - _tokenRules.Remove(r.Value.Name); - } - } - - foreach (var r in _triviaRules) - { - if (r.Value.Group == group) - { - _triviaRules.Remove(r.Value.Name); - } - } - } - } - - public void UnregisterAllTreeRules() - { - _treeRules.Clear(); - } - - public void UnregisterAllNonTerminalRules() - { - _nonTerminalRules.Clear(); - } - - public void UnregisterAllTokenRules() - { - _tokenRules.Clear(); - } - - public void UnregisterAllTriviaRules() - { - _triviaRules.Clear(); - } - - public void UnregisterAllRules() - { - UnregisterAllTreeRules(); - UnregisterAllNonTerminalRules(); - UnregisterAllTokenRules(); - UnregisterAllTriviaRules(); - } - - /* #End Region - */ - /* #Region "Validate" - */ - private bool ValidateTree(SyntaxTree tree, string codeText, string filename, List failures = null) - { - var retVal = true; - if (!string.IsNullOrEmpty(filename)) - { - filename = Path.GetFullPath(filename); - } - else if (filename == null) - { - filename = string.Empty; - } - - bool pass = false; - if (tree != null) - { - foreach (var rule in _treeRules.Values) - { - var errorText = string.Empty; - pass = rule.Test(tree, codeText, filename, ref errorText); - if (!pass) - { - if (failures != null) - { - failures.Add(new Failure(filename, rule, tree.GetRoot().GetKind(), errorText, new FailureLocation(tree.GetRoot().Span, tree))); - } - - ValidationFailed(errorText, rule); - } - - retVal = retVal & pass; - } - } - - return retVal; - } - - private bool ValidateNodeOrToken(SyntaxNodeOrToken nodeOrtoken, SyntaxTree tree, string filename = "", List failures = null) - { - var retVal = true; - if (nodeOrtoken.IsNode) - { - retVal = ValidateNonTerminal(nodeOrtoken.AsNode(), tree, filename, failures); - } - else - { - retVal = ValidateToken(nodeOrtoken.AsToken(), tree, filename, failures); - } - - return retVal; - } - - private bool ValidateNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, string filename = "", List failures = null) - { - var retVal = true; - if (!string.IsNullOrEmpty(filename)) - { - filename = Path.GetFullPath(filename); - } - else if (filename == null) - { - filename = string.Empty; - } - - if (nonTerminal != null) - { - foreach (var child in nonTerminal.ChildNodesAndTokens()) - { - retVal = retVal & ValidateNodeOrToken(child, tree, filename, failures); - } - - bool pass = false; - foreach (var rule in _nonTerminalRules.Values) - { - var errorText = string.Empty; - pass = rule.Test(nonTerminal, tree, ref errorText); - if (!pass) - { - if (failures != null) - { - failures.Add(new Failure(filename, rule, nonTerminal.GetKind(), errorText, new FailureLocation(nonTerminal.Span, tree))); - } - - ValidationFailed(errorText, rule); - } - - retVal = retVal & pass; - } - } - - return retVal; - } - - private bool ValidateToken(SyntaxToken token, SyntaxTree tree, string filename = "", List failures = null) - { - var retVal = true; - foreach (var leadingTrivia in token.LeadingTrivia) - { - retVal = retVal & ValidateTrivia(leadingTrivia, tree, filename, failures); - } - - foreach (var trailingTrivia in token.TrailingTrivia) - { - retVal = retVal & ValidateTrivia(trailingTrivia, tree, filename, failures); - } - - bool pass = false; - foreach (var rule in _tokenRules.Values) - { - var errorText = string.Empty; - pass = rule.Test(token, tree, ref errorText); - if (!pass) - { - if (failures != null) - { - failures.Add(new Failure(filename, rule, token.GetKind(), errorText, new FailureLocation(token.Span, tree))); - } - - ValidationFailed(errorText, rule); - } - - retVal = retVal & pass; - } - - return retVal; - } - - private bool ValidateTrivia(SyntaxTrivia trivia, SyntaxTree tree, string filename = "", List failures = null) - { - var retVal = true; - if (trivia.HasStructure) - { - retVal = retVal & ValidateNonTerminal(trivia.GetStructure(), tree, filename, failures); - } - - bool pass = false; - foreach (var rule in _triviaRules.Values) - { - var errorText = string.Empty; - pass = rule.Test(trivia, tree, ref errorText); - if (!pass) - { - if (failures != null) - { - failures.Add(new Failure(filename, rule, trivia.GetKind(), errorText, new FailureLocation(trivia.Span, tree))); - } - - ValidationFailed(errorText, rule); - } - - retVal = retVal & pass; - } - - return retVal; - } - - public bool Validate(SyntaxTree tree, string codeText, string filename, List failures = null) - { - var retVal = true; - if (!string.IsNullOrEmpty(filename)) - { - filename = Path.GetFullPath(filename); - } - else if (filename == null) - { - filename = string.Empty; - } - - if (_treeRules.Count > 0) - { - retVal = retVal & ValidateTree(tree, codeText, filename, failures); - } - - if (_nonTerminalRules.Count > 0) - { - retVal = retVal & ValidateNonTerminal(tree.GetRoot(), tree, filename, failures); - } - - return retVal; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/TriviaRuleAttribute.cs b/src/Compilers/Test/Utilities/Core2/TriviaRuleAttribute.cs deleted file mode 100644 index 1848ef71f69d97493bde8b7994753b0d603264b0..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/TriviaRuleAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class TriviaRuleAttribute : Attribute - { - public string Name - { - get; - set; - } - - public string Group - { - get; - set; - } - } -} diff --git a/src/Compilers/Test/Utilities/Core2/VBReflectionBasedKindProvider.cs b/src/Compilers/Test/Utilities/Core2/VBReflectionBasedKindProvider.cs deleted file mode 100644 index 04d0cf5a118fc764dc8a516b8483272a867e04e5..0000000000000000000000000000000000000000 --- a/src/Compilers/Test/Utilities/Core2/VBReflectionBasedKindProvider.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Reflection; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.Test.Utilities -{ - public class VBReflectionBasedKindProvider : ISyntaxNodeKindProvider - { - private const string VB_DLL = "Microsoft.CodeAnalysis.VisualBasic.dll"; - private const string VB_KIND_TYPE = "Roslyn.Compilers.VisualBasic.SyntaxKind"; - private Type _VBKindType; - private readonly string _folder; - - public VBReflectionBasedKindProvider(string folder) - { - _folder = Path.GetFullPath(folder); - GetKindTypes(); - } - - private void GetKindTypes() - { - if (_VBKindType == null) - { - var asm = Assembly.LoadFrom(Path.Combine(_folder, VB_DLL)); - _VBKindType = asm.GetType(VB_KIND_TYPE); - } - } - - private string GetKind(object o) - { - string kind = (string)o.GetType().GetProperty("Kind").GetValue(o, new object[] { }); - return Enum.Parse(_VBKindType, kind).ToString(); - } - - public string Kind(object node) - { - return GetKind(node); - } - } -} diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/SyntaxTreeRootTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/SyntaxTreeRootTests.vb index b7c91ea5d2087e49809a76709479f31b85c500be..5920ddc970cc5a8c8a101e906ffd859975dd4389 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/SyntaxTreeRootTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/SyntaxTreeRootTests.vb @@ -81,7 +81,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics End Sub Private Sub CheckTree(tree As SyntaxTree) -#If False Then +#If False Then ' https://github.com/dotnet/roslyn/issues/4453 CheckAllMembers( tree, New Dictionary(Of Type, Func(Of Object)) From diff --git a/src/Test/Utilities/TestUtilities.csproj b/src/Test/Utilities/TestUtilities.csproj index af705b25cda480bd218acf3eb274dff03267a33d..a987413338d07533dc54cf20a1efdcd3db24bc20 100644 --- a/src/Test/Utilities/TestUtilities.csproj +++ b/src/Test/Utilities/TestUtilities.csproj @@ -105,6 +105,12 @@ + + AbstractAnalyzerAssemblyLoader.cs + + + SimpleAnalyzerAssemblyLoader.cs + @@ -220,4 +226,4 @@ - + \ No newline at end of file