private IEnumerable <IMisc> CreateFromVariableDeclaration(
            VariableDeclarationSyntax syntax, SyntaxNode syntaxNode, IDom parent, SemanticModel model,
            Func <SyntaxNode, IDom, SemanticModel, RDomBaseVariable> makeNewDelegate)
        {
            var list        = new List <IMisc>();
            var declarators = syntax.Variables.OfType <VariableDeclaratorSyntax>();

            foreach (var decl in declarators)
            {
                var newItem = SetupNewVariable(VariableKind.Local,
                                               makeNewDelegate(decl, parent, model),
                                               syntax.Type, decl, parent, model);
                var rDomItem = newItem as IRoslynDom;
                list.Add(newItem);
                CreateFromWorker.StoreWhitespace(newItem, decl, LanguagePart.Current, WhitespaceLookup);
                if (decl.Initializer != null)
                {
                    var equalsClause = decl.Initializer;
                    newItem.Initializer = OutputContext.Corporation.CreateSpecial <IExpression>(equalsClause.Value, newItem, model).FirstOrDefault();
                    //newItem.Initializer = (IExpression)OutputContext.Corporation.Create(equalsClause.Value, newItem, model).FirstOrDefault();
                    CreateFromWorker.StandardInitialize(newItem.Initializer, decl, parent, model, OutputContext);
                    CreateFromWorker.StoreWhitespaceForToken(newItem, decl.Initializer.EqualsToken, LanguagePart.Current, LanguageElement.EqualsAssignmentOperator);
                    CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newItem, decl.Initializer, LanguagePart.Current, LanguageElement.Expression);
                }
            }
            return(list);
        }
        public IVariable SetupNewVariable(VariableKind variableKind, RDomBaseVariable newItem, TypeSyntax typeSyntax,
                                          SyntaxNode node, IDom parent, SemanticModel model)
        {
            CreateFromWorker.StandardInitialize(newItem, node, parent, model, OutputContext);
            newItem.Name = newItem.TypedSymbol.Name;
            var declaredType = typeSyntax.ToString();
            var returnType   = OutputContext.Corporation
                               .Create(typeSyntax, newItem, model)
                               .FirstOrDefault()
                               as IReferencedType;

            newItem.Type         = returnType;
            newItem.VariableKind = variableKind;

            newItem.IsImplicitlyTyped = (declaredType == "var");
            if (!newItem.IsImplicitlyTyped &&
                newItem.Type.TypeArguments.Count() == 0 &&
                declaredType != newItem.Type.Name)
            {
                var test = Mappings.AliasFromSystemType(newItem.Type.Name);
                if (declaredType == test)
                {
                    newItem.IsAliased = true;
                }
            }
            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ParameterSyntax;
            var newItem = new RDomParameter(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);

            newItem.Name = newItem.TypedSymbol.Name;

            // TODO: Determine if null types for anonymous methods are a fact of life, or a temporary bug
            if (syntax.Type != null)
            {
                var type = OutputContext.Corporation
                           .Create(syntax.Type, newItem, model)
                           .FirstOrDefault()
                           as IReferencedType;
                newItem.Type = type;
            }

            newItem.IsOut        = newItem.TypedSymbol.RefKind == RefKind.Out;
            newItem.IsRef        = newItem.TypedSymbol.RefKind == RefKind.Ref;
            newItem.IsParamArray = newItem.TypedSymbol.IsParams;
            newItem.IsOptional   = newItem.TypedSymbol.IsOptional;
            if (syntax.Default != null)
            {
                var tuple = CreateFromWorker.GetArgumentValue(newItem, model, syntax.Default.Value);
                newItem.DefaultValue = tuple.Item1;
                newItem.DefaultConstantIdentifier = tuple.Item2;
                newItem.DefaultValueType          = tuple.Item3;
            }
            newItem.Ordinal = newItem.TypedSymbol.Ordinal;
            MemberWhitespace(newItem, syntax);

            return(newItem);
        }
