private static InvocationContext CreateContextForMethod(string typeAndMethodName, SnippetCompiler snippet) { var nameParts = typeAndMethodName.Split('.'); var identifierPairs = snippet.IsCSharp() ? GetCSharpNodes() : GetVbNodes(); foreach (var(invocation, methodName) in identifierPairs) { var symbol = snippet.GetSymbol <IMethodSymbol>(invocation); if (symbol.Name == nameParts[1] && symbol.ContainingType.Name == nameParts[0]) { return(new InvocationContext(invocation, methodName, snippet.SemanticModel)); } } Assert.Fail($"Test setup error: could not find method call in test code snippet: {typeAndMethodName}"); return(null); IEnumerable <(SyntaxNode node, string name)> GetCSharpNodes() => snippet.GetNodes <CSharpSyntax.InvocationExpressionSyntax>() .Select(n => ((SyntaxNode)n, n.Expression.GetIdentifier()?.Identifier.ValueText)); IEnumerable <(SyntaxNode node, string name)> GetVbNodes() => snippet.GetNodes <VBSyntax.InvocationExpressionSyntax>() .Select(n => ((SyntaxNode)n, VisualBasicSyntaxHelper.GetIdentifier(n.Expression)?.Identifier.ValueText)); }
private static FieldAccessContext CreateContext <TSyntaxNodeType>(string testInput, string fieldName, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, true, language); var node = testCode.GetNodes <TSyntaxNodeType>().First(x => x.ToString() == fieldName); return(new FieldAccessContext(testCode.CreateAnalysisContext(node), fieldName)); }
private static PropertyAccessContext CreateContext <TSyntaxNodeType>(string testInput, string propertyName, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, false, language); var node = testCode.GetNodes <TSyntaxNodeType>().First(); return(new PropertyAccessContext(testCode.CreateAnalysisContext(node), propertyName)); }
private static PropertyAccessContext CreateContext <TSyntaxNodeType>(string testInput, string propertyName, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, false, language); var expression = testCode.GetNodes <TSyntaxNodeType>().First(); return(new PropertyAccessContext(expression, propertyName, testCode.SemanticModel)); }
private static InvocationContext CreateContext <TSyntaxNodeType>(string testInput, string methodName, AnalyzerLanguage language, int skip = 0) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, true, language); var invocationSyntaxNode = testCode.GetNodes <TSyntaxNodeType>().Skip(skip).First(); var context = new InvocationContext(invocationSyntaxNode, methodName, testCode.SemanticModel); return(context); }
private static ObjectCreationContext CreateContext <TSyntaxNodeType>(string testInput, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, false, language); var objectCreationSyntaxNode = testCode.GetNodes <TSyntaxNodeType>().First(); var context = new ObjectCreationContext(objectCreationSyntaxNode, testCode.SemanticModel); return(context); }
private static ElementAccessContext CreateContext <TSyntaxNodeType>(string testInput, int skip, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, true, language); var node = testCode.GetNodes <TSyntaxNodeType>().Skip(skip).First(); var context = new ElementAccessContext(testCode.CreateAnalysisContext(node)); return(context); }
private static ObjectCreationContext CreateContext <TSyntaxNodeType>(string testInput, AnalyzerLanguage language) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, true, language); var node = testCode.GetNodes <TSyntaxNodeType>().First(); var context = new ObjectCreationContext(testCode.CreateAnalysisContext(node)); return(context); }
private static BaseTypeContext CreateContext <TSyntaxNodeType>(string testInput, AnalyzerLanguage language, Func <TSyntaxNodeType, IEnumerable <SyntaxNode> > baseTypeNodes) where TSyntaxNodeType : SyntaxNode { var testCode = new SnippetCompiler(testInput, false, language); var node = testCode.GetNodes <TSyntaxNodeType>().Single(); return(new BaseTypeContext(testCode.CreateAnalysisContext(node), baseTypeNodes(node))); }