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(); } //} }
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); }
/// <summary> /// This is the key method for creating new RoslynDom elements. You can create new factories /// by overriding the CreateListFrom or CreateItemFrom methods depending on whether you are /// creating a list or single element respectively /// </summary> /// <param name="syntaxNode"></param> /// <param name="parent"></param> /// <param name="model"></param> /// <returns></returns> /// <remarks> /// Lists are created when multiple items are declared on a line. This allows simple access to /// variables and fields in the predominate case with only one variable per line. Currently this is not /// recreated on output but the design intent was to have variable groups with arbitrarily defined /// IDs and probably a position in the list. These two properties would be added to Field and Declaration /// RDom items, and possibly interfaces. This would be sufficient for recreation of lists /// <para/> /// Use CanCreate and Priority to control how your factory is selected. Highest priority wins and /// you can add to the enum values (as in Normal + 1) /// </remarks> public IEnumerable <IDom> CreateFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model, bool skipWhitespace) { var ret = new List <IDom>(); var newItems = CreateListFromInterim(syntaxNode, parent, model); if (!newItems.Any()) { return(ret); } var lookForTrivia = typeof(IStatement).IsAssignableFrom(typeof(T)) || typeof(ITypeMember).IsAssignableFrom(typeof(T)) || typeof(IStemMember).IsAssignableFrom(typeof(T)); var lookForTrailingTrivia = !typeof(IHasGroup).IsAssignableFrom(typeof(T)); if (lookForTrivia) { var leading = CreateFromWorker.GetDetail(syntaxNode, syntaxNode.GetLeadingTrivia(), newItems.FirstOrDefault().Parent, model, OutputContext); ret.AddRange(leading.OfType <IDom>()); if (lookForTrailingTrivia) { HandleTrailingTrivia(syntaxNode, model, newItems.LastOrDefault()); } ret.AddRange(newItems.OfType <IDom>()); } else { ret.AddRange(newItems.OfType <IDom>()); } return(ret); }
private void MemberWhitespace(RDomEnumMember newItem, EnumMemberDeclarationSyntax syntax) { //CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetFirstToken(), LanguagePart.Current, LanguageElement.EnumValueFirstToken); //CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.GetLastToken(), LanguagePart.Current, LanguageElement.EnumValueLastToken); if (syntax.EqualsValue != null) { CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.EqualsValue.Value.GetLastToken(), LanguagePart.Current, LanguageElement.Expression); CreateFromWorker.StoreWhitespaceForToken(newItem, syntax.EqualsValue.EqualsToken, LanguagePart.Current, LanguageElement.EnumValueAssignOperator); } CreateFromWorker.StoreListMemberWhitespace(syntax, WhitespaceLookup.Lookup(LanguageElement.EnumValueSeparator), LanguageElement.Identifier, newItem); //var prevNodeOrToken = syntax.Parent // .ChildNodesAndTokens() // .PreviousSiblings(syntax) // .LastOrDefault(); //var sepKind = WhitespaceLookup.Lookup(LanguageElement.EnumValueSeparator); //if (prevNodeOrToken.CSharpKind() == sepKind) //{ // var commaToken = prevNodeOrToken.AsToken(); // var whitespace2 = newItem.Whitespace2Set[LanguageElement.Identifier]; // var newLeadingWhitespace = commaToken.TrailingTrivia.ToString();; // if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace) // || newLeadingWhitespace.EndsWith("\r\n")) // { whitespace2.LeadingWhitespace = newLeadingWhitespace // + whitespace2.LeadingWhitespace; } //} }
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 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); }
private void StoreWhitespaceForNamed(RDomAttributeValue newItem, AttributeArgumentSyntax syntax, SyntaxToken identifier, SyntaxToken op) { CreateFromWorker.StoreWhitespaceForToken(newItem, identifier, LanguagePart.Current, LanguageElement.AttributeValueName); CreateFromWorker.StoreWhitespaceForToken(newItem, op, LanguagePart.Current, LanguageElement.AttributeValueEqualsOrColon); var lastToken = syntax.GetLastToken(); CreateFromWorker.StoreWhitespaceForToken(newItem, lastToken, LanguagePart.Current, LanguageElement.AttributeValueValue); }
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); }
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 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); }
private Tuple <object, string, LiteralKind> GetAttributeValueValue( SyntaxNode argNode, IDom newItem, SemanticModel model) { var arg = argNode as AttributeArgumentSyntax; Guardian.Assert.IsNotNull(arg, nameof(arg)); // TODO: Manage multiple values because of AllowMultiples, param array, or missing symbol var expr = arg.Expression; return(CreateFromWorker.GetArgumentValue(newItem, model, expr)); }
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 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 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 void HandleTrailingTrivia(SyntaxNode syntaxNode, SemanticModel model, IDom parent) { var trailingTrivia = syntaxNode.ChildTokens().Last().LeadingTrivia; var trailing = CreateFromWorker.GetDetail(syntaxNode, trailingTrivia, parent, model, OutputContext); var container = parent as IRDomContainer; if (trailing.Any() && container != null) { foreach (var newTrailing in trailing) { container.AddOrMoveMember(newTrailing); } } }
protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model) { var syntax = syntaxNode as CompilationUnitSyntax; var newItem = new RDomRoot(OutputContext.Corporation.FactoryAccess, syntaxNode, parent, model); // Root does not call StandardInitialize because the info is attched to the first item // and particularly, whitespace would be doubled. //CreateFromWorker.InitializePublicAnnotations(newItem, syntaxNode, parent, model); newItem.FilePath = syntax.SyntaxTree.FilePath; newItem.Name = Path.GetFileNameWithoutExtension(newItem.FilePath); CreateFromWorker.LoadStemMembers(newItem, syntax.Members, syntax.Usings, model); 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); }
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); }
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 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); }
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 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 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 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); }