示例#4
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as OperatorDeclarationSyntax;
            var newItem = new RDomOperator(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Body, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Body, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.ParameterList, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = newItem.TypedSymbol.Name;

            var returnType = OutputContext.Corporation
                             .Create(syntax.ReturnType, newItem, model)
                             .FirstOrDefault()
                             as IReferencedType;

            newItem.Type = returnType;

            newItem.Operator = Mappings.OperatorFromCSharpKind(syntax.OperatorToken.Kind());

            newItem.Parameters.CreateAndAdd(syntax, x => x.ParameterList.Parameters, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IParameter>());
            //var parameters = ListUtilities.MakeList(syntax, x => x.ParameterList.Parameters, x => Corporation.Create(x, newItem, model))
            //                             .OfType<IParameter>();
            //newItem.Parameters.AddOrMoveRange(parameters);

            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as AttributeArgumentSyntax;
            var newItem = new RDomAttributeValue(syntaxNode, parent, model);

            InitializeAttributeValue(newItem, syntax, model);
            CreateFromWorker.StandardInitialize(newItem, syntax, parent, model, OutputContext);
            StoreWhitespace(newItem, syntax);
            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ContinueStatementSyntax;
            var newItem = new RDomContinueStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ConstructorDeclarationSyntax;
            var newItem = new RDomConstructor(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Body, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Initializer, LanguagePart.Initializer, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Body, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.ParameterList, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = newItem.TypedSymbol.Name;

            //newItem.AccessModifier = RoslynUtilities.GetAccessibilityFromSymbol(newItem.Symbol);
            //newItem.IsStatic = newItem.Symbol.IsStatic;

            newItem.Parameters.CreateAndAdd(syntax, x => x.ParameterList.Parameters, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IParameter>());
            //var parameters = ListUtilities.MakeList(syntax, x => x.ParameterList.Parameters, x => Corporation.Create(x, newItem, model))
            //                    .OfType<IParameter>();
            //newItem.Parameters.AddOrMoveRange(parameters);


            if (syntax.Initializer == null)
            {
                newItem.ConstructorInitializerType = ConstructorInitializerType.None;
            }
            else
            {
                var initializerSyntax = syntax.Initializer;
                if (initializerSyntax.ThisOrBaseKeyword.ToString() == "this")
                {
                    newItem.ConstructorInitializerType = ConstructorInitializerType.This;
                }
                else
                {
                    newItem.ConstructorInitializerType = ConstructorInitializerType.Base;
                }
                CreateFromWorker.StoreWhitespace(newItem, initializerSyntax.ArgumentList,
                                                 LanguagePart.Initializer, WhitespaceLookup);
                foreach (var arg in initializerSyntax.ArgumentList.Arguments)
                {
                    var newArg = new RDomArgument(arg, newItem, model);

                    // TODO: Named paramters and align this with the invocation factory
                    newArg.ValueExpression = OutputContext.Corporation.CreateSpecial <IExpression>(arg.Expression, newItem, model).FirstOrDefault();
                    CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newArg, arg, LanguagePart.Current, LanguageElement.ConstructorInitializerArgument);
                    CreateFromWorker.StoreListMemberWhitespace(arg,
                                                               SyntaxKind.CommaToken, LanguageElement.ConstructorInitializerArgument, newArg);
                    newItem.InitializationArguments.AddOrMove(newArg);
                }
            }

            return(newItem);
        }
示例#8
0
        protected override IEnumerable <IDom> CreateListFromInterim(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as StructDeclarationSyntax;
            var newItem = new RDomStructure(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, whitespaceLookup);

            newItem.MembersAll.CreateAndAdd(syntax, x => x.Members, x => OutputContext.Corporation.Create(x, newItem, model).Cast <ITypeMemberAndDetail>());

            return(new IDom[] { newItem });
        }
