private NativeMethods.FindSourceDefinitionsAndDetermineSymbolResult GetNode(SnapshotPoint point, Project project, string fileName) { Compiler compiler; try { compiler = compilerHost.Value.CreateCompiler(project); } catch (COMException) { return(null); } // Don't choke on metadata as source var sourceFile = compiler.SourceFiles[new FileName(fileName)]; var node = sourceFile.GetParseTree().FindLeafNode(CSharpLanguageUtilities.ToPosition(point)); if (node == null) { return(null); } var rNode = ParseTreeMatch.GetReferencedNode(node); if (rNode == null) { return(null); } return(NativeMethods.FindSourceDefinitionsAndDetermineSymbolFromParseTree((IDECompilation)compiler.GetCompilation(), null, rNode)); }
public void Test_queries_rule_can_parse_multiple(string query) { CmsqlParser parser = CreateParserForQuery(query); IParseTree tree = parser.queries(); ParseTreePattern pattern = parser.CompileParseTreePattern( "<query> <TERMINATOR> <query> <TERMINATOR> <query> <EOF>", CmsqlParser.RULE_queries); ParseTreeMatch match = pattern.Match(tree); match.Succeeded.Should().BeTrue(); }
public void Test_query_rule_can_parse_query_with_where_clause(string query) { CmsqlParser parser = CreateParserForQuery(query); IParseTree tree = parser.query(); ParseTreePattern pattern = parser.CompileParseTreePattern( "<selectClause> <fromClause> <whereClause>", CmsqlParser.RULE_query); ParseTreeMatch match = pattern.Match(tree); match.Succeeded.Should().BeTrue(); }
public void Test_conditon_rule_can_parse_not_equals_condition(string query) { CmsqlParser parser = CreateParserForQuery(query); IParseTree tree = parser.condition(); ParseTreePattern pattern = parser.CompileParseTreePattern( "<IDENTIFIER> <NOTEQUALS> <LITERAL>", CmsqlParser.RULE_condition); ParseTreeMatch match = pattern.Match(tree); match.Succeeded.Should().BeTrue(); }
public void Test_expression_rule_can_parse_condition(string query) { CmsqlParser parser = CreateParserForQuery(query); IParseTree tree = parser.expression(); ParseTreePattern pattern = parser.CompileParseTreePattern( "<expression>", CmsqlParser.RULE_expression); ParseTreeMatch match = pattern.Match(tree); match.Succeeded.Should().BeTrue(); }
public void Test_selectClause_rule_can_parse_valid_identifier(string identifier) { CmsqlParser parser = CreateParserForQuery($"select {identifier}"); IParseTree tree = parser.selectClause(); ParseTreePattern pattern = parser.CompileParseTreePattern( "<SELECT> <IDENTIFIER>", CmsqlParser.RULE_selectClause); ParseTreeMatch match = pattern.Match(tree); match.Succeeded.Should().BeTrue(); }
public static NativeMethods.FindSourceDefinitionsAndDetermineSymbolResult GetNode(SnapshotPoint point, Project project, string fileName) { var compiler = compilerHost.Value.CreateCompiler(project); var sourceFile = compiler.SourceFiles[new FileName(fileName)]; var node = sourceFile.GetParseTree().FindLeafNode(LanguageUtilities.ToCSharpPosition(point)); if (node == null) { return(null); } var rNode = ParseTreeMatch.GetReferencedNode(node); if (rNode == null) { return(null); } return(NativeMethods.FindSourceDefinitionsAndDetermineSymbolFromParseTree((IDECompilation)compiler.GetCompilation(), null, rNode)); }