private string GetDestructorSignatureString(DestructorDeclarationSyntax syntax) { StringBuilder stringBuilder = new StringBuilder(); this.AppendMethodIdentifier(syntax, stringBuilder); return(stringBuilder.ToString()); }
private static string GetDestructorSignatureString(DestructorDeclarationSyntax syntax) { var builder = new StringBuilder(); AppendMethodIdentifier(syntax, builder); return(builder.ToString()); }
public static Task <Document> RefactorAsync( Document document, DestructorDeclarationSyntax destructorDeclaration, CancellationToken cancellationToken) { return(Remover.RemoveMemberAsync(document, destructorDeclaration, cancellationToken)); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); DestructorDeclarationSyntax destructor = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <DestructorDeclarationSyntax>(); Debug.Assert(destructor != null, $"{nameof(destructor)} is null"); if (destructor == null) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.RemoveEmptyDestructor: { CodeAction codeAction = CodeAction.Create( "Remove empty destructor", cancellationToken => SyntaxRemover.RemoveMemberAsync(context.Document, destructor, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { VisitAttributeLists(node.AttributeLists); Visit(node.ParameterList); VisitBodyOrExpressionBody(node.Body, node.ExpressionBody); //base.VisitDestructorDeclaration(node); }
public static async Task <Document> RefactorAsync( Document document, DestructorDeclarationSyntax destructorDeclaration, CancellationToken cancellationToken) { return(await Remover.RemoveMemberAsync(document, destructorDeclaration, cancellationToken).ConfigureAwait(false)); }
private DestructorDef ParseDestructor(DestructorDeclarationSyntax destructorSyntax, SemanticModel semanticModel) { var def = new DestructorDef(); def.Internal = destructorSyntax; return(def); }
public _Item(MemberDeclarationSyntax m) { //CiUtil.PrintNode(m); string name; if (m is BaseFieldDeclarationSyntax fd) //field, event { var vd = fd.Declaration; var a = vd.Variables; if (a.Count == 1) { name = a[0].Identifier.Text + " : " + vd.Type; } else { name = string.Join(", ", a.Select(o => o.Identifier.ToString())) + " : " + vd.Type; } } else if (m is BaseNamespaceDeclarationSyntax nd) { name = nd.Name.ToString(); } else if (m is TypeDeclarationSyntax td) { name = td.Identifier.Text + td.TypeParameterList; } else { name = m switch { DestructorDeclarationSyntax dd => "~" + dd.Identifier.Text, ConversionOperatorDeclarationSyntax od => $"{od.ImplicitOrExplicitKeyword.Text} {od.Type}", _ => m.GetNameToken().Text }; if (m is MethodDeclarationSyntax md) { name = $"{name}{md.TypeParameterList}({_Function(md.ParameterList.Parameters)}) : {md.ReturnType}"; } else if (m is OperatorDeclarationSyntax od) { name = $"{name}({_Function(od.ParameterList.Parameters)}) : {od.ReturnType}"; } else if (m is BaseMethodDeclarationSyntax bmd) { name = $"{name}({_Function(bmd.ParameterList.Parameters)})"; } else if (m is IndexerDeclarationSyntax id) { name = $"{name}[{_Function(id.ParameterList.Parameters)}]"; } else if (m is DelegateDeclarationSyntax odd) { name = $"{name}{odd.TypeParameterList}({_Function(odd.ParameterList.Parameters)}) : {odd.ReturnType}"; } if (m is BasePropertyDeclarationSyntax pd) { name = $"{name} : {pd.Type}"; //property, indexer, event }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { LackOfCohesionAnalyzer lackOfCohesionAnalyzer = this; lackOfCohesionAnalyzer.numMethods = checked (lackOfCohesionAnalyzer.numMethods + 1); this.FilterFieldAccessExpressions(node); base.VisitDestructorDeclaration(node); }
public DestructorNodeWithSymbols( DestructorDeclarationSyntax declaration, ClassDeclarationNode container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public static void Analyze(SyntaxNodeAnalysisContext context, DestructorDeclarationSyntax destructor) { if (destructor.Body?.Statements.Count == 0 && !destructor.SpanContainsDirectives()) { context.ReportDiagnostic(DiagnosticDescriptors.RemoveEmptyDestructor, destructor); } }
public static string DestructorDeclaration(DestructorDeclarationSyntax destructor) { var parsedAttributes = ParseAttributes(destructor.AttributeLists); var output = parsedAttributes.Item1; return(output + "deinit " + Block(destructor.Body)); }
internal static FunctionDefinition CreateMethod(DestructorDeclarationSyntax node, ISyntaxEntity parent, CodeFile currentCodeFile, SyntaxTree tree) { FunctionDefinition func = createFunctionObject(node.Identifier.Text, tree.GetLineSpan(node.Span), node.Modifiers, parent, currentCodeFile); func.TypeOfFunction = FunctionTypes.Destructor; func.AssociatedComment = GetComment(func, node, tree, currentCodeFile); return(func); }
internal static ModifierListInfo Create(DestructorDeclarationSyntax destructorDeclaration) { if (destructorDeclaration == null) { return(Default); } return(new ModifierListInfo(destructorDeclaration, destructorDeclaration.Modifiers)); }
public override Ust VisitDestructorDeclaration(DestructorDeclarationSyntax node) { var name = new IdToken(node.Identifier.ValueText + "_Destroy", node.Identifier.GetTextSpan()); var body = (BlockStatement)VisitBlock(node.Body); var result = new MethodDeclaration(name, null, body, node.GetTextSpan()); return(result); }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { var methodObj = CSharpEntityCreationHelper.CreateMethod(node, m_currentParent, m_currentCodeFile, m_currentTree); ISyntaxEntity oldParent = setCurrentParent(methodObj); base.VisitDestructorDeclaration(node); m_currentParent = oldParent; }
public static DestructorDeclarationSyntax InsertModifier(DestructorDeclarationSyntax destructorDeclaration, SyntaxKind modifierKind) { if (destructorDeclaration == null) { throw new ArgumentNullException(nameof(destructorDeclaration)); } return(destructorDeclaration.WithModifiers(InsertModifier(destructorDeclaration.Modifiers, modifierKind))); }
public static SyntaxTriviaList Generate(DestructorDeclarationSyntax destructorDeclaration, DocumentationCommentGeneratorSettings settings = null) { if (destructorDeclaration == null) { throw new ArgumentNullException(nameof(destructorDeclaration)); } return(Generate(settings: settings)); }
public static int GetModifierInsertIndex(DestructorDeclarationSyntax destructorDeclaration, SyntaxKind modifierKind) { if (destructorDeclaration == null) { throw new ArgumentNullException(nameof(destructorDeclaration)); } return(GetModifierInsertIndex(destructorDeclaration.Modifiers, modifierKind)); }
public static DestructorDeclarationSyntax ToStatementBody(DestructorDeclarationSyntax method) { var body = method.ExpressionBody.Expression.WithLeadingTrivia(SyntaxFactory.Space); return(method.WithBody(SyntaxFactory.Block(SyntaxFactory.ExpressionStatement(body))) .WithExpressionBody(null) .WithSemicolonToken(SyntaxFactory.MissingToken(SyntaxKind.SemicolonToken)) .WithTrailingTrivia(method.GetTrailingTrivia())); }
private async Task <Document> RemoveDestructorAsync(Document document, DestructorDeclarationSyntax declaration, CancellationToken cancellationToken) { // Get the symbol representing the type to be renamed. var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.RemoveNode(declaration, SyntaxRemoveOptions.KeepEndOfLine); return(document.WithSyntaxRoot(newRoot)); }
/// <summary> /// Visits a destructor declaration. /// </summary> /// <param name="node">The destructor declaration to visit.</param> public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { // Visit this.Visit <DestructorDeclarationSyntax>( node: node, typeParameterList: null, exctractName: n => "<Destructor>", targetNode: n => n, visit: base.VisitDestructorDeclaration); }
public static bool CanRefactor(DestructorDeclarationSyntax declaration) { if (declaration == null) { throw new ArgumentNullException(nameof(declaration)); } return(declaration.ExpressionBody == null && GetExpression(declaration.Body) != null); }
public T ConvertToBody <T>(T method) where T : BaseMethodDeclarationSyntax { if (method.ExpressionBody == null || method.Body != null) { // can't convert return(method); } StatementSyntax statementLine; switch (method) { case MethodDeclarationSyntax actualMethod when actualMethod.NeedsReturn(): statementLine = SyntaxFactory.ReturnStatement(method.ExpressionBody.Expression.WithLeadingTrivia(SyntaxFactory.Space)); break; case ConversionOperatorDeclarationSyntax _: case OperatorDeclarationSyntax _: statementLine = SyntaxFactory.ReturnStatement(method.ExpressionBody.Expression.WithLeadingTrivia(SyntaxFactory.Space)); break; default: statementLine = SyntaxFactory.ExpressionStatement(method.ExpressionBody.Expression); break; } // do we need add return to the expression body? var statement = SyntaxFactory.Block(statementLine); BaseMethodDeclarationSyntax result = method switch { MethodDeclarationSyntax actualMethod => actualMethod.Update(actualMethod.AttributeLists, actualMethod.Modifiers, actualMethod.ReturnType, actualMethod.ExplicitInterfaceSpecifier, actualMethod.Identifier, actualMethod.TypeParameterList, actualMethod.ParameterList, actualMethod.ConstraintClauses, statement, null, SyntaxFactory.Token(SyntaxKind.None)), OperatorDeclarationSyntax operatorDeclaration => operatorDeclaration.Update( operatorDeclaration.AttributeLists, operatorDeclaration.Modifiers, operatorDeclaration.ReturnType, operatorDeclaration.OperatorKeyword, operatorDeclaration.OperatorToken, operatorDeclaration.ParameterList, statement, SyntaxFactory.Token(SyntaxKind.None)), ConversionOperatorDeclarationSyntax conversion => conversion.Update(conversion.AttributeLists, conversion.Modifiers, conversion.ImplicitOrExplicitKeyword, conversion.OperatorKeyword, conversion.Type, conversion.ParameterList, statement, null, SyntaxFactory.Token(SyntaxKind.None)), DestructorDeclarationSyntax destructor => destructor.Update(destructor.AttributeLists, destructor.Modifiers, destructor.TildeToken, destructor.Identifier, destructor.ParameterList, statement, SyntaxFactory.Token(SyntaxKind.None)), ConstructorDeclarationSyntax constructor => constructor.Update(constructor.AttributeLists, constructor.Modifiers, constructor.Identifier, constructor.ParameterList, constructor.Initializer, statement, SyntaxFactory.Token(SyntaxKind.None)), _ => method }; return(result.WithAdditionalAnnotations(Marker) as T); }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { base.VisitDestructorDeclaration(node); MemberNode memberNode = new MemberNode() { SyntaxNode = node, Kind = MemberKind.Destructor }; this.members.Add(memberNode); }
public override SyntaxNode VisitDestructorDeclaration(DestructorDeclarationSyntax node) { node = (DestructorDeclarationSyntax)base.VisitDestructorDeclaration(node); if (node.ExpressionBody != null) { return(SyntaxHelper.ToStatementBody(node).NormalizeWhitespace()); } return(node); }
// gets the return type of a method (incl. constructor, destructor...) public static TypeSyntax ReturnType(this BaseMethodDeclarationSyntax baseMethod) { return(baseMethod switch { ConstructorDeclarationSyntax _ => null, ConversionOperatorDeclarationSyntax _ => null, DestructorDeclarationSyntax _ => null, MethodDeclarationSyntax method => method.ReturnType, OperatorDeclarationSyntax operatorSyntax => operatorSyntax.ReturnType, _ => null });
public static void ComputeRefactorings(RefactoringContext context, DestructorDeclarationSyntax destructorDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && destructorDeclaration.Body?.Span.Contains(context.Span) == true && context.SupportsCSharp6 && UseExpressionBodiedMemberAnalysis.IsFixable(destructorDeclaration)) { context.RegisterRefactoring( "Use expression-bodied member", cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, destructorDeclaration, cancellationToken)); } }
public static void ComputeRefactorings(RefactoringContext context, DestructorDeclarationSyntax destructorDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(destructorDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, destructorDeclaration, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } }
private void HandleDestructorDeclaration(SyntaxNodeAnalysisContext context) { DestructorDeclarationSyntax declaration = context.Node as DestructorDeclarationSyntax; if (declaration != null) { if (!XmlCommentHelper.HasDocumentation(declaration)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.Identifier.GetLocation())); } } }
public void AddFunction(DestructorDeclarationSyntax node) { int nFunction = FunctionsByNumber.Count; Function f = new Function(this, nFunction, Model, Model.GetDeclaredSymbol(node)); Functions.Add(f.MethodSymbol, f); FunctionsByNumber.Add(f); }
public void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); WriteLeadingTrivia(node); _writer.WriteIndent(); WriteAttributes( node, _writer.Configuration.LineBreaksAndWrapping.Other.PlaceMethodAttributeOnSameLine ); _writer.WriteSyntax(Syntax.Tilde); _writer.WriteIdentifier(node.Identifier); node.ParameterList.Accept(this); node.Body.Accept(this); WriteTrailingTrivia(node); }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { base.VisitDestructorDeclaration(node); Chunk.AddFunction(node, Model); }
public void AddFunction(DestructorDeclarationSyntax node, SemanticModel Model) { MethodSymbol ms = Model.GetDeclaredSymbol(node); AddFunction(ms, Model); }
public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) { base.VisitDestructorDeclaration(node); }