示例#9
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as TryStatementSyntax;
            var newItem = new RDomTryStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Block, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Block, LanguagePart.Current, WhitespaceLookup);

            var catchSyntaxList = syntax.ChildNodes()
                                  .Where(x => x.CSharpKind() == SyntaxKind.CatchClause)
                                  .OfType <CatchClauseSyntax>();

            foreach (var ctch in catchSyntaxList)
            {
                var newCatch = new RDomCatchStatement(ctch, newItem, model);
                CreateFromWorker.StandardInitialize(newCatch, ctch, newItem, model, OutputContext);
                CreateFromWorker.InitializeStatements(newCatch, ctch.Block, newCatch, model);
                CreateFromWorker.StoreWhitespace(newCatch, ctch, LanguagePart.Current, WhitespaceLookup);
                CreateFromWorker.StoreWhitespace(newCatch, ctch.Block, LanguagePart.Current, WhitespaceLookup);
                if (ctch.Declaration != null)
                {
                    var type = OutputContext.Corporation
                               .Create(ctch.Declaration.Type, newCatch, model)
                               .FirstOrDefault()
                               as IReferencedType;
                    newCatch.ExceptionType = type;
                    CreateFromWorker.StoreWhitespace(newCatch, ctch.Declaration, LanguagePart.Current, WhitespaceLookup);
                    if (!string.IsNullOrWhiteSpace(ctch.Declaration.Identifier.ToString()))
                    {
                        newCatch.Variable      = OutputContext.Corporation.Create(ctch.Declaration, newCatch, model).FirstOrDefault() as IVariableDeclaration;
                        newCatch.Variable.Type = type;
                    }
                }
                if (ctch.Filter != null)
                {
                    newCatch.Condition = OutputContext.Corporation.CreateSpecial <IExpression>(ctch.Filter.FilterExpression, newCatch, model).FirstOrDefault();
                    CreateFromWorker.StoreWhitespace(newCatch.Condition, ctch.Filter, LanguagePart.Current, WhitespaceLookup);
                }
                newItem.CatchesAll.AddOrMove(newCatch);
            }
            if (syntax.Finally != null)
            {
                var newFinally = new RDomFinallyStatement(syntax.Finally, newItem, model);
                CreateFromWorker.StandardInitialize(newFinally, syntax.Finally, parent, model, OutputContext);
                CreateFromWorker.InitializeStatements(newFinally, syntax.Finally.Block, newFinally, model);
                CreateFromWorker.StoreWhitespace(newFinally, syntax.Finally, LanguagePart.Current, WhitespaceLookup);
                CreateFromWorker.StoreWhitespace(newFinally, syntax.Finally.Block, LanguagePart.Current, WhitespaceLookup);
                newItem.Finally = newFinally;
            }
            return(newItem);
        }
示例#10
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as DestructorDeclarationSyntax;
            var newItem = new RDomDestructor(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Body, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = newItem.TypedSymbol.Name;

            return(newItem);
        }
示例#11
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax = syntaxNode as NamespaceDeclarationSyntax;
            // TODO: I think there is a better way to do this, but I can't find it right now
            var names = syntax.Name.ToString().Split(new char[] { '.' });
            var group = Guid.Empty;

            if (names.Count() > 1)
            {
                group = Guid.NewGuid();
            }
            RDomNamespace item           = null;
            RDomNamespace outerNamespace = null;

            foreach (var name in names)
            {
                var newItem = new RDomNamespace(syntaxNode, parent, model, name, group);
                CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
                CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

                // At this point, item is the last newItem
                if (item != null)
                {
                    item.StemMembersAll.AddOrMove(newItem);
                }
                item = newItem;
                if (outerNamespace == null)
                {
                    outerNamespace = item;
                }
                if (name != names.Last())
                {
                    parent = item;
                }
            }

            // Qualified name unbundles namespaces, and if it's defined together, we want it together here.
            // Thus, this replaces hte base Initialize name with the correct one
            if (item.Name.StartsWith("@"))
            {
                item.Name = item.Name.Substring(1);
            }
            CreateFromWorker.LoadStemMembers(item, syntax.Members, syntax.Usings, model);

            HandleTrailingTrivia(syntax, model, item);

            // This will return the outer namespace, which in the form N is the only one.
            // In the form N1.N2.. there is a nested level for each part (N1, N2).
            // The inner holds the children, the outer is returned.
            return(outerNamespace);
        }
