Exemplo n.º 1
0
        public void Apply(BaseTypeDeclarationTranslation typeDeclarationTranslation)
        {
            TypeDeclarationTranslation outerMemberDeclaration =
                (TypeDeclarationTranslation)typeDeclarationTranslation.TravelUpNotMe(f => f is TypeDeclarationTranslation);

            if (outerMemberDeclaration == null)
            {
                return;
            }

            SyntaxListBaseTranslation syntaxListBaseTranslation = (SyntaxListBaseTranslation)typeDeclarationTranslation.Parent;

            syntaxListBaseTranslation.Remove(typeDeclarationTranslation);

            SyntaxListBaseTranslation outerSyntaxListBaseTranslation = (SyntaxListBaseTranslation)outerMemberDeclaration.Parent;
            var newNamespace = CreateNewNamespace(outerMemberDeclaration.Syntax.Identifier.ToString(), typeDeclarationTranslation);

            outerSyntaxListBaseTranslation.Add(newNamespace);
        }
Exemplo n.º 2
0
        private void HandleContinueInOuterLoop(LabeledStatementTranslation labeledStatement, int from, int to, SyntaxListBaseTranslation syntaxList)
        {
            var found = labeledStatement.TravelUpNotMe(f =>
                                                       f is WhileStatementTranslation ||
                                                       f is ForStatementTranslation ||
                                                       f is DoStatementTranslation);

            if (found == null)
            {
                return;
            }

            var root = labeledStatement.GetRootTranslation();

            var continueStatements = new List <ContinueStatementTranslation>();

            for (int i = from; i <= to; i++)
            {
                var syntax = syntaxList.SyntaxCollection[i];
                continueStatements.AddRange(root.ContinueStatements.Where(f => syntax.Syntax.Span.Contains(f.Syntax.Span)));
            }

            Random rd    = new Random(DateTime.Now.Millisecond + increment++);
            var    label = $"__Outer{rd.Next(100)}";

            if (found.Prefix != null && found.Prefix.EndsWith(":"))
            {
                label = found.Prefix.Substring(0, found.Prefix.Length - 1);
            }
            else
            {
                found.Prefix = $"{label}:" + found.Prefix;
            }


            foreach (var item in continueStatements)
            {
                item.SyntaxString = $"continue {label};";
            }
        }