private static void GenerateStaticConstructor(DocumentEditor editor, ClassBlockSyntax classDeclaration, string registerPropertyMethodName, IPropertySymbol propertySymbol, bool returnsMounter, CancellationToken ct) { var semanticModel = editor.SemanticModel; var classSymbol = semanticModel.GetDeclaredSymbol(classDeclaration, ct); var staticConstructor = editor.Generator.GeneratePropertyRegistration(LanguageNames.VisualBasic, classSymbol, propertySymbol, registerPropertyMethodName, returnsMounter, false); var index = GetMounterDeclarationInsertIndex(classDeclaration, semanticModel); editor.InsertMembers(classDeclaration, index, new SyntaxNode[] { staticConstructor }); }
private static void GenerateMounterFieldDeclaration(DocumentEditor editor, string registerPropertyMethodName, ClassBlockSyntax classDeclaration, IPropertySymbol propertySymbol, CancellationToken ct) { var semanticModel = editor.SemanticModel; var classSymbol = semanticModel.GetDeclaredSymbol(classDeclaration, ct); var mounterDeclaration = editor.Generator.GenerateMounterDeclaration(LanguageNames.VisualBasic, classSymbol, propertySymbol, registerPropertyMethodName); var index = GetMounterDeclarationInsertIndex(classDeclaration, semanticModel); editor.InsertMembers(classDeclaration, index, new SyntaxNode[] { mounterDeclaration }); }
private void ProccessNode(CSharpSyntaxNode node) { var modifiers = GetModifiers(Command.Modifiers, Command.Static); var Constructor = SyntaxFactory.ConstructorDeclaration((node as TypeDeclarationSyntax).Identifier) .WithAttributeLists(Command.Attributes) .WithBody(Command.BlockBody) .WithExpressionBody(Command.ExpressionBody) .WithParameterList(Command.Parameters ?? SyntaxFactory.ParameterList()) .WithModifiers(modifiers) .WithAdditionalAnnotations(new SyntaxAnnotation($"{Id}")); DocumentEditor.InsertMembers(node, 0, new[] { Constructor }); }
private void ProccessNode(CSharpSyntaxNode node) { var modifiers = GetModifiers(Command.Modifiers, Command.Partial); var baseTypes = GetBaseTypes(Command.ImplementedInterfaces); var interfaceNode = SyntaxFactory.InterfaceDeclaration(Command.Name) .WithBaseList(baseTypes) .WithTypeParameterList(Command.GenericParameters) .WithConstraintClauses(Command.GenericParametersConstraints) .WithAttributeLists(Command.Attributes) .WithModifiers(modifiers) .WithAdditionalAnnotations(new SyntaxAnnotation($"{Id}")); DocumentEditor.InsertMembers(node, 0, new[] { interfaceNode }); }
public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node) { var modifiers = GetModifiers(Command.Modifiers, Command.Static); var ConstructorNode = node.WithIdentifier((Command.OnNode as TypeDeclarationSyntax)?.Identifier ?? node.Identifier) .WithAttributeLists(Command.Attributes.Count > 0 ? Command.Attributes : node.AttributeLists) .WithParameterList(Command.Parameters ?? node.ParameterList) .WithBody(Command.BlockBody ?? node.Body) .WithModifiers(modifiers.Count > 0 ? modifiers : node.Modifiers) .WithAdditionalAnnotations(new SyntaxAnnotation($"{Id}")); if (Command.OnNode is null) { DocumentEditor.InsertAfter(node, ConstructorNode); } else { DocumentEditor.InsertMembers(Command.OnNode, 0, new[] { ConstructorNode }); } }
private void ProccessNode(CSharpSyntaxNode node) { var modifiers = GetModifiers(Command.Modifiers, Command.Abstract, Command.Static); var newGetAccessor = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithModifiers(Command.GetModifier) .WithExpressionBody(Command.GetExpression) .WithBody(Command.GetStatements); if (newGetAccessor.Body is null) { newGetAccessor = newGetAccessor.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } var newSetAccessor = SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithModifiers(Command.SetModifier) .WithExpressionBody(Command.SetExpression) .WithBody(Command.SetStatements); if (newSetAccessor.Body is null) { newSetAccessor = newSetAccessor.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } var Accesors = new SyntaxList <AccessorDeclarationSyntax>().Add(newGetAccessor).Add(newSetAccessor); var property = SyntaxFactory.PropertyDeclaration(Command.ReturnType ?? SyntaxFactory.ParseTypeName("object"), Command.Name) .WithAttributeLists(Command.Attributes) .WithModifiers(modifiers) .WithAdditionalAnnotations(new SyntaxAnnotation($"{Id}")) .WithAccessorList(SyntaxFactory.AccessorList(Accesors)); if (Command.InitializerExpression != null) { property = property.WithInitializer(SyntaxFactory.EqualsValueClause(Command.InitializerExpression)) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } DocumentEditor.InsertMembers(node, 0, new[] { property }); }
private void ProccessNode(CSharpSyntaxNode node) { var modifiers = GetModifiers(Command.Modifiers, Command.Abstract, Command.Static, Command.Partial); var bodySyntax = Command.BlockBody; var method = SyntaxFactory.MethodDeclaration(Command.ReturnType ?? SyntaxFactory.ParseTypeName("void"), Command.Name) .WithAttributeLists(Command.Attributes) .WithBody(Command.BlockBody) .WithExpressionBody(Command.ExpressionBody) .WithParameterList(Command.Parameters ?? SyntaxFactory.ParameterList()) .WithTypeParameterList(Command.GenericParameters) .WithConstraintClauses(Command.GenericParametersConstraints) .WithModifiers(modifiers) .WithAdditionalAnnotations(new SyntaxAnnotation($"{Id}")); if (Command.ExpressionBody != null) { method = method.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } DocumentEditor.InsertMembers(node, 0, new[] { method }); }
private static void GenerateRegisterChildModel(DocumentEditor editor, ConstructorBlockSyntax staticConstructor, ClassBlockSyntax classDeclaration, SemanticModel semanticModel, IPropertySymbol childProperty, IPropertySymbol foreignKey) { if (staticConstructor == null) { var newStaticConstructor = editor.Generator.GenerateChildModelRegistrationStaticConstructor(LanguageNames.VisualBasic, childProperty, foreignKey); var index = GetMounterDeclarationInsertIndex(classDeclaration, semanticModel); editor.InsertMembers(classDeclaration, index, new SyntaxNode[] { newStaticConstructor }); } else { var statements = staticConstructor.Statements; if (statements.Count > 0) { var statement = editor.Generator.GenerateChildModelRegistration(LanguageNames.VisualBasic, childProperty, foreignKey); editor.InsertAfter(statements.Last(), new SyntaxNode[] { statement }); } else { var newStaticConstructor = editor.Generator.GenerateChildModelRegistrationStaticConstructor(LanguageNames.VisualBasic, childProperty, foreignKey); editor.ReplaceNode(staticConstructor, newStaticConstructor); } } }
private static Dictionary <string, string> CreateConstants( IReadOnlyCollection <string> constantsToCreate, ClassDeclarationSyntax classNode, DocumentEditor editor) { var result = new Dictionary <string, string>(); if (!constantsToCreate.Any()) { return(result); } var trivia = classNode.GetLeadingTrivia().ToString(); trivia = trivia.Substring(trivia.LastIndexOf('\n') + 1); string indent; if (string.IsNullOrEmpty(trivia)) { indent = " "; } else { indent = trivia + trivia; } var counter = 0; var newConstants = new List <MemberDeclarationSyntax>(); foreach (var constant in constantsToCreate) { counter++; var constantSubstring = SyntaxFactory.ParseToken(constant); var constName = GetConstantName(constantSubstring.ValueText, result, classNode, counter); var constSyntax = SyntaxFactory.FieldDeclaration( SyntaxFactory .VariableDeclaration( SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.StringKeyword))) .WithVariables( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(constName)) .WithInitializer( SyntaxFactory.EqualsValueClause( SyntaxFactory.LiteralExpression( SyntaxKind.StringLiteralExpression, constantSubstring)))))) .WithModifiers( SyntaxFactory.TokenList( SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.ConstKeyword))) .NormalizeWhitespace() .WithLeadingTrivia(SyntaxFactory.Whitespace(indent)) .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed); newConstants.Add(constSyntax); result.Add(constant, constName); } editor.InsertMembers(classNode, 0, newConstants); return(result); }