示例#12
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as CheckedStatementSyntax;
            var newItem = new RDomCheckedStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Block, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Block, LanguagePart.Current, WhitespaceLookup);

            newItem.Unchecked = (syntax.CSharpKind() == SyntaxKind.UncheckedStatement);

            return(newItem);
        }
示例#13
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ExpressionStatementSyntax;
            var newItem = new RDomInvocationStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newItem, syntax, LanguagePart.Current,
                                                                 LanguageElement.Expression);

            var expression = syntax.Expression;

            //newItem.Invocation = (IInvocationExpression)OutputContext.Corporation.Create<IExpression>(expression, newItem, model).FirstOrDefault();
            newItem.Invocation = OutputContext.Corporation.Create(expression, newItem, model).FirstOrDefault() as IInvocationExpression;
            return(newItem);
        }
示例#14
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ThrowStatementSyntax;
            var newItem = new RDomThrowStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

            if (syntax.Expression != null)
            {
                var expression = OutputContext.Corporation.CreateSpecial <IExpression>(syntax.Expression, newItem, model).FirstOrDefault();
                newItem.ExceptionExpression = expression;
            }

            return(newItem);
        }
示例#15
0
        private void UpdateItem <T>(T newItem, StatementSyntax statement, ExpressionSyntax condition,
                                    SyntaxNode syntax, IDom parent, SemanticModel model)
            where T : class, IDom, IStatementBlock
        {
            CreateFromWorker.StandardInitialize(newItem, syntax, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, statement, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, statement, LanguagePart.Current, WhitespaceLookup);
            var itemAsHasCondition = newItem as IHasCondition;

            if (itemAsHasCondition != null)
            {
                itemAsHasCondition.Condition = OutputContext.Corporation.CreateSpecial <IExpression>(condition, newItem, model).FirstOrDefault();
                CreateFromWorker.StoreWhitespace(itemAsHasCondition, condition, LanguagePart.Current, WhitespaceLookup);
            }
        }
示例#16
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as BlockSyntax;
            var newItem = new RDomBlockStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

            foreach (var statementSyntax in syntax.Statements)
            {
                var statements = OutputContext.Corporation.Create(statementSyntax, newItem, model).OfType <IStatementAndDetail>();
                newItem.Statements.AddOrMoveRange(statements);
            }

            return(newItem);
        }
