public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { OperatorWalker walker = this.CreateSyntaxWalker<OperatorWalker>(node); walker.Visit(node); this.Operators.Add(walker); base.VisitOperatorDeclaration(node); }
public static TextSpan HeaderSpan(this OperatorDeclarationSyntax operatorDeclaration) { if (operatorDeclaration == null) { throw new ArgumentNullException(nameof(operatorDeclaration)); } return(TextSpan.FromBounds( operatorDeclaration.Span.Start, operatorDeclaration.ParameterList?.Span.End ?? operatorDeclaration.OperatorToken.Span.End)); }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { var methodObj = CSharpEntityCreationHelper.CreateMethod(node, m_currentParent, m_currentCodeFile, m_currentTree); Debug.Assert(methodObj.TypeOfFunction == FunctionTypes.Operator); ISyntaxEntity oldParent = setCurrentParent(methodObj); base.VisitOperatorDeclaration(node); m_currentParent = oldParent; }
// 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 override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (entryNode == null) { entryNode = node; } _weComeFromMethod = true; base.VisitOperatorDeclaration(node); _weComeFromMethod = false; entryNode = null; }
/// <summary> /// Converts the given method (or operator) from expression to body form. /// </summary> /// <typeparam name="T">Specific node type</typeparam> /// <param name="method">Method/operator to be converted.</param> /// <returns>the converted method/operator</returns> /// <remarks>returns the original node if no conversion is needed/possible</remarks> 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 SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node.Body == null) { return(node); } BlockSyntax block = (BlockSyntax)SyntaxFactory.ParseStatement(GetDefaultMessage()); return(node.WithBody(block)); }
private static int Compare(OperatorDeclarationSyntax x, OperatorDeclarationSyntax y) { int result; if (EqualOperatorPrecedence(x.OperatorToken, y.OperatorToken, out result)) { EqualParameterCount(x.ParameterList, y.ParameterList, out result); } return(result); }
protected override (TypeWithAnnotations ReturnType, ImmutableArray <ParameterSymbol> Parameters) MakeParametersAndBindReturnType( BindingDiagnosticBag diagnostics ) { OperatorDeclarationSyntax declarationSyntax = GetSyntax(); return(MakeParametersAndBindReturnType( declarationSyntax, declarationSyntax.ReturnType, diagnostics )); }
public static SourceUserDefinedOperatorSymbol CreateUserDefinedOperatorSymbol( SourceMemberContainerTypeSymbol containingType, OperatorDeclarationSyntax syntax, DiagnosticBag diagnostics) { var location = syntax.OperatorToken.GetLocation(); string name = OperatorFacts.OperatorNameFromDeclaration(syntax); return new SourceUserDefinedOperatorSymbol( containingType, name, location, syntax, diagnostics); }
/// <summary> /// Processes an operator declaration. /// </summary> public static void ProcessNode(OperatorDeclarationSyntax node, ItemCollection itemCollection, int?index = null) { var item = new TreeViewItem { Header = new TreeElement( $"{node.ReturnType} {node.OperatorToken}({string.Join(", ", node.ParameterList.Parameters.Select(p => p.Type))})", node.Span, TreeImages.GetImage(ElementType.Operator, GetModifiers(node))) }; AddOrInsert(itemCollection, item, index); }
public static SourceUserDefinedOperatorSymbol CreateUserDefinedOperatorSymbol( SourceMemberContainerTypeSymbol containingType, OperatorDeclarationSyntax syntax, DiagnosticBag diagnostics) { var location = syntax.OperatorToken.GetLocation(); string name = OperatorFacts.OperatorNameFromDeclaration(syntax); return(new SourceUserDefinedOperatorSymbol( containingType, name, location, syntax, diagnostics)); }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (_isBeforeFirstVisit) { _isBeforeFirstVisit = false; base.VisitOperatorDeclaration(node); } else if (!node.Modifiers.Contains(SyntaxKind.UnsafeKeyword)) { base.VisitOperatorDeclaration(node); } }
private static void ComputeRefactorings(RefactoringContext context, OperatorDeclarationSyntax operatorDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(operatorDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, operatorDeclaration, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } }
private static void ComputeRefactorings(RefactoringContext context, OperatorDeclarationSyntax operatorDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && operatorDeclaration.Body?.Span.Contains(context.Span) == true && context.SupportsCSharp6 && UseExpressionBodiedMemberRefactoring.CanRefactor(operatorDeclaration)) { context.RegisterRefactoring( "Use expression-bodied member", cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, operatorDeclaration, cancellationToken)); } }
private static void ComputeRefactorings(RefactoringContext context, OperatorDeclarationSyntax operatorDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && context.SupportsCSharp6 && UseExpressionBodiedMemberRefactoring.CanRefactor(operatorDeclaration, context.Span)) { context.RegisterRefactoring( UseExpressionBodiedMemberRefactoring.Title, cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, operatorDeclaration, cancellationToken), RefactoringIdentifiers.UseExpressionBodiedMember); } }
public static SyntaxTriviaList Generate(OperatorDeclarationSyntax operatorDeclaration, DocumentationCommentGeneratorSettings settings = null) { if (operatorDeclaration == null) { throw new ArgumentNullException(nameof(operatorDeclaration)); } return(Generate( default(TypeParameterListSyntax), operatorDeclaration.ParameterList, canGenerateReturns: true, settings: settings)); }
private static async Task<Document> ReplaceWithExpressionBodiedMember(Document document, OperatorDeclarationSyntax declaration, CancellationToken cancellationToken) { var newDeclaration = declaration .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(GetExpression(declaration.Body))) .WithBody(null) .WithSemicolonToken(GetSemicolon(declaration.Body)) .WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }
public override SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node.Body == null && node.ExpressionBody == null) { return(base.VisitOperatorDeclaration(node)); } var blockResumeLocation = GetBlockResumeLocation((SyntaxNode)node.Body ?? node.ExpressionBody); node = (OperatorDeclarationSyntax)base.VisitOperatorDeclaration(node); return(ProcessMethod(node, blockResumeLocation)); }
public override object VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node.ExpressionBody != null) { Visit(node.ExpressionBody); } if (node.Body != null) { Visit(node.Body); } return(null); }
/// <summary> /// Add <paramref name="text"/> as attribute list to <paramref name="member"/>. /// </summary> /// <param name="member">The <see cref="OperatorDeclarationSyntax"/>.</param> /// <param name="text"> /// The attribute text including start and end []. /// </param> /// <param name="adjustLeadingWhitespace">If true leading whitespace is adjusted to match <paramref name="member"/>.</param> /// <returns>The <paramref name="member"/> with docs in leading trivia.</returns> public static OperatorDeclarationSyntax WithAttributeListText(this OperatorDeclarationSyntax member, string text, bool adjustLeadingWhitespace = true) { if (member is null) { throw new System.ArgumentNullException(nameof(member)); } if (text is null) { throw new System.ArgumentNullException(nameof(text)); } return(member.WithAttributeList(Parse.AttributeList(text, adjustLeadingWhitespace ? member.LeadingWhitespace() : null))); }
/// <summary> /// Add the attribute list to the <see cref="OperatorDeclarationSyntax"/>. /// </summary> /// <param name="member">The <see cref="OperatorDeclarationSyntax"/>.</param> /// <param name="attributeList">The <see cref="AttributeListSyntax"/>.</param> /// <returns>The <paramref name="member"/> with <paramref name="attributeList"/> added.</returns> public static OperatorDeclarationSyntax WithAttributeList(this OperatorDeclarationSyntax member, AttributeListSyntax attributeList) { if (member is null) { throw new System.ArgumentNullException(nameof(member)); } if (attributeList is null) { throw new System.ArgumentNullException(nameof(attributeList)); } return(member.WithAttributeLists(member.AttributeLists.Add(attributeList))); }
private static bool IsFunctionNameSpan(OperatorDeclarationSyntax syntax, TextSpan span) { if (syntax.OperatorKeyword.Span.Contains(span) || syntax.OperatorToken.Span.Contains(span)) { return(true); } if (span.Start < syntax.OperatorKeyword.Span.Start || syntax.OperatorToken.Span.End < span.End) { return(false); } return(span.Start < syntax.OperatorKeyword.Span.End || syntax.OperatorToken.Span.Start < span.End); }
private static void ComputeRefactorings(RefactoringContext context, OperatorDeclarationSyntax operatorDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && context.SupportsCSharp6 && operatorDeclaration.Body != null && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(operatorDeclaration.Body) && UseExpressionBodiedMemberAnalysis.GetReturnExpression(operatorDeclaration.Body) != null) { context.RegisterRefactoring( UseExpressionBodiedMemberRefactoring.Title, cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, operatorDeclaration, cancellationToken), RefactoringIdentifiers.UseExpressionBodiedMember); } }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { foreach (AttributeListSyntax attributeList in node.AttributeLists) { attributeList.Accept(this); } node.ParameterList?.Accept(this); node.ReturnType?.Accept(this); node.Body?.Accept(this); node.ExpressionBody?.Accept(this); base.VisitOperatorDeclaration(node); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { Diagnostic diagnostic = context.Diagnostics[0]; SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!IsEnabled(diagnostic.Id, CodeFixIdentifiers.DefineMatchingOperator, context.Document, root.SyntaxTree)) { return; } if (!TryFindFirstAncestorOrSelf(root, context.Span, out OperatorDeclarationSyntax operatorDeclaration)) { return; } SyntaxToken token = operatorDeclaration.OperatorToken; SyntaxKind matchingKind = GetMatchingOperatorToken(token); if (matchingKind == SyntaxKind.None) { return; } SyntaxToken newToken = SyntaxFactory.Token(token.LeadingTrivia, matchingKind, token.TrailingTrivia); if (operatorDeclaration.BodyOrExpressionBody() == null) { return; } if (operatorDeclaration.Parent is not TypeDeclarationSyntax typeDeclaration) { return; } CodeAction codeAction = CodeAction.Create( $"Generate {newToken} operator", ct => { OperatorDeclarationSyntax newNode = operatorDeclaration.WithOperatorToken(newToken); return(context.Document.InsertNodeAfterAsync(operatorDeclaration, newNode, ct)); }, EquivalenceKey.Create(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); }
public override SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node == null) { return(null); } var symbol = _semanticModel.GetDeclaredSymbol(node); node = (OperatorDeclarationSyntax)base.VisitOperatorDeclaration(node); if (!IsPrivateOrInternal(symbol.DeclaredAccessibility)) { node = (OperatorDeclarationSyntax)ApplyDocComment(node, symbol.GetDocumentationCommentId()); } return(node); }
private OperatorDef ParseOperator(OperatorDeclarationSyntax operatorSyntax, SemanticModel semanticModel) { var operatorDef = new OperatorDef(); operatorDef.Operator = operatorSyntax.OperatorToken.ValueText; operatorDef.ReturnType = ParseTypeSpecifier(operatorSyntax.ReturnType, semanticModel); operatorDef.AccessLevel = ParseAccessLevel(operatorSyntax.Modifiers) ?? AccessLevel.Private; foreach (var item in operatorSyntax.ParameterList.Parameters) { operatorDef.Parameters.Add(ParseParameter(item, semanticModel)); } return(operatorDef); }
public override SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { var symbol = sem.GetDeclaredSymbol(node); var newNode = (OperatorDeclarationSyntax)base.VisitOperatorDeclaration(node); return(MethodDeclaration( attributeLists: newNode.AttributeLists, modifiers: newNode.Modifiers, returnType: newNode.ReturnType, identifier: Identifier(symbol.Name) .WithLeadingTrivia(newNode.OperatorToken.LeadingTrivia) .WithTrailingTrivia(newNode.OperatorToken.TrailingTrivia), parameterList: newNode.ParameterList, body: newNode.Body, typeParameterList: default,
public static SourceUserDefinedOperatorSymbol CreateUserDefinedOperatorSymbol( // @MattWindsor91 (Concept-C# 2017) // See base class for comment on why this type has been relaxed. NamedTypeSymbol containingType, OperatorDeclarationSyntax syntax, DiagnosticBag diagnostics) { var location = syntax.OperatorToken.GetLocation(); string name = OperatorFacts.OperatorNameFromDeclaration(syntax); return(new SourceUserDefinedOperatorSymbol( containingType, name, location, syntax, diagnostics, syntax.Body == null && syntax.ExpressionBody != null)); }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { // Don't process intrinsics var attributes = mFrontEnd.ParseAttributes(GetDeclaredSymbol(node)); if (IsIntrinsic(attributes)) { return; } var functionName = node.ToString(); var returnType = FindType(node.ReturnType); CreateFunction(node, functionName, returnType); }
public override SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { bool isPubliclyVisible = IsPubliclyVisible(node); node = (OperatorDeclarationSyntax)base.VisitOperatorDeclaration(node); if (isPubliclyVisible && !node.HasDocumentationComment()) { return(AddDocumentationComment(node)); } else { return(node); } }
private static SyntaxNode HandleOperatorDeclaration(OperatorDeclarationSyntax node) { TypeSyntax type = node.ReturnType; if (type == null || type.IsMissing) { return(null); } SyntaxTokenList modifiers = AddModifier(node.Modifiers, ref type, SyntaxKind.PublicKeyword); return(node .WithReturnType(type) .WithModifiers(modifiers) .WithoutFormatting()); }
// NOTE: no need to call WithUnsafeRegionIfNecessary, since the signature // is bound lazily using binders from a BinderFactory (which will already include an // UnsafeBinder, if necessary). private SourceUserDefinedOperatorSymbol( SourceMemberContainerTypeSymbol containingType, string name, Location location, OperatorDeclarationSyntax syntax, DiagnosticBag diagnostics) : base( MethodKind.UserDefinedOperator, name, containingType, location, syntax.GetReference(), syntax.Body.GetReferenceOrNull(), syntax.Modifiers, diagnostics) { }
// NOTE: no need to call WithUnsafeRegionIfNecessary, since the signature // is bound lazily using binders from a BinderFactory (which will already include an // UnsafeBinder, if necessary). private SourceUserDefinedOperatorSymbol( SourceMemberContainerTypeSymbol containingType, string name, Location location, OperatorDeclarationSyntax syntax, DiagnosticBag diagnostics, bool isExpressionBodied) : base( MethodKind.UserDefinedOperator, name, containingType, location, syntax.GetReference(), syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), syntax.Modifiers, diagnostics, isExpressionBodied) { }
private static async Task<Document> ReplaceWithExpressionBodiedMember(Document document, OperatorDeclarationSyntax declaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia; var expression = GetExpressionAndLeadingTrivia(declaration.Body, out leadingTrivia); var declarationTrivia = declaration.GetLeadingTrivia(); declarationTrivia = declarationTrivia.AddRange(leadingTrivia); var newDeclaration = declaration .WithLeadingTrivia(declarationTrivia) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression)) .WithBody(null) .WithSemicolonToken(GetSemicolon(declaration.Body)) .WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }
private static OperatorDeclarationSyntax UseExpressionBodyIfDesired( Workspace workspace, OperatorDeclarationSyntax declaration, ParseOptions options) { if (declaration.ExpressionBody == null) { var preferExpressionBody = workspace.Options.GetOption(CSharpCodeStyleOptions.PreferExpressionBodiedOperators).Value; if (preferExpressionBody) { var expressionBody = declaration.Body.TryConvertToExpressionBody(options); if (expressionBody != null) { return declaration.WithBody(null) .WithExpressionBody(expressionBody) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } } } return declaration; }
public static string OperatorNameFromDeclaration(OperatorDeclarationSyntax declaration) { return OperatorNameFromDeclaration((Syntax.InternalSyntax.OperatorDeclarationSyntax)(declaration.Green)); }
private static SyntaxNode HandleOperatorDeclaration(OperatorDeclarationSyntax node) { TypeSyntax type = node.ReturnType; if (type == null || type.IsMissing) { return null; } SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref type, SyntaxKind.PublicKeyword); return node .WithReturnType(type) .WithModifiers(modifiers) .WithoutFormatting(); }
public void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); WriteLeadingTrivia(node); _writer.WriteIndent(); WriteAttributes( node, _writer.Configuration.LineBreaksAndWrapping.Other.PlaceMethodAttributeOnSameLine ); WriteMemberModifiers(node.Modifiers); _writer.WriteKeyword(PrinterKeyword.Operator); _writer.WriteSpace(); node.ReturnType.Accept(this); _writer.WriteSpace(); switch (node.Operator) { case Operator.Ampersand: _writer.WriteOperator(PrinterOperator.Ampersand); break; case Operator.Asterisk: _writer.WriteOperator(PrinterOperator.Asterisk); break; case Operator.Bar: _writer.WriteOperator(PrinterOperator.Bar); break; case Operator.Caret: _writer.WriteOperator(PrinterOperator.Caret); break; case Operator.EqualsEquals: _writer.WriteOperator(PrinterOperator.EqualsEquals); break; case Operator.Exclamation: _writer.WriteOperator(PrinterOperator.Exclamation); break; case Operator.ExclamationEquals: _writer.WriteOperator(PrinterOperator.ExclamationEquals); break; case Operator.False: _writer.WriteKeyword(PrinterKeyword.False); break; case Operator.GreaterThan: _writer.WriteOperator(PrinterOperator.GreaterThan); break; case Operator.GreaterThanEquals: _writer.WriteOperator(PrinterOperator.GreaterThanEquals); break; case Operator.GreaterThanGreaterThan: _writer.WriteOperator(PrinterOperator.GreaterThanGreaterThan); break; case Operator.LessThan: _writer.WriteOperator(PrinterOperator.LessThan); break; case Operator.LessThanEquals: _writer.WriteOperator(PrinterOperator.LessThanEquals); break; case Operator.LessThanLessThan: _writer.WriteOperator(PrinterOperator.LessThanLessThan); break; case Operator.Minus: _writer.WriteOperator(PrinterOperator.Minus); break; case Operator.MinusMinus: _writer.WriteOperator(PrinterOperator.MinusMinus); break; case Operator.Percent: _writer.WriteOperator(PrinterOperator.Percent); break; case Operator.Plus: _writer.WriteOperator(PrinterOperator.Plus); break; case Operator.PlusPlus: _writer.WriteOperator(PrinterOperator.PlusPlus); break; case Operator.Slash: _writer.WriteOperator(PrinterOperator.Slash); break; case Operator.Tilde: _writer.WriteOperator(PrinterOperator.Tilde); break; case Operator.True: _writer.WriteKeyword(PrinterKeyword.True); break; default: throw ThrowHelper.InvalidEnumValue(node.Operator); } node.ParameterList.Accept(this); node.Body.Accept(this); WriteTrailingTrivia(node); }
public OperatorDeclarationTranslation(OperatorDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { ReturnType = syntax.ReturnType.Get<TypeTranslation>(this); Identifier = new TokenTranslation { SyntaxString = Helper.OperatorToMethod(syntax.OperatorToken.ToString()) }; }
private void ClassifyUpdate(OperatorDeclarationSyntax oldNode, OperatorDeclarationSyntax newNode) { if (!SyntaxFactory.AreEquivalent(oldNode.Modifiers, newNode.Modifiers)) { ReportError(RudeEditKind.ModifiersUpdate); return; } if (!SyntaxFactory.AreEquivalent(oldNode.OperatorToken, newNode.OperatorToken)) { ReportError(RudeEditKind.Renamed); return; } if (!SyntaxFactory.AreEquivalent(oldNode.ReturnType, newNode.ReturnType)) { ReportError(RudeEditKind.TypeUpdate); return; } ClassifyMethodBodyRudeUpdate( (SyntaxNode)oldNode.Body ?? oldNode.ExpressionBody?.Expression, (SyntaxNode)newNode.Body ?? newNode.ExpressionBody?.Expression, containingMethodOpt: null, containingType: (TypeDeclarationSyntax)newNode.Parent); }
public static void Go(OutputWriter writer, OperatorDeclarationSyntax method) { var methodSymbol = (IMethodSymbol)TypeProcessor.GetDeclaredSymbol(method); var actualMethodName = OverloadResolver.MethodName(methodSymbol); writer.Write("\n"); var returnType = ""; if (method.ReturnType.ToString() == "void") returnType = ("void "); else { returnType = TypeProcessor.ConvertType(method.ReturnType) + " "; // writer.Write(returnType); } var methodName = ""; if (BinaryOperators.ContainsKey(actualMethodName)) { methodName = "opBinary"; var typeSymbolParam0 = TypeProcessor.GetTypeInfo(method.ParameterList.Parameters[0].Type); var typeSymbolParent = (methodSymbol.ContainingType); if (typeSymbolParam0.Type != typeSymbolParent) methodName += "Right"; } if (UnaryOperators.ContainsKey(actualMethodName)) methodName = "opUnary"; if (EqualsOperators.ContainsKey(actualMethodName)) methodName = "opEquals"; if (CmpOperators.ContainsKey(actualMethodName)) methodName = "opCmp"; if (AssignOperators.ContainsKey(actualMethodName)) methodName = "opAssign"; if (AssignOpOperators.ContainsKey(actualMethodName)) methodName = "opOpAssign"; // need to remove = from the name var paramType = method.ParameterList.Parameters[0]; if (method.ParameterList.Parameters.Count == 2) { if (methodName.EndsWith("Right")) paramType = method.ParameterList.Parameters[0]; else paramType = method.ParameterList.Parameters[1]; } var token = method.OperatorToken.Text; var methodBody = ""; var temp = new TempWriter(); foreach (var statement in method.Body.Statements) Core.Write(temp, statement); TriviaProcessor.ProcessTrivias(temp, method.Body.DescendantTrivia()); methodBody = temp.ToString(); if (methodName == "opOpAssign") token = token.Substring(0, 1); //We are going to have to rewrite this bit later ... for now all overloads are called directly /* if (methodName == "opBinary") { writer.WriteLine("public final " + returnType + " " + methodName + String.Format( " (string _op) ({0} other)\r\n\tif(_op==\"{2}\")\r\n\t{{ \r\n\t\treturn {1}(this,other); \r\n\t}}\r\n\r\n", TypeProcessor.ConvertType(paramType.Type), actualMethodName, token)); //Add Assignment operator if it doesn't exist if (!methodSymbol.ContainingType.GetMembers(AssignOpOperators.FirstOrDefault(k => k.Value == token + "=").Key).Any()) { writer.WriteLine("public final " + returnType + " opOpAssign" + String.Format( " (string _op) ({0} other)\r\n\tif(_op==\"{2}\")\r\n\t{{ \r\n\t\treturn {1}(this,other); \r\n\t}}\r\n\r\n", TypeProcessor.ConvertType(paramType.Type), actualMethodName, token)); } } else if (methodName == "opUnary")//TODO unary operators are mostly going to be direct methodCalls { writer.WriteLine("public final " + returnType + " " + methodName + String.Format( " (string _op) ()\r\n\tif(_op==\"{2}\")\r\n\t{{ \r\n\t\treturn {1}(this); \r\n\t}}\r\n\r\n", TypeProcessor.ConvertType(paramType.Type), actualMethodName, token)); // writer.WriteLine ("public final ref " + returnType + " " + methodName + // String.Format ( // " (string _op) ()\r\n\tif(_op==\"{2}\")\r\n\t{{ \r\n\t\t{3}\r\n\t}}\r\n\r\n", //TypeProcessor.ConvertType (paramType.Type), actualMethodName, token, methodBody.Replace(method.ParameterList.Parameters[0].Identifier.ValueText,"this"))); } else { writer.WriteLine("public final " + returnType + " " + methodName + String.Format( " (string _op) ({0} other)\r\n\tif(_op==\"{2}\")\r\n\t{{ \r\n\t\treturn {1}(this); \r\n\t}}\r\n\r\n", TypeProcessor.ConvertType(paramType.Type), actualMethodName, token)); }*/ var @params = method.ParameterList.Parameters; writer.WriteLine("public static " + returnType + " " + actualMethodName + WriteMethod.GetParameterListAsString(method.ParameterList.Parameters)); writer.OpenBrace(); if (method.Body != null) { foreach (var statement in method.Body.Statements) Core.Write(writer, statement); TriviaProcessor.ProcessTrivias(writer, method.Body.DescendantTrivia()); } writer.CloseBrace(); }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { CheckXmlDocForErrors(node, semanticModel.GetDeclaredSymbol(node)); }
public override void VisitOperatorDeclaration (OperatorDeclarationSyntax node) { base.VisitOperatorDeclaration (node); Append (node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitOperatorDeclaration(node); }
public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { VisitBlock(node.Body); }
private async Task<Document> HandleOperatorDeclaration(OperatorDeclarationSyntax declaration, Document document, CancellationToken cancellationToken) { var returnStatement = SyntaxFactory.ReturnStatement( returnKeyword: SyntaxFactory.Token(SyntaxKind.ReturnKeyword), expression: declaration.ExpressionBody.Expression, semicolonToken: declaration.SemicolonToken); var newDeclaration = declaration .WithBody(SyntaxFactory.Block(returnStatement)) .WithExpressionBody(null) .WithSemicolonToken(default(SyntaxToken)) .WithAdditionalAnnotations(Formatter.Annotation); var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = oldRoot.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }
public override SyntaxNode VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node == null) return null; var symbol = m_model.GetDeclaredSymbol(node); node = (OperatorDeclarationSyntax)base.VisitOperatorDeclaration(node); if (!IsPrivateOrInternal(symbol.DeclaredAccessibility)) node = (OperatorDeclarationSyntax)ApplyDocComment(node, symbol.GetDocumentationCommentId()); return node; }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitOperatorDeclaration(node); }