private void BuildPropertyDeclaration(string tcLine)
        {
            // the last word in this line is the name of the property
            tcLine = ReplaceManager.GetSingledSpacedString(tcLine).Trim();

            if (tcLine.EndsWith(")"))
            {
                int nEnd = tcLine.IndexOf("(");
                this.PropertyParameterToken = this.ExtractBlock(tcLine, "(", ")");
                FieldManager fm = new FieldManager();
                this.PropertyParameterToken = "(" + fm.GetConvertedExpression(this.PropertyParameterToken) + ") ";
                this.PropertyParameterToken = this.PropertyParameterToken.Replace("Dim ", "");
                tcLine = tcLine.Substring(0, nEnd).Trim();
            }

            int npos = tcLine.LastIndexOf(" ");

            this.PropertyNameToken = tcLine.Substring(npos + 1);
            string cDefinition = tcLine.Substring(0, npos).Trim();

            cDefinition = ReplaceManager.HandleModifiers(cDefinition);

            //A property has to return a value
            cDefinition           = cDefinition.Trim();
            npos                  = cDefinition.LastIndexOf(" ");
            this.ReturnValueToken = "As " + cDefinition.Substring(npos).Trim();
            cDefinition           = cDefinition.Substring(0, npos);

            this.PropertyModifiersToken = cDefinition;
        }
        public string GetBlock(string tcLine, string tcBlock)
        {
            this.GetBlankToken(tcLine);

            string cDeclaration = ReplaceManager.GetSingledSpacedString(tcLine);

            //Locate the colon in the enum and if so then the enum has a return type
            int npos = cDeclaration.LastIndexOf(":");

            if (npos > 0)
            {
                this.EnumReturnValue = "As " + cDeclaration.Substring(npos + 1).Trim();
                cDeclaration         = cDeclaration.Substring(0, npos).Trim();
            }

            //handle the appropriate conversions
            cDeclaration = ReplaceManager.HandleTypes(cDeclaration);

            //The last word is the name of the enumeration
            npos                      = cDeclaration.IndexOf(" ");
            this.EnumName             = cDeclaration.Substring(npos + 1);
            this.EnumDeclarationToken = cDeclaration.Substring(0, npos).Trim();

            //Replace any commas in the enum block with a next line + blank space
            this.EnumBlock = this.ExtractBlock(tcBlock, "{", "}").Replace(",", "\r\n" + this.BlankToken + "	");

            return(this.Execute());
        }
Exemple #3
0
        private void GetCondition(string tcLine)
        {
            string lcStr = this.ExtractBlock(tcLine, "(", ")");

            lcStr = ReplaceManager.GetSingledSpacedString(lcStr);

            //We assume that there will not be any spaces in between quotes and parenthesis when GetSingledSpaceString
            string[] aStr = lcStr.Split(' ');
            if (aStr.Length > 3)
            {
                //The first word in this is a declaration of the second word
                //foreach(              String x in MyArrayList             )
                FieldManager fm = new FieldManager();
                this.DeclarationToken = this.BlankToken + fm.GetConvertedExpression(aStr[0] + " " + aStr[1] + ";") + "\n";

                //Build the ConditionToken
                int npos = lcStr.IndexOf(" ");
                this.ConditionToken = lcStr.Substring(npos).Trim();
            }
            else
            {
                this.ConditionToken = lcStr.Trim();
            }

            this.ConditionToken = this.ConditionToken.Replace(" in ", " In ");
        }
        private void GetCondition(string tcLine)
        {
            tcLine = ((ConvertCSharp2VB.CSharpToVBConverter) this.oParent).HandleCasting(tcLine);
            string lcStr = this.ExtractBlock(tcLine, "(", ")");

            lcStr = ReplaceManager.GetSingledSpacedString(lcStr);

            this.ExpresionToken = ReplaceManager.HandleExpression(lcStr);
        }
        private void GetCatchToken(string tcCatchToken)
        {
            string sCatchToken = this.ExtractBlock(ReplaceManager.GetSingledSpacedString(tcCatchToken).Trim(), "(", ")").Trim();
            int    npos        = sCatchToken.IndexOf(" ");

            if (npos > 0)
            {
                FieldManager fm = new FieldManager();
                this.CatchToken = fm.GetConvertedExpression(sCatchToken + ";").Replace("Dim ", "Catch ");
            }
            else
            {
                this.CatchToken = "Catch";
            }
        }