示例#17
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as UsingDirectiveSyntax;
            var newItem = new RDomUsingDirective(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = syntax.Name.NameFrom();
            if (syntax.Alias != null)
            {
                newItem.Alias = syntax.Alias.ToString().Replace("=", "").Trim();
            }

            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as EnumMemberDeclarationSyntax;
            var newItem = new RDomEnumMember(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            MemberWhitespace(newItem, syntax);

            newItem.Name = syntax.Identifier.ToString();
            if (syntax.EqualsValue != null)
            {
                newItem.Expression = OutputContext.Corporation.CreateSpecial <IExpression>(syntax.EqualsValue.Value, newItem, model).FirstOrDefault();
            }
            return(newItem);
        }
示例#19
0
        protected override IEnumerable <IDom> CreateListFromInterim(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as EnumDeclarationSyntax;
            var newItem = new RDomEnum(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, whitespaceLookup);

            InitializeBaseList(syntax, newItem, model, CreateFromWorker, OutputContext.Corporation);

            newItem.Members.CreateAndAdd(syntax, x => x.Members, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IEnumMember>());
            //var members = ListUtilities.MakeList(syntax, x => x.Members, x => corporation.Create(x, newItem, model))
            //                .OfType<IEnumMember>();
            //newItem.Members.AddOrMoveRange(members);

            return(new IDom[] { newItem });
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ReturnStatementSyntax;
            var newItem = new RDomReturnStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);


            if (syntax.Expression != null)
            {
                newItem.Return = OutputContext.Corporation.CreateSpecial <IExpression>(syntax.Expression, newItem, model).FirstOrDefault();
                Guardian.Assert.IsNotNull(newItem.Return, nameof(newItem.Return));
            }

            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ConstructorDeclarationSyntax;
            var newItem = new RDomConstructor(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Body, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Initializer, LanguagePart.Initializer, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Body, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.ParameterList, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = newItem.TypedSymbol.Name;

            //newItem.AccessModifier = RoslynUtilities.GetAccessibilityFromSymbol(newItem.Symbol);
            //newItem.IsStatic = newItem.Symbol.IsStatic;

            newItem.Parameters.CreateAndAdd(syntax, x => x.ParameterList.Parameters, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IParameter>());
            //var parameters = ListUtilities.MakeList(syntax, x => x.ParameterList.Parameters, x => Corporation.Create(x, newItem, model))
            //                    .OfType<IParameter>();
            //newItem.Parameters.AddOrMoveRange(parameters);


            if (syntax.Initializer == null)
            {
                newItem.ConstructorInitializerType = ConstructorInitializerType.None;
            }
            else
            {
                var initializerSyntax = syntax.Initializer;
                if (initializerSyntax.ThisOrBaseKeyword.ToString() == "this")
                {
                    newItem.ConstructorInitializerType = ConstructorInitializerType.This;
                }
                else
                {
                    newItem.ConstructorInitializerType = ConstructorInitializerType.Base;
                }

                newItem.InitializationArguments.CreateAndAdd(syntax, x => x.Initializer.ArgumentList.Arguments, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IArgument>());
                CreateFromWorker.StoreWhitespace(newItem, initializerSyntax.ArgumentList, LanguagePart.Initializer, WhitespaceLookup);
            }

            return(newItem);
        }
示例#22
0
        protected override IEnumerable <IDom> CreateListFromInterim(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ClassDeclarationSyntax;
            var newItem = new RDomClass(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, whitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.TypeParameterList, LanguagePart.Current, whitespaceLookup);

            newItem.MembersAll.CreateAndAdd(syntax, x => x.Members, x => OutputContext.Corporation.Create(x, newItem, model).Cast <ITypeMemberAndDetail>());

            newItem.IsAbstract = newItem.Symbol.IsAbstract;
            newItem.IsSealed   = newItem.Symbol.IsSealed;
            newItem.IsStatic   = newItem.Symbol.IsStatic;
            newItem.IsPartial  = syntax.Modifiers.Contains(SyntaxFactory.Token(SyntaxKind.PartialKeyword));

            return(new IDom[] { newItem });
        }
示例#23
0
        protected override IEnumerable <IDom> CreateListFromInterim(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as InterfaceDeclarationSyntax;
            var newItem = new RDomInterface(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, whitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.TypeParameterList, LanguagePart.Current, whitespaceLookup);

            newItem.MembersAll.CreateAndAdd(syntax, x => x.Members, x => OutputContext.Corporation.Create(x, newItem, model).Cast <ITypeMemberAndDetail>());
            // this is a hack because the membersare appearing with a scope
            foreach (var member in newItem.MembersAll.OfType <ITypeMember>())
            {
                member.AccessModifier = AccessModifier.None;
            }

            return(new IDom[] { newItem });
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var typeParameterSyntax = syntaxNode as TypeParameterSyntax;

            if (typeParameterSyntax != null)
            {
                throw new NotImplementedException("Should have called TypeParameterFactory");
            }
            var        baseTypeSyntax = syntaxNode as BaseTypeSyntax;
            TypeSyntax typeSyntax     = null;

            if (baseTypeSyntax != null)
            {
                typeSyntax = baseTypeSyntax.Type;
            }
            else
            {
                typeSyntax = syntaxNode as TypeSyntax;
            }
            if (typeSyntax != null)
            {
                var newItem = new RDomReferencedType(typeSyntax, parent, model);

                CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
                StoreWhitespace(typeSyntax, newItem);

                CreateTypeArgs(syntaxNode, model, newItem);

                var arrayTypeSyntax = syntaxNode as ArrayTypeSyntax;
                if (arrayTypeSyntax != null)
                {
                    newItem.IsArray = true;
                    var arraySymbol = newItem.Symbol as IArrayTypeSymbol;
                    InitalizeNameAndNamespace(newItem, arraySymbol.ElementType, arrayTypeSyntax.ElementType);
                }
                else
                {
                    newItem.IsArray = false;
                    InitalizeNameAndNamespace(newItem, newItem.Symbol, typeSyntax);
                }
                return(newItem);
            }
            throw new InvalidOperationException();
        }
示例#25
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as UsingStatementSyntax;
            var newItem = new RDomUsingStatement(syntaxNode, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Statement, newItem, model);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Statement, LanguagePart.Current, WhitespaceLookup);
            // if there is both a declaration and an expression, I'm terribly confused
            var declaration = syntax.Declaration;
            var expression  = syntax.Expression;

            if (declaration != null && expression != null)
            {
                throw new InvalidOperationException();
            }
            if (declaration == null && expression == null)
            {
                throw new InvalidOperationException();
            }
            var statement = syntax.Statement;

            if (declaration != null)
            {
                // Not yet, and might never support as Kendall Miller said "huh, that works?" on Twitter
                if (declaration.Variables.Count() > 1)
                {
                    throw new NotImplementedException();
                }

                var newVariable = OutputContext.Corporation.Create(syntax.Declaration, newItem, model).FirstOrDefault();
                newItem.Variable = (IVariableDeclaration)newVariable;
            }
            else
            {
                var expr = OutputContext.Corporation.CreateSpecial <IExpression>(syntax.Expression, newItem, model).FirstOrDefault();
                CreateFromWorker.StoreWhitespace(expr, syntax.Expression, LanguagePart.Current, WhitespaceLookup);
                newItem.Expression = expr;
            }

            return(newItem);
        }
