public void Finds_variable_origins_to_be_local_declaration() { var codeAsText = File.ReadAllText(@"SyntaxAnalyserExamples/TestFunctions.cs"); var syntaxTree = SyntaxOperations.Parse(codeAsText); var semanticModel = SemanticOperations.GetSemanticModel(syntaxTree); var methodSyntax = SyntaxOperations .FindMethodsOfClass(syntaxTree, nameof(TestFunctions), nameof(TestFunctions.DoublesParameter)) .Value .Single(); var methodAnalysis = MethodBlockAnalysis.FromSemanticModel(methodSyntax, semanticModel); var returnSyntax = methodAnalysis.BodyBlock.DescendantNodes().OfType <ReturnStatementSyntax>().Single(); var identSyntax = SyntaxOperations.GetVariable(returnSyntax); var origin = SemanticOperations.GetIdentifierDeclarationSyntax(identSyntax, methodAnalysis).Value.A; var localDeclarSyntax = origin.A; var variableName = SyntaxOperations.GetVariableTokenSingle(localDeclarSyntax).ToString(); Assert.AreEqual("res", variableName); }
private IXor2ComputationNodeReference _Assert_LocalDeclaration(ComputationGraphNode node, string variableName) { var localDecl = (LocalDeclarationStatementSyntax)node.Syntax; var varName = SyntaxOperations.GetVariableTokenSingle(localDecl).ToString(); Assert.AreEqual(variableName, varName); return(node.MainAntedecent.Value); }