Exemple #6
0
        private void GetCatchToken(string tcCatchToken)
        {
            string sCatchToken = ReplaceManager.GetSingledSpacedString(tcCatchToken).Trim();
            int    npos        = sCatchToken.IndexOf(" ");

            if (npos > 0)
            {
                FieldManager fm = new FieldManager();
                this.CatchToken = "Catch " + fm.GetConvertedExpression(sCatchToken.Substring(npos) + ";");
            }
            else
            {
                this.CatchToken = "Catch";
            }
        }
Exemple #7
0
        private void BuildClassDeclaration(string tcline)
        {
            tcline = tcline.Replace(":", " : ");
            tcline = ReplaceManager.GetSingledSpacedString(tcline);

            string cCurrent = "";
            string cParent  = "";
            int    npos     = tcline.IndexOf(":");

            if (npos > 0)
            {
                cCurrent = tcline.Substring(0, npos - 1);
                cParent  = tcline.Substring(npos).Trim();
            }
            else
            {
                cCurrent = tcline;
                cParent  = "";
            }

            cCurrent = ReplaceManager.HandleTypes(cCurrent);
            this.ClassDeclarationToken = cCurrent.Trim();

            int nClassPos = this.ClassDeclarationToken.LastIndexOf(" ");

            this.ClassNameToken = this.ClassDeclarationToken.Substring(nClassPos + 1);


            cParent = cParent.Replace(":", "").Trim();

            if (cParent.Length == 0)
            {
                return;
            }

            string[] aParent = cParent.Split(',');
            for (int i = 0; i < aParent.Length; i++)
            {
                string cParentClass    = aParent[i].Trim();
                string cImplementation = " Inherits ";
                if (cParentClass[0] == 'i' || cParentClass[0] == 'I')
                {
                    cImplementation = " Implements ";
                }

                this.ImplementationDeclationToken += "\n" + ((Char)9).ToString() + cImplementation + cParentClass;
            }
        }
Exemple #8
0
        public static string HandleExpression(string tcExpression)
        {
            // Get a single spaced version of the expression
            tcExpression = ReplaceManager.GetSingledSpacedString(tcExpression);

            // Remove any extra blank spaces from front and back
            tcExpression = tcExpression.Trim();

            // Special handling required for " is " keyword
            int nPos = tcExpression.IndexOf(" is ");

            if (nPos > 0)
            {
                tcExpression = "TypeOf " + tcExpression.Substring(0, nPos) + tcExpression.Substring(nPos);
                tcExpression = tcExpression.Replace(" is ", " Is ");
            }

            // Special handling required for null
            if (tcExpression.EndsWith("null"))
            {
                // Check if it is a valid null
                string lcExpression = tcExpression.Replace("!=", "!= ");
                lcExpression = lcExpression.Replace("==", "== ");
                if (lcExpression.EndsWith(" null"))
                {
                    tcExpression = lcExpression;
                    tcExpression = tcExpression.Replace(" null", " Nothing");

                    // Handle positive/negative pattern
                    if (tcExpression.IndexOf("!=") > 0)
                    {
                        tcExpression = tcExpression.Replace("!=", " Is ");
                        tcExpression = "Not " + tcExpression;
                    }
                    else
                    {
                        tcExpression = tcExpression.Replace("==", " Is ");
                    }

                    // Get the single line version of this string
                    tcExpression = ReplaceManager.GetSingledSpacedString(tcExpression);
                }
            }

            return(tcExpression);
        }
Exemple #9
0
        public string GetConvertedExpression(string tcLine)
        {
            this.GetBlankToken(tcLine);

            this.ExtractModifiers(ref tcLine);

            //Leave the spaces in the front but fix the line
            tcLine = this.BlankToken + ReplaceManager.GetSingledSpacedString(tcLine);
            tcLine = tcLine.Replace("==", "=");
            tcLine = tcLine.Replace("=", " = ");

            //Add the appropriate token to the parenthesis in this string
            tcLine = this.CheckTokens(tcLine, '(', ')');
            tcLine = this.CheckTokens(tcLine, '[', ']');


            if (this.valid(tcLine) == true)
            {
                return(this.PopTokens(tcLine));
            }

            //If there is no spaces in the expression return as is
            if (tcLine.Trim().IndexOf(' ') < 0)
            {
                return(this.PopTokens(tcLine));
            }


            if (this.ModifierToken.Trim().Length == 0)
            {
                this.ModifierToken = "Dim ";
            }

            this.GetDataType(tcLine);
            return(this.PopTokens(this.Build()));
        }
Exemple #10
0
        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());
        }
        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) + " ";
            }
        }