示例#26
0
        protected override IEnumerable <IDom> CreateListFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var list = new List <ITypeMember>();

            //var fieldPublicAnnotations = CreateFromWorker.GetPublicAnnotations(syntaxNode, parent, model);
            var rawField    = syntaxNode as FieldDeclarationSyntax;
            var declarators = rawField.Declaration.Variables.OfType <VariableDeclaratorSyntax>();

            foreach (var decl in declarators)
            {
                var newItem = new RDomField(decl, parent, model);
                list.Add(newItem);
                CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
                CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, WhitespaceLookup);
                CreateFromWorker.StoreWhitespace(newItem, decl, LanguagePart.Current, WhitespaceLookup);

                newItem.Name = newItem.TypedSymbol.Name;

                if (decl.Initializer != null)
                {
                    CreateFromWorker.StoreWhitespaceForToken(newItem, decl.Initializer.EqualsToken, LanguagePart.Current, LanguageElement.EqualsAssignmentOperator);
                    CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newItem, decl.Initializer, LanguagePart.Current, LanguageElement.Expression);
                    newItem.Initializer = OutputContext.Corporation.CreateSpecial <IExpression>(decl.Initializer.Value, newItem, model).FirstOrDefault();
                }

                var returnType = OutputContext.Corporation
                                 .Create(rawField.Declaration.Type, newItem, model)
                                 .FirstOrDefault()
                                 as IReferencedType;
                newItem.ReturnType = returnType;

                var fieldSymbol = newItem.Symbol as IFieldSymbol;
                newItem.IsStatic   = fieldSymbol.IsStatic;
                newItem.IsVolatile = fieldSymbol.IsVolatile;
                newItem.IsReadOnly = fieldSymbol.IsReadOnly;
                newItem.IsConstant = fieldSymbol.HasConstantValue;
                // See note on IsNew on interface before changing
                newItem.IsNew = rawField.Modifiers.Any(x => x.Kind() == SyntaxKind.NewKeyword);
                //newItem.PublicAnnotations.Add(fieldPublicAnnotations);
            }
            return(list);
        }
示例#27
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax         = syntaxNode as AccessorDeclarationSyntax;
            var parentProperty = parent as IProperty;
            var accessorType   = (syntaxNode.Kind() == SyntaxKind.GetAccessorDeclaration)
                             ? AccessorType.Get : AccessorType.Set;
            var newItem = new RDomPropertyAccessor(syntaxNode, accessorType, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.InitializeStatements(newItem, syntax.Body, newItem, model);

            CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Body, LanguagePart.Current, WhitespaceLookup);

            var newItemName = accessorType.ToString().ToLower() + "_" + parentProperty.Name;

            newItem.Name = newItemName;

            return(newItem);
        }
示例#28
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as ArgumentSyntax;
            var newItem = new RDomArgument(syntax, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);

            newItem.ValueExpression = OutputContext.Corporation.CreateSpecial <IExpression>(syntax.Expression, newItem, model).FirstOrDefault();
            newItem.IsOut           = syntax.ChildTokens().Any(x => x.Kind() == SyntaxKind.OutKeyword);
            newItem.IsRef           = syntax.ChildTokens().Any(x => x.Kind() == SyntaxKind.RefKeyword);
            if (syntax.NameColon != null)
            {
                newItem.Name = syntax.NameColon.Name.ToString();
            }

            CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newItem, syntax, LanguagePart.Current, LanguageElement.OutModifier);
            CreateFromWorker.StoreWhitespaceForFirstAndLastToken(newItem, syntax, LanguagePart.Current, LanguageElement.RefModifier);

            MemberWhitespace(newItem, syntax);
            return(newItem);
        }
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax    = syntaxNode as TSyntax;
            var newItem   = MakeNewItem(syntax, parent, model);
            var condition = GetConditionFromSyntax(syntax);
            var statement = GetStatementFromSyntax(syntax);

            var conditionObj = OutputContext.Corporation.CreateSpecial <IExpression>(condition, newItem, model).FirstOrDefault();

            newItem.Condition = conditionObj as IExpression;
            CreateFromWorker.InitializeStatements(newItem, statement, newItem, model);

            Guardian.Assert.IsNotNull(condition, nameof(condition));

            CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, statement, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, condition, LanguagePart.Current, WhitespaceLookup);

            return(newItem);
        }
示例#30
0
        private IAttribute CreateFromItem(AttributeSyntax syntax, IDom parent, SemanticModel model)
        {
            var newItem = new RDomAttribute(syntax, parent, model);

            CreateFromWorker.StandardInitialize(newItem, syntax, parent, model, OutputContext);
            CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Parent, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.ArgumentList, LanguagePart.Current, WhitespaceLookup);
            CreateFromWorker.StoreWhitespace(newItem, syntax.Name, LanguagePart.Current, WhitespaceLookup);

            newItem.Name = syntax.Name.ToString();

            if (syntax.ArgumentList != null)
            {
                newItem.AttributeValues.CreateAndAdd(syntax, x => x.ArgumentList.Arguments, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IAttributeValue>());
                //var values = ListUtilities.MakeList(syntax, x => x.ArgumentList.Arguments, x => Corporation.Create(x, newItem, model))
                //      .OfType<IAttributeValue>();
                //  foreach (var value in values)
                //  { newItem.AddOrMoveAttributeValue(value); }
            }
            return(newItem);
        }