private void BuildMethodDeclaration(string tcLine) { //Locate the position of a colon and if we find it then break the method line and parent int nColon = tcLine.IndexOf(":"); if (nColon > 0) { this.MethodParentToken = tcLine.Substring(nColon + 1); tcLine = tcLine.Substring(0, nColon); //fix the MethodParentToken first [COMMENTED FOR NOW. NOT SURE IF REQUIRED] //string lcParameters = this.GetParameters(this.MethodParentToken); //int nEndPos = this.MethodParentToken.IndexOf("("); //this.MethodParentToken = this.MethodParentToken.Substring(0, nEndPos) + lcParameters; } //Break the method call into two parts // 1. Method definition // 2. Parameters passed // Let us get the parameters tcLine = ReplaceManager.GetSingledSpacedString(tcLine).Trim(); int nOpenParen = 0; int nClosedParen = 0; string cParameters = ""; string cDefinition = tcLine; int k; for (int i = tcLine.Length; 0 < i; i--) { k = i - 1; if (tcLine[k] == ')') { nClosedParen++; } if (tcLine[k] == '(') { nOpenParen++; } if (nOpenParen != 0 && nClosedParen != 0) { if (nOpenParen - nClosedParen == 0) { //Create the two seperate strings and exit out cDefinition = tcLine.Substring(0, k); cParameters = tcLine.Substring(k).Trim(); break; } } } this.ParameterToken = this.GetParameters(cParameters); //split the definition and if the length is two then add a private modifier as default cDefinition = ReplaceManager.GetSingledSpacedString(cDefinition); //safety purposes //Check for any modifiers in this string and if so then handle them string[] cTemp = cDefinition.Split(' '); if (cTemp.Length == 2) { //add a private modifier cDefinition = "private " + cDefinition; } //If we find a void in the definition part it is a Sub else a Function //In VB Sub do not return a value and Functions do return a value if (cDefinition.IndexOf("void ") >= 0) { this.MethodType = "Sub"; } cDefinition = " " + cDefinition.Trim() + " "; cDefinition = ReplaceManager.HandleModifiers(cDefinition); //The last word will always be the name of the method cDefinition = cDefinition.Trim(); int npos = cDefinition.LastIndexOf(" "); this.MethodNameToken = cDefinition.Substring(npos).Trim(); cDefinition = cDefinition.Substring(0, npos); //In this case the second last value will be the return value datatype of the method if (this.MethodType != "Sub") { npos = cDefinition.LastIndexOf(" "); if (npos >= 0) { this.ReturnValueToken = " As " + cDefinition.Substring(npos).Trim(); cDefinition = cDefinition.Substring(0, npos); } } //if(cDefinition.Length > 0) if (npos > 0) { this.MethodModifiersToken = cDefinition.Substring(0, npos) + " "; } }
public string GetBlock(string tcLine) { // Initialize the properties this.Initialize(); this.GetBlankToken(tcLine); //Check if the operation is ++ or -- int npos; tcLine = ReplaceManager.GetSingledSpacedString(tcLine); // Check for an equal sign in the variable block and if so, then this is the declaration int nEqualsPosition = tcLine.IndexOf("="); if (nEqualsPosition > 0) { // Capture the declaration string lcDeclaration = tcLine.Substring(0, nEqualsPosition); // Fix the declaration by passing it to the appropriate handler FieldManager fm = new FieldManager(); this.DeclarationBlock = fm.GetConvertedExpression(lcDeclaration).Replace(";", "") + " = "; tcLine = tcLine.Substring(nEqualsPosition + 1).Trim(); } // Verify that the expression has atleast a ++ or -- npos = tcLine.IndexOf("++"); if (npos < 0) { npos = tcLine.IndexOf("--"); if (npos < 0) { return(tcLine); } else { this.ExpressionBlock = "- 1"; } } else { this.ExpressionBlock = "+ 1"; } //best case scenario //Determine the expression part and update the variable block if (npos != 0) { //between this and the previous whitespace this.VariableBlock = tcLine.Substring(0, npos); } else { // Begin by removing the semicolon tcLine = tcLine.Replace(";", "").Trim(); // Check if there is extra space at the end left int nBlankPos = tcLine.IndexOf(" "); if (nBlankPos > 0) { // Extract all the padding and store it seperately this.PaddingBlock = tcLine.Substring(nBlankPos); tcLine = tcLine.Substring(0, nBlankPos); } this.VariableBlock = tcLine.Replace("++", "").Replace("--", "").Trim(); } // Update the declaration if (this.DeclarationBlock.Length == 0) { this.DeclarationBlock = this.VariableBlock + " = "; } return(this.Execute()); }