public void ProcessBeforeInterior(ITreeNode element) { if (IsNestingStatement(element)) { ComplexityScore += _nesting + 1; _nesting++; if (element is ICatchClause clause && clause.Filter != null) { ComplexityScore++; } } if (element is IGotoStatement || element is IBreakStatement || element is IContinueStatement || element is ICSharpStatement statement && IfStatementNavigator.GetByElse(statement) != null || element is IConditionalOrExpression && HasParent <IConditionalAndExpression>(element) || element is IConditionalAndExpression && HasParent <IConditionalOrExpression>(element) || element is ICSharpExpression expression && expression.HasRecursion(_element) || element is IConditionalOrExpression && !HasParent <IBinaryExpression>(element) || element is IConditionalAndExpression && !HasParent <IBinaryExpression>(element)) { ComplexityScore++; } if (element is ILambdaExpression || element is IAnonymousMethodExpression) { _nesting++; } }
private static bool IsNestingStatement(ITreeNode element) { return(element is IWhileStatement || element is ISwitchStatement || element is IDoStatement || element is IIfStatement ifStatement && IfStatementNavigator.GetByElse(ifStatement) == null || element is IForStatement || element is IForeachStatement || element is ICatchClause); }
private ITreeRange AdjustStatement(ITreeRange range, IJavaScriptStatement statement) { var ifStatementByThen = IfStatementNavigator.GetByThen(statement); if (ifStatementByThen != null) { if (ifStatementByThen.Else == null) { return(new TreeRange(ifStatementByThen, ifStatementByThen)); } if (!_executing) { return(range); } ifStatementByThen.ReplaceBy(ifStatementByThen.Else); return(null); } var ifStatementByElse = IfStatementNavigator.GetByElse(statement); if (ifStatementByElse != null) { if (ifStatementByElse.Then == null) { return(new TreeRange(ifStatementByElse, ifStatementByElse)); } if (!_executing) { return(range); } ifStatementByElse.SetElse(null); return(null); } var doStatement = DoStatementNavigator.GetByStatement(statement); if (doStatement != null) { return(new TreeRange(doStatement, doStatement)); } var whileStatement = WhileStatementNavigator.GetByStatement(statement); if (whileStatement != null) { return(new TreeRange(whileStatement, whileStatement)); } var forStatement = ForStatementNavigator.GetByStatement(statement); if (forStatement != null) { return(new TreeRange(forStatement, forStatement)); } var foreachStatement = ForeachStatementNavigator.GetByStatement(statement); if (foreachStatement != null) { return(new TreeRange(foreachStatement, foreachStatement)); } var withStatement = WithStatementNavigator.GetByStatement(statement); if (withStatement != null) { return(new TreeRange(withStatement, withStatement)); } return(range); }