public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { base.VisitIndexerDeclaration(node); Chunk.AddFunction(node, Model); }
internal static SourcePropertySymbol Create(SourceMemberContainerTypeSymbol containingType, Binder bodyBinder, IndexerDeclarationSyntax syntax, DiagnosticBag diagnostics) { var location = syntax.ThisKeyword.GetLocation(); return new SourcePropertySymbol(containingType, bodyBinder, syntax, DefaultIndexerName, location, diagnostics); }
private void ClassifyUpdate(IndexerDeclarationSyntax oldNode, IndexerDeclarationSyntax newNode) { if (!SyntaxFactory.AreEquivalent(oldNode.Modifiers, newNode.Modifiers)) { ReportError(RudeEditKind.ModifiersUpdate); return; } if (!SyntaxFactory.AreEquivalent(oldNode.Type, newNode.Type)) { ReportError(RudeEditKind.TypeUpdate); return; } if (!SyntaxFactory.AreEquivalent(oldNode.ExplicitInterfaceSpecifier, newNode.ExplicitInterfaceSpecifier)) { ReportError(RudeEditKind.Renamed); return; } Debug.Assert(!SyntaxFactory.AreEquivalent(oldNode.ExpressionBody, newNode.ExpressionBody)); var oldBody = SyntaxUtilities.TryGetEffectiveGetterBody(oldNode.ExpressionBody, oldNode.AccessorList); var newBody = SyntaxUtilities.TryGetEffectiveGetterBody(newNode.ExpressionBody, newNode.AccessorList); ClassifyMethodBodyRudeUpdate( oldBody, newBody, containingMethodOpt: null, containingType: (TypeDeclarationSyntax)newNode.Parent); }
public override SyntaxNode VisitIndexerDeclaration(IndexerDeclarationSyntax node) { this.AppendCompileIssue(node, IssueType.Error, IssueId.IndexerNotSupport); return node; }
/// <summary> /// A position is inside a property body only if it is inside an expression body. /// All block bodies for properties are part of the accessor declaration (a type /// of BaseMethodDeclaration), not the property declaration. /// </summary> internal static bool IsInBody(int position, IndexerDeclarationSyntax indexer) => IsInBody(position, blockOpt: null, indexer.GetExpressionBodySyntax(), indexer.SemicolonToken);
/// <summary> /// Normalizes the <paramref name="declaration" />. /// </summary> public override SyntaxNode VisitIndexerDeclaration(IndexerDeclarationSyntax declaration) { // Nothing to do here for properties without expression bodies if (declaration.ExpressionBody == null) return declaration; // Nothing to do here for indexers not defined in fault effects or for indexers that are no overrides of some port var propertySymbol = declaration.GetPropertySymbol(SemanticModel); if (!propertySymbol.ContainingType.IsFaultEffect(SemanticModel) || !propertySymbol.IsOverride) return declaration; var originalDeclaration = declaration; var statements = AsStatementBody(propertySymbol.GetMethod, declaration.ExpressionBody.Expression); var getter = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration, statements); var accessorList = SyntaxFactory.AccessorList(SyntaxFactory.SingletonList(getter)); declaration = declaration.WithAccessorList(accessorList); declaration = declaration.WithExpressionBody(null).WithSemicolonToken(default(SyntaxToken)); return declaration.EnsureLineCount(originalDeclaration); }
public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { base.VisitIndexerDeclaration(node); if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.ExternKeyword))) { // This method body is unable to be analysed, so may contain writer instances CheckForRefParametersForExternMethod(node.ParameterList.Parameters); } }
public IndexerDeclarationTranslation(IndexerDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { ParameterList = syntax.ParameterList.Get<BracketedParameterListTranslation>(this); }
/// <summary> /// Given a syntax node that declares an indexer, get the corresponding declared symbol. /// </summary> /// <param name="declarationSyntax">The syntax node that declares an indexer.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The symbol that was declared.</returns> public override IPropertySymbol GetDeclaredSymbol(IndexerDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken)) { using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetDeclaredSymbol, message: this.SyntaxTree.FilePath, cancellationToken: cancellationToken)) { return (IPropertySymbol)GetDeclaredMemberSymbol(declarationSyntax); } }
/// <summary> /// A position is inside a property body only if it is inside an expression body. /// All block bodies for properties are part of the accessor declaration (a type /// of BaseMethodDeclaration), not the property declaration. /// </summary> internal static bool IsInBody(int position, IndexerDeclarationSyntax indexer) => IsInBody(position, default(BlockSyntax), indexer.GetExpressionBodySyntax(), indexer.SemicolonToken);
private async Task<Document> HandleIndexerDeclaration(IndexerDeclarationSyntax declaration, Document document, CancellationToken cancellationToken) { var returnStatement = SyntaxFactory.ReturnStatement( returnKeyword: SyntaxFactory.Token(SyntaxKind.ReturnKeyword), expression: declaration.ExpressionBody.Expression, semicolonToken: declaration.SemicolonToken); var accessorDeclaration = SyntaxFactory.AccessorDeclaration( kind: SyntaxKind.GetAccessorDeclaration, body: SyntaxFactory.Block(returnStatement)); var newDeclaration = declaration .WithAccessorList( SyntaxFactory.AccessorList( SyntaxFactory.SingletonList(accessorDeclaration))) .WithExpressionBody(null) .WithSemicolonToken(default(SyntaxToken)) .WithAdditionalAnnotations(Formatter.Annotation); var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = oldRoot.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitIndexerDeclaration(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitIndexerDeclaration(node); }
public void Add(IndexerDeclarationSyntax node) { if (IsLibrary) return; ISymbol s = Model.GetDeclaredSymbol(node); Function fGet = null; Function fSet = null; string sGet = string.Empty; string sSet = string.Empty; IMethodSymbol msGet = null; IMethodSymbol msSet = null; foreach (AccessorDeclarationSyntax ads in node.AccessorList.Accessors) { switch (ads.Keyword.CSharpKind()) { case SyntaxKind.GetKeyword: { msGet = Model.GetDeclaredSymbol(ads); if (!Chunk.Functions.TryGetValue(msGet, out fGet)) { throw new LS2ILMethodException("Method not found " + msGet.ToString()); } sGet = /*"get_" +*/ msGet.GetFullyQualifiedName(); } break; case SyntaxKind.SetKeyword: { msSet = Model.GetDeclaredSymbol(ads); if (!Chunk.Functions.TryGetValue(msSet, out fSet)) { throw new LS2ILMethodException("Method not found " + msSet.ToString()); } sSet = /*"set_" +*/ msSet.GetFullyQualifiedName(); } break; default: throw new NotImplementedException("unhandled property accessor: " + ads.Keyword.CSharpKind().ToString()); break; } } if (msGet != null) { FlatArrayBuilder fab = new FlatArrayBuilder(); fab.Add(FlatValue.Int32(s.IsStatic ? (int)ClassMemberType.StaticMethod : (int)ClassMemberType.Method)); fab.Add(FlatValue.String(sGet)); Function f; if (!Chunk.Functions.TryGetValue(msGet, out f)) { throw new LS2ILMethodException("Method not found " + msGet.ToString()); } fab.Add(FlatValue.Int32(f.NumFunction)); fab.Add(GenerateInputDeclarations(msGet).GetFlatValue()); Members.Add(fab.GetFlatValue()); } if (msSet != null) { FlatArrayBuilder fab = new FlatArrayBuilder(); fab.Add(FlatValue.Int32(s.IsStatic ? (int)ClassMemberType.StaticMethod : (int)ClassMemberType.Method)); fab.Add(FlatValue.String(sSet)); Function f; if (!Chunk.Functions.TryGetValue(msSet, out f)) { throw new LS2ILMethodException("Method not found " + msGet.ToString()); } fab.Add(FlatValue.Int32(f.NumFunction)); fab.Add(GenerateInputDeclarations(msSet).GetFlatValue()); Members.Add(fab.GetFlatValue()); } }
public void AddFunction(IndexerDeclarationSyntax node, SemanticModel Model) { IPropertySymbol ps = Model.GetDeclaredSymbol(node); foreach(AccessorDeclarationSyntax ads in node.AccessorList.Accessors) { IMethodSymbol ms = Model.GetDeclaredSymbol(ads); AddFunction(ms, Model); } /* Function f; if (Indexers.TryGetValue(ms, out f)) { return; } int nFunction = FunctionsByNumber.Count; f = new Function(this, nFunction, Model, ms); Functions.Add(f.IMethodSymbol, f); FunctionsByNumber.Add(f); if (ms.IsImplicitlyDeclared) { TypeExtraInfo tei = AddTypeExtraInfo(ms.ContainingType, Model, false); // assuming isLibrary=false because we have a function representing it in the chunk. tei.MetadataGenerator.Add(ms); } /**/ }
public override SyntaxNode VisitIndexerDeclaration(IndexerDeclarationSyntax node) { if (node == null) return null; var symbol = m_model.GetDeclaredSymbol(node); node = (IndexerDeclarationSyntax)base.VisitIndexerDeclaration(node); if (!IsPrivateOrInternal(symbol.DeclaredAccessibility)) node = (IndexerDeclarationSyntax)ApplyDocComment(node, symbol.GetDocumentationCommentId()); return node; }
private static Document GetTransformedDocumentForIndexerDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, IndexerDeclarationSyntax indexerDeclaration, CancellationToken cancellationToken) { if (indexerDeclaration.ExplicitInterfaceSpecifier == null && !indexerDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { ISymbol declaredSymbol = semanticModel.GetDeclaredSymbol(indexerDeclaration, cancellationToken); if (declaredSymbol == null || !NamedTypeHelpers.IsImplementingAnInterfaceMember(declaredSymbol)) { return document; } } return InsertInheritdocComment(document, diagnostic, root, indexerDeclaration, cancellationToken); }
private static IndexerDeclarationSyntax UseExpressionBodyIfDesired( Workspace workspace, IndexerDeclarationSyntax declaration, ParseOptions options) { if (declaration.ExpressionBody == null) { var preferExpressionBody = workspace.Options.GetOption(CSharpCodeStyleOptions.PreferExpressionBodiedIndexers).Value; if (preferExpressionBody) { var expressionBody = TryGetExpressionBody(declaration.AccessorList, options); if (expressionBody != null) { declaration = declaration.WithAccessorList(null) .WithExpressionBody(expressionBody) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } } } return declaration; }
/// <summary> /// Given a syntax node that declares an indexer, get the corresponding declared symbol. /// </summary> /// <param name="declarationSyntax">The syntax node that declares an indexer.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The symbol that was declared.</returns> public abstract IPropertySymbol GetDeclaredSymbol(IndexerDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken));
public static void Go(OutputWriter writer, IndexerDeclarationSyntax property, bool isProxy = false) { WriteProperty.Go(writer, property, isProxy); }
public override IPropertySymbol GetDeclaredSymbol(IndexerDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken)) { // Can't define indexer inside member. return null; }
/// <summary> /// A position is inside a property body only if it is inside an expression body. /// All block bodies for properties are part of the accessor declaration (a type /// of BaseMethodDeclaration), not the property declaration. /// </summary> internal static bool IsInBody(int position, IndexerDeclarationSyntax indexer) { var exprOpt = indexer.GetExpressionBodySyntax(); return IsInExpressionBody(position, exprOpt, indexer.SemicolonToken); }
public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { base.VisitIndexerDeclaration(node); if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.VirtualKeyword) || m.IsKind(SyntaxKind.NewKeyword) || m.IsKind(SyntaxKind.PartialKeyword))) return; if (node.GetBodies().IsEmpty()) return; var member = model.GetDeclaredSymbol(node); if (member.IsOverride) return; if (member.ExplicitInterfaceImplementations().Length > 0) return; if (GetImplementingInterface(member, member.ContainingType) != null) return; Analyze(node.ParameterList.Parameters, node.GetBodies()); }
public override void VisitIndexerDeclaration (IndexerDeclarationSyntax node) { base.VisitIndexerDeclaration (node); Append (node); }
private static SyntaxNode HandleIndexerDeclaration(IndexerDeclarationSyntax node) { TypeSyntax type = node.Type; if (type == null || type.IsMissing) { return null; } SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref type, SyntaxKind.PrivateKeyword); return node .WithType(type) .WithModifiers(modifiers) .WithoutFormatting(); }
private static async Task<Document> ReplaceWithExpressionBodiedMember(Document document, IndexerDeclarationSyntax declaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia; var expression = GetExpression(declaration.AccessorList, out leadingTrivia); var declarationTrivia = declaration.GetLeadingTrivia(); declarationTrivia = declarationTrivia.AddRange(leadingTrivia); var newDeclaration = declaration .WithLeadingTrivia(declarationTrivia) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression)) .WithAccessorList(null) .WithSemicolonToken(GetSemicolon(declaration.AccessorList)) .WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }
/// <summary> /// Given a syntax node that declares an indexer, get the corresponding declared symbol. /// </summary> /// <param name="declarationSyntax">The syntax node that declares an indexer.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The symbol that was declared.</returns> public override IPropertySymbol GetDeclaredSymbol(IndexerDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken)) { return (IPropertySymbol)GetDeclaredMemberSymbol(declarationSyntax); }
public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { CheckXmlDocForErrors(node, semanticModel.GetDeclaredSymbol(node)); }
public override SyntaxNode VisitIndexerDeclaration(IndexerDeclarationSyntax node) { //return base.VisitIndexerDeclaration(node); /* public override AccessorListSyntax AccessorList { get; } public override SyntaxList<AttributeListSyntax> AttributeLists { get; } public override ExplicitInterfaceSpecifierSyntax ExplicitInterfaceSpecifier { get; } public override SyntaxTokenList Modifiers { get; } public BracketedParameterListSyntax ParameterList { get; } public SyntaxToken ThisKeyword { get; } public override TypeSyntax Type { get; } */ BlockSyntax block = SyntaxFactory.Block(); /* // Summary: // Gets the attribute declaration list. public SyntaxList<AttributeListSyntax> AttributeLists { get; } // // Summary: // Gets the optional body block which may be empty, but it is null if there // are no braces. public BlockSyntax Body { get; } // // Summary: // Gets the keyword token, or identifier if an erroneous accessor declaration. public SyntaxToken Keyword { get; } // // Summary: // Gets the modifier list. public SyntaxTokenList Modifiers { get; } // // Summary: // Gets the optional semicolon token. public SyntaxToken SemicolonToken { get; } */ foreach(AccessorDeclarationSyntax ads in node.AccessorList.Accessors) { block = block.WithStatements( SyntaxFactory.MethodDeclaration(ads.AttributeLists, ads.Modifiers, node.Type, node.ExplicitInterfaceSpecifier, SyntaxFactory.Identifier(ads.Keyword.ToString() + "_item"), SyntaxFactory.TypeParameterList(), SyntaxFactory.ParameterList(node.ParameterList.Parameters), SyntaxFactory.List<TypeParameterConstraintClauseSyntax>(), ads.Body) ); } return block; //return base.VisitIndexerDeclaration(node); }