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); }
private void MemberWhitespace(RDomParameter newItem, ParameterSyntax syntax) { CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetFirstToken(), LanguagePart.Current, LanguageElement.ParameterFirstToken); CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetLastToken(), LanguagePart.Current, LanguageElement.ParameterLastToken); CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup); if (syntax.Default != null) { CreateFromWorker.StoreWhitespace(newItem, syntax.Default, LanguagePart.Current, WhitespaceLookup); //CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.Default.Value.GetLastToken(), LanguagePart.Current, LanguageElement.Identifier); //CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.Default.EqualsToken, LanguagePart.Current, LanguageElement.ParameterDefaultAssignOperator); } CreateFromWorker.StoreListMemberWhitespace(syntax, WhitespaceLookup.Lookup(LanguageElement.ParameterSeparator), LanguageElement.ParameterFirstToken, newItem); //var prevNodeOrToken = syntax.Parent // .ChildNodesAndTokens() // .PreviousSiblings(syntax) // .LastOrDefault(); //var sepKind = WhitespaceLookup.Lookup(LanguageElement.ParameterSeparator); //if (prevNodeOrToken.CSharpKind() == sepKind) //{ // var commaToken = prevNodeOrToken.AsToken(); // var whitespace2 = newItem.Whitespace2Set[LanguageElement.ParameterFirstToken]; // if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace)) // { whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString(); } //} }
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); }
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); }
private void MemberWhitespace(RDomArgument newItem, ArgumentSyntax syntax) { CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetFirstToken(), LanguagePart.Current, LanguageElement.ParameterFirstToken); CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetLastToken(), LanguagePart.Current, LanguageElement.ParameterLastToken); CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup); CreateFromWorker.StoreListMemberWhitespace(syntax, WhitespaceLookup.Lookup(LanguageElement.ParameterSeparator), LanguageElement.ParameterFirstToken, 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); }
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 }); }
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); }
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); }
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); }
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); }
protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model) { var syntax = syntaxNode as InvocationExpressionSyntax; var newItem = new RDomInvocationExpression(syntaxNode, parent, model); newItem.InitialExpressionString = syntax.ToString(); newItem.InitialExpressionLanguage = ExpectedLanguages.CSharp; newItem.MethodName = GetMethodName(syntax.Expression.ToString()); newItem.TypeArguments.AddOrMoveRange(GetTypeArguments(syntax.Expression, newItem, model)); newItem.Arguments.CreateAndAdd(syntax, x => x.ArgumentList.Arguments, x => OutputContext.Corporation.Create(x, newItem, model).Cast <IArgument>()); CreateFromWorker.StoreWhitespace(newItem, syntax.ArgumentList, LanguagePart.Initializer, WhitespaceLookup); return(newItem); }
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); } }
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); }
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); }
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); }
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 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 IEnumerable <IDom> CreateListFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model) { var list = new List <IStatementAndDetail>(); var rawDeclaration = syntaxNode as LocalDeclarationStatementSyntax; // VariableDeclarationFactory does most of the work, and at present returns a single // DeclarationStatement, and possibly a comment var newItems = OutputContext.Corporation.Create(rawDeclaration.Declaration, parent, model, true); foreach (var newItem in newItems.OfType <IDeclarationStatement>()) { CreateFromWorker.StoreWhitespace(newItem, syntaxNode, LanguagePart.Current, WhitespaceLookup); newItem.IsConst = rawDeclaration.IsConst; } list.AddRange(newItems.OfType <IStatementAndDetail>()); return(list); }
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); }
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 }); }
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 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); }
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); }
private void MemberWhitespace(RDomTypeParameter newItem, TypeParameterSyntax syntax) { CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup); CreateFromWorker.StoreListMemberWhitespace(syntax, SyntaxKind.CommaToken, LanguageElement.Identifier, newItem); //var whitespace2 = newItem.Whitespace2Set[LanguageElement.Identifier]; //if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace)) //{ // var prevNodeOrToken = syntax.Parent // .ChildNodesAndTokens() // .PreviousSiblings(syntax) // .LastOrDefault(); // var sepKind = SyntaxKind.CommaToken; // if (prevNodeOrToken.Kind() == sepKind) // { // var commaToken = prevNodeOrToken.AsToken(); // whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString(); // } //} }
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); }
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); }
private void InitializeConstraints(TypeParameterSyntax syntax, RDomTypeParameter newItem, SemanticModel model, string name) { // parent is type parameter list. Parent parent contains constraints var syntaxParent = syntax.Parent.Parent; var constraintClauses = syntaxParent.ChildNodes() .OfType <TypeParameterConstraintClauseSyntax>() .ToList(); var constraintClause = constraintClauses .Where(x => x.Name.ToString() == name) .FirstOrDefault(); if (constraintClause != null) { // The constraint clause must be set first because the constructor constraint may change it. CreateFromWorker.StoreWhitespace(newItem, constraintClause, LanguagePart.Constraint, WhitespaceLookup); // Class/Struct whitespace managed in above call, type explicitly handled below, constructor not handled by current design foreach (var constraint in constraintClause.Constraints) { var asClassStruct = constraint as ClassOrStructConstraintSyntax; if (asClassStruct != null) { StoreClassOrStructureConstraint(newItem, asClassStruct.ClassOrStructKeyword.Kind()); continue; } var asConstructor = constraint as ConstructorConstraintSyntax; if (asConstructor != null) { StoreConstructorConstraint(asConstructor, newItem); continue; } var asType = constraint as TypeConstraintSyntax; if (asType != null) { StoreTypeConstraint(asType, newItem, model); continue; } } } }
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); }