/// <summary> /// Returns true when <paramref name="statement"/> is a call to a function <paramref name="functionName"/>. /// </summary> public static bool IsFunctionCallDeclaration(this IStatement statement, string functionName) { Contract.Requires(statement != null); // config statement is a special kind of statement declaration if (statement.Kind != SyntaxKind.ExpressionStatement) { return(false); } var expressionStatement = statement.As <IExpressionStatement>(); if (expressionStatement.Expression.Kind != SyntaxKind.CallExpression) { return(false); } var callExpression = expressionStatement.Expression.Cast <ICallExpression>(); var identifier = callExpression?.Expression.As <IIdentifier>(); if (identifier == null) { return(false); } return(identifier.Text == functionName); }
private static IDeclaration GetDeclaration(IStatement statement) { var declarationStatement = statement.As <IDeclarationStatement>(); if (declarationStatement != null) { return(declarationStatement); } var variableStatement = statement.As <IVariableStatement>(); if (variableStatement != null) { Assert.Equal(1, variableStatement.DeclarationList.Declarations.Count); var declaration = variableStatement.DeclarationList.Declarations[0]; return(declaration); } Assert.True(false); return(null); }