private string PaddedDeclaration(string declarationText, VBAParser.BlockStmtContext blockStmtContext) { if (blockStmtContext.TryGetPrecedingContext(out VBAParser.IndividualNonEOFEndOfStatementContext precedingEndOfStatement)) { if (precedingEndOfStatement.COLON() != null) { //You have been asking for it! return($"{declarationText} : "); } var labelContext = blockStmtContext.statementLabelDefinition(); if (labelContext != null) { var labelAsSpace = new string(' ', labelContext.GetText().Length); return($"{labelAsSpace}{blockStmtContext.whiteSpace()?.GetText()}{declarationText}{Environment.NewLine}"); } var precedingWhitespaces = precedingEndOfStatement.whiteSpace(); if (precedingWhitespaces != null && precedingWhitespaces.Length > 0) { return($"{declarationText}{Environment.NewLine}{precedingWhitespaces[0]?.GetText()}"); } return($"{declarationText}{Environment.NewLine}"); } //This is the very first statement. In the context of this refactoring, this should not happen since we move a declaration into or inside a method. //We will handle this edge-case nonetheless and return the result with the proper indentation for this special case. if (blockStmtContext.TryGetPrecedingContext(out VBAParser.WhiteSpaceContext startingWhitespace)) { return($"{declarationText}{Environment.NewLine}{startingWhitespace?.GetText()}"); } return($"{declarationText}{Environment.NewLine}"); }
private string FrontPadding(VBAParser.BlockStmtContext context) { var statementLabelContext = context.statementLabelDefinition(); if (statementLabelContext == null) { return(string.Empty); } var statementLabelTextAsWhitespace = ReplaceNonWhitespaceWithSpace(statementLabelContext.GetText()); var whitespaceContext = context.whiteSpace(); return(statementLabelTextAsWhitespace + (whitespaceContext?.GetText() ?? string.Empty)); }
public override void EnterBlockStmt([NotNull] VBAParser.BlockStmtContext context) { // there is a whitespace context here after the option of a statementLabel. // we need to account for that _results.Add(new CodeMetricsResult(0, 0, IndentationLevelFromWhitespace(context.whiteSpace()))); }