示例#1
0
        internal static bool IsInMethodDeclaration(int position, AccessorDeclarationSyntax accessorDecl)
        {
            Debug.Assert(accessorDecl != null);

            var body = accessorDecl.Body;
            SyntaxToken lastToken = body == null ? accessorDecl.SemicolonToken : body.CloseBraceToken;
            return IsBeforeToken(position, accessorDecl, lastToken);
        }
 public override void VisitAccessorDeclaration(Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax node)
 {
     base.VisitAccessorDeclaration(node);
     if (node.Body == null)
     {
         return;
     }
     VisitBody("Accessor", node.Keyword, node.Body, semanticModel.GetDeclaredSymbol(node.Parent.Parent), node.Kind());
 }
        private IFieldSymbol GetBackingFieldFromGetter(AccessorDeclarationSyntax getter)
        {
            if (getter.Body?.Statements.Count != 1) return null;

            var statement = getter.Body.Statements.Single() as ReturnStatementSyntax;
            if (statement?.Expression == null) return null;

            return _semanticModel.GetSymbolInfo(statement.Expression).Symbol as IFieldSymbol;
        }
			/// <summary>
			/// Called when the visitor visits a AccessorDeclarationSyntax node.
			/// </summary>
			public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
			{
				if (node.Body == null)
				{
					_counter++;
				}

				base.VisitAccessorDeclaration(node);
			}
		public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
		{
			if (!this.InsideFluentOrInitializerExample) return;
			var syntaxNode = node?.ChildNodes()?.LastOrDefault()?.WithAdditionalAnnotations() as BlockSyntax;
			if (syntaxNode == null) return;
			var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line;
			var walker = new CodeWithDocumentationWalker(ClassDepth, line);
			walker.VisitBlock(syntaxNode);
			this.Blocks.AddRange(walker.Blocks);
		}
        protected IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, AccessorDeclarationSyntax node)
        {
            var propertyOrIndexerDeclaration = node.Ancestors().Where(n => n.GetType().Equals(typeof(PropertyDeclarationSyntax)) || n.GetType().Equals(typeof(IndexerDeclarationSyntax))).FirstOrDefault();

            var nullableType = propertyOrIndexerDeclaration.ChildNodes().OfType<NullableTypeSyntax>().FirstOrDefault();
            
            var objectType = propertyOrIndexerDeclaration.ChildNodes().OfType<IdentifierNameSyntax>().FirstOrDefault();

            return GetActions(document, root, node, nullableType, objectType);
        }
        protected IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, MethodDeclarationSyntax methodNode, AccessorDeclarationSyntax getterNode)
        {
            if (methodNode != null)
                return GetActions(document, root, methodNode);

            if (getterNode != null)
                return GetActions(document, root, getterNode);

            return Enumerable.Empty<CodeAction>();
        }
示例#8
0
        /// <summary>
        /// Retrieves the get and set accessor declarations of the specified property.
        /// Returns true if both get and set accessors exist; otherwise false.
        /// </summary>
        internal static bool TryGetAccessors(
            PropertyDeclarationSyntax property,
            out AccessorDeclarationSyntax getter,
            out AccessorDeclarationSyntax setter)
        {
            var accessors = property.AccessorList.Accessors;
            getter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration);
            setter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.SetAccessorDeclaration);

            return accessors.Count == 2 && getter != null && setter != null;
        }
 static string GetMessageArgument(AccessorDeclarationSyntax node)
 {
     switch (node.Kind())
     {
         case SyntaxKind.SetAccessorDeclaration:
             return GettextCatalog.GetString("setter");
         case SyntaxKind.AddAccessorDeclaration:
             return GettextCatalog.GetString("add accessor");
         case SyntaxKind.RemoveAccessorDeclaration:
             return GettextCatalog.GetString("remove accessor");
     }
     return null;
 }
            public override VisualBasicSyntaxNode VisitAccessorDeclaration(CSS.AccessorDeclarationSyntax node)
            {
                SyntaxKind blockKind;
                AccessorStatementSyntax      stmt;
                EndBlockStatementSyntax      endStmt;
                SyntaxList <StatementSyntax> body = SyntaxFactory.List <StatementSyntax>();

                if (node.Body != null)
                {
                    body = SyntaxFactory.List(node.Body.Statements.SelectMany(s => s.Accept(new MethodBodyVisitor(semanticModel, this))));
                }
                var             attributes = SyntaxFactory.List(node.AttributeLists.Select(a => (AttributeListSyntax)a.Accept(this)));
                var             modifiers  = ConvertModifiers(node.Modifiers, TokenContext.Member);
                var             parent     = (CSS.BasePropertyDeclarationSyntax)node.Parent.Parent;
                ParameterSyntax valueParam;

                switch (CS.CSharpExtensions.Kind(node))
                {
                case CS.SyntaxKind.GetAccessorDeclaration:
                    blockKind = SyntaxKind.GetAccessorBlock;
                    stmt      = SyntaxFactory.GetAccessorStatement(attributes, modifiers, null);
                    endStmt   = SyntaxFactory.EndGetStatement();
                    break;

                case CS.SyntaxKind.SetAccessorDeclaration:
                    blockKind  = SyntaxKind.SetAccessorBlock;
                    valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")).WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(this)));
                    stmt       = SyntaxFactory.SetAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                    endStmt    = SyntaxFactory.EndSetStatement();
                    break;

                case CS.SyntaxKind.AddAccessorDeclaration:
                    blockKind  = SyntaxKind.AddHandlerAccessorBlock;
                    valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")).WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(this)));
                    stmt       = SyntaxFactory.AddHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                    endStmt    = SyntaxFactory.EndAddHandlerStatement();
                    break;

                case CS.SyntaxKind.RemoveAccessorDeclaration:
                    blockKind  = SyntaxKind.RemoveHandlerAccessorBlock;
                    valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")).WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(this)));
                    stmt       = SyntaxFactory.RemoveHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                    endStmt    = SyntaxFactory.EndRemoveHandlerStatement();
                    break;

                default:
                    throw new NotSupportedException();
                }
                return(SyntaxFactory.AccessorBlock(blockKind, stmt, body, endStmt));
            }
示例#11
0
        public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
        {
            if (node.Body != null && node.Parent is BasePropertyDeclarationSyntax)
              {
            var z = model.GetDeclaredSymbol(node.Parent as PropertyDeclarationSyntax);

            cb.AppendWithIndent(z.Type.ToCppType())
              .Append(" ")
              .Append(settings.GetPrefix)
              .Append(z.Name)
              .AppendLine("() const");
              }
              base.VisitAccessorDeclaration(node);
        }
        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind == SyntaxKind.GetAccessorDeclaration || syntax.Kind == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind == SyntaxKind.GetAccessorDeclaration);
            bool isWinMd = property.IsCompilationOutputWinMdObj();
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            if ((object)explicitlyImplementedPropertyOpt == null)
            {
                name = GetAccessorName(propertyName, isGetMethod, isWinMd);
                explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
            }
            else
            {
                MethodSymbol implementedAccessor = isGetMethod ? explicitlyImplementedPropertyOpt.GetMethod : explicitlyImplementedPropertyOpt.SetMethod;
                string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name
                    : GetAccessorName(explicitlyImplementedPropertyOpt.MetadataName, isGetMethod, isWinMd); //Not name - could be indexer placeholder
                name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedPropertyOpt.ContainingType, aliasQualifierOpt);
                explicitInterfaceImplementations =
                    (object)implementedAccessor == null ?
                        ImmutableArray<MethodSymbol>.Empty :
                        ImmutableArray.Create<MethodSymbol>(implementedAccessor);
            }

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
        static bool FindIssuesInAccessor(SemanticModel semanticModel, AccessorDeclarationSyntax accessor)
        {
            var body = accessor.Body;
            if (!IsEligible(body))
                return false;

            if (body.Statements.Any())
            {
                var foundValueSymbol = semanticModel.LookupSymbols(body.Statements.First().SpanStart, null, "value").FirstOrDefault();
                if (foundValueSymbol == null)
                    return false;

                foreach (var valueRef in body.DescendantNodes().OfType<IdentifierNameSyntax>().Where(ins => ins.Identifier.ValueText == "value"))
                {
                    var valueRefSymbol = semanticModel.GetSymbolInfo(valueRef).Symbol;
                    if (foundValueSymbol.Equals(valueRefSymbol))
                        return false;
                }
            }

            return true;
        }
        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind() == SyntaxKind.GetAccessorDeclaration || syntax.Kind() == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind() == SyntaxKind.GetAccessorDeclaration);
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            GetNameAndExplicitInterfaceImplementations(
                explicitlyImplementedPropertyOpt,
                propertyName,
                property.IsCompilationOutputWinMdObj(),
                aliasQualifierOpt,
                isGetMethod,
                out name,
                out explicitInterfaceImplementations);

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
        private static bool TryGetFieldFromGetter(AccessorDeclarationSyntax getter, SemanticModel semanticModel, out IFieldSymbol getterField)
        {
            getterField = null;
            if (getter.Body == null ||
                getter.Body.Statements.Count != 1)
            {
                return false;
            }

            var statement = getter.Body.Statements[0] as ReturnStatementSyntax;
            if (statement == null ||
                statement.Expression == null)
            {
                return false;
            }

            return TryGetField(statement.Expression, semanticModel.GetDeclaredSymbol(getter).ContainingType,
                semanticModel, out getterField);
        }
        private static bool TryGetFieldFromSetter(AccessorDeclarationSyntax setter, SemanticModel semanticModel, out IFieldSymbol setterField)
        {
            setterField = null;
            if (setter.Body == null ||
                setter.Body.Statements.Count != 1)
            {
                return false;
            }

            var statement = setter.Body.Statements[0] as ExpressionStatementSyntax;
            var assignment = statement?.Expression as AssignmentExpressionSyntax;
            if (assignment == null ||
                !assignment.IsKind(SyntaxKind.SimpleAssignmentExpression))
            {
                return false;
            }

            var parameter = semanticModel.GetSymbolInfo(assignment.Right).Symbol as IParameterSymbol;
            if (parameter == null ||
                parameter.Name != "value" ||
                !parameter.IsImplicitlyDeclared)
            {
                return false;
            }

            return TryGetField(assignment.Left, semanticModel.GetDeclaredSymbol(setter).ContainingType,
                semanticModel, out setterField);
        }
 private static IEnumerable<SyntaxKind> GetModifierKinds(AccessorDeclarationSyntax accessor)
 {
     return accessor.Modifiers.Select(m => m.Kind());
 }
 private static bool IsMultiline(AccessorDeclarationSyntax accessorDeclaration)
 {
     var lineSpan = accessorDeclaration.GetLineSpan();
     return lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line;
 }
        private DeclarationModifiers MakeModifiers(AccessorDeclarationSyntax syntax, Location location, DiagnosticBag diagnostics, out bool modifierErrors)
        {
            // No default accessibility. If unset, accessibility
            // will be inherited from the property.
            const DeclarationModifiers defaultAccess = DeclarationModifiers.None;

            // Check that the set of modifiers is allowed
            const DeclarationModifiers allowedModifiers = DeclarationModifiers.AccessibilityMask;
            var mods = ModifierUtils.MakeAndCheckNontypeMemberModifiers(syntax.Modifiers, defaultAccess, allowedModifiers, location, diagnostics, out modifierErrors);

            // For interface, check there are no accessibility modifiers.
            // (This check is handled outside of MakeAndCheckModifiers
            // since a distinct error message is reported for interfaces.)
            if (this.ContainingType.IsInterface)
            {
                if ((mods & DeclarationModifiers.AccessibilityMask) != 0)
                {
                    diagnostics.Add(ErrorCode.ERR_PropertyAccessModInInterface, location, this);
                    mods = (mods & ~DeclarationModifiers.AccessibilityMask);
                }
            }

            return mods;
        }
示例#20
0
		private string GetRemoveEventHandlerSignatureString(AccessorDeclarationSyntax accessor)
		{
			var syntax = (EventDeclarationSyntax)accessor.Parent.Parent;
			var builder = new StringBuilder();
			AppendMethodIdentifier(syntax, builder);
			builder.Append(".remove");
			AppendParameters(syntax, builder);
			builder.Append(" : void");
			return builder.ToString();
		}
        private SourcePropertyAccessorSymbol(
            NamedTypeSymbol containingType,
            string name,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations,
            Location location,
            AccessorDeclarationSyntax syntax,
            MethodKind methodKind,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics) :
            base(containingType, syntax.GetReference(), syntax.Body?.GetReference(), location)
        {
            _property = property;
            _explicitInterfaceImplementations = explicitInterfaceImplementations;
            _name = name;
            _isAutoPropertyAccessor = isAutoPropertyAccessor;

            bool modifierErrors;
            var declarationModifiers = this.MakeModifiers(syntax, location, diagnostics, out modifierErrors);

            // Include modifiers from the containing property.
            propertyModifiers &= ~DeclarationModifiers.AccessibilityMask;
            if ((declarationModifiers & DeclarationModifiers.Private) != 0)
            {
                // Private accessors cannot be virtual.
                propertyModifiers &= ~DeclarationModifiers.Virtual;
            }
            declarationModifiers |= propertyModifiers & ~DeclarationModifiers.Indexer;

            // ReturnsVoid property is overridden in this class so
            // returnsVoid argument to MakeFlags is ignored.
            this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false,
                isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any());

            var bodyOpt = syntax.Body;
            if (bodyOpt != null)
            {
                CheckModifiersForBody(location, diagnostics);
            }

            var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers);
            if (info != null)
            {
                diagnostics.Add(info, location);
            }

            if (!modifierErrors)
            {
                this.CheckModifiers(location, isAutoPropertyAccessor, diagnostics);
            }

            if (this.IsOverride)
            {
                MethodSymbol overriddenMethod = this.OverriddenMethod;
                if ((object)overriddenMethod != null)
                {
                    // If this accessor is overriding a method from metadata, it is possible that
                    // the name of the overridden method doesn't follow the C# get_X/set_X pattern.
                    // We should copy the name so that the runtime will recognize this as an override.
                    _name = overriddenMethod.Name;
                }
            }
        }
示例#22
0
 internal static bool IsInBody(int position, AccessorDeclarationSyntax method)
 => IsInBody(position, method.Body, method.GetExpressionBodySyntax(), method.SemicolonToken);
示例#23
0
        public AccessorBlockSyntax ConvertAccessor(CSS.AccessorDeclarationSyntax node, out bool isIterator, bool isAutoImplementedProperty = false)
        {
            SyntaxKind blockKind;
            AccessorStatementSyntax      stmt;
            EndBlockStatementSyntax      endStmt;
            SyntaxList <StatementSyntax> body;

            isIterator = false;
            var accesorKind     = CSharpExtensions.Kind(node);
            var isIteratorState = new MethodBodyExecutableStatementVisitor(_semanticModel, _nodesVisitor, this);

            body       = ConvertBody(node.Body, node.ExpressionBody, accesorKind == CSSyntaxKind.GetAccessorDeclaration, isIteratorState);
            isIterator = isIteratorState.IsIterator;
            var attributes = SyntaxFactory.List(node.AttributeLists.Select(a => (AttributeListSyntax)a.Accept(_nodesVisitor)));
            var modifiers  = ConvertModifiers(node.Modifiers, TokenContext.Local);
            var parent     = (CSS.BasePropertyDeclarationSyntax)node.Parent.Parent;

            Microsoft.CodeAnalysis.VisualBasic.Syntax.ParameterSyntax valueParam;

            switch (accesorKind)
            {
            case CSSyntaxKind.GetAccessorDeclaration:
                blockKind = SyntaxKind.GetAccessorBlock;
                stmt      = SyntaxFactory.GetAccessorStatement(attributes, modifiers, null);
                endStmt   = SyntaxFactory.EndGetStatement();
                if (isAutoImplementedProperty)
                {
                    body = body.Count > 0 ? body :
                           SyntaxFactory.SingletonList((StatementSyntax)SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName(GetVbPropertyBackingFieldName(parent))));
                }
                break;

            case CSSyntaxKind.SetAccessorDeclaration:
                blockKind  = SyntaxKind.SetAccessorBlock;
                valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value"))
                             .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false)))
                             .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword)));
                stmt    = SyntaxFactory.SetAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                endStmt = SyntaxFactory.EndSetStatement();
                if (isAutoImplementedProperty)
                {
                    body = body.Count > 0 ? body :
                           SyntaxFactory.SingletonList((StatementSyntax)SyntaxFactory.AssignmentStatement(SyntaxKind.SimpleAssignmentStatement,
                                                                                                          SyntaxFactory.IdentifierName(GetVbPropertyBackingFieldName(parent)),
                                                                                                          SyntaxFactory.Token(VBUtil.GetExpressionOperatorTokenKind(SyntaxKind.SimpleAssignmentStatement)),
                                                                                                          SyntaxFactory.IdentifierName("value")
                                                                                                          ));
                }
                break;

            case CSSyntaxKind.AddAccessorDeclaration:
                blockKind  = SyntaxKind.AddHandlerAccessorBlock;
                valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value"))
                             .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false)))
                             .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword)));
                stmt    = SyntaxFactory.AddHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                endStmt = SyntaxFactory.EndAddHandlerStatement();
                break;

            case CSSyntaxKind.RemoveAccessorDeclaration:
                blockKind  = SyntaxKind.RemoveHandlerAccessorBlock;
                valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value"))
                             .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false)))
                             .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword)));
                stmt    = SyntaxFactory.RemoveHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam)));
                endStmt = SyntaxFactory.EndRemoveHandlerStatement();
                break;

            default:
                throw new NotSupportedException();
            }
            return(SyntaxFactory.AccessorBlock(blockKind, stmt, body, endStmt).WithCsSourceMappingFrom(node));
        }
        /// <summary>
        /// Given an syntax node that declares a property or member accessor, get the corresponding symbol.
        /// </summary>
        /// <param name="declarationSyntax">The syntax node that declares an accessor.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The symbol that was declared.</returns>
        public override IMethodSymbol GetDeclaredSymbol(AccessorDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckSyntaxNode(declarationSyntax);

            if (declarationSyntax.Kind() == SyntaxKind.UnknownAccessorDeclaration)
            {
                // this is not a real accessor, so we shouldn't return anything.
                return null;
            }

            var propertyOrEventDecl = declarationSyntax.Parent.Parent;

            switch (propertyOrEventDecl.Kind())
            {
                case SyntaxKind.PropertyDeclaration:
                case SyntaxKind.IndexerDeclaration:
                case SyntaxKind.EventDeclaration:
                case SyntaxKind.EventFieldDeclaration:
                    // NOTE: it's an error for field-like events to have accessors, 
                    // but we want to bind them anyway for error tolerance reasons.
                    var container = GetDeclaredTypeMemberContainer(propertyOrEventDecl);
                    Debug.Assert((object)container != null);
                    Debug.Assert(declarationSyntax.Keyword.Kind() != SyntaxKind.IdentifierToken);
                    return this.GetDeclaredMember(container, declarationSyntax.Span) as MethodSymbol;

                default:
                    throw ExceptionUtilities.UnexpectedValue(propertyOrEventDecl.Kind());
            }
        }
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return false;
 }
示例#26
0
 public override IMethodSymbol GetDeclaredSymbol(AccessorDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define accessor inside member.
     return null;
 }
 // Create AccessorSymbol for AccessorDeclarationSyntax
 private SourcePropertyAccessorSymbol CreateAccessorSymbol(AccessorDeclarationSyntax syntaxOpt,
     PropertySymbol explicitlyImplementedPropertyOpt, string aliasQualifierOpt, bool isAutoPropertyAccessor, DiagnosticBag diagnostics)
 {
     if (syntaxOpt == null)
     {
         return null;
     }
     return SourcePropertyAccessorSymbol.CreateAccessorSymbol(_containingType, this, _modifiers, _sourceName, syntaxOpt,
         explicitlyImplementedPropertyOpt, aliasQualifierOpt, isAutoPropertyAccessor, diagnostics);
 }
示例#28
0
 public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
 {
     VisitBlock(node.Body);
 }
        internal sealed override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
        {
            position = CheckAndAdjustPosition(position);

            var model = this.GetMemberModel(position);
            if (model != null)
            {
                return model.TryGetSpeculativeSemanticModelForMethodBodyCore(parentModel, position, accessor, out speculativeModel);
            }

            speculativeModel = null;
            return false;
        }
            private void ClassifyUpdate(AccessorDeclarationSyntax oldNode, AccessorDeclarationSyntax newNode)
            {
                if (!SyntaxFactory.AreEquivalent(oldNode.Modifiers, newNode.Modifiers))
                {
                    ReportError(RudeEditKind.ModifiersUpdate);
                    return;
                }

                if (oldNode.Kind() != newNode.Kind())
                {
                    ReportError(RudeEditKind.AccessorKindUpdate);
                    return;
                }

                Debug.Assert(newNode.Parent is AccessorListSyntax);
                Debug.Assert(newNode.Parent.Parent is BasePropertyDeclarationSyntax);

                ClassifyMethodBodyRudeUpdate(
                    oldNode.Body,
                    newNode.Body,
                    containingMethodOpt: null,
                    containingType: (TypeDeclarationSyntax)newNode.Parent.Parent.Parent);
            }
 private void ClassifyAccessorInsert(AccessorDeclarationSyntax accessor)
 {
     var baseProperty = (BasePropertyDeclarationSyntax)accessor.Parent.Parent;
     ClassifyModifiedMemberInsert(baseProperty.Modifiers);
 }
示例#32
0
		private string GetPropertyGetterSignatureString(AccessorDeclarationSyntax syntax)
		{
			var propertyDeclarationSyntax = syntax.Parent.Parent as PropertyDeclarationSyntax;
			var identifier = GetMethodIdentifier(propertyDeclarationSyntax) + ".get()";
			var returnType = GetReturnType(propertyDeclarationSyntax);
			return identifier + returnType;
		}
示例#33
0
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
 {
     return GetSpeculativeSemanticModelForMethodBody(parentModel, position, accessor.Body, out speculativeModel);
 }
示例#34
0
		private string GetPropertySetterSignatureString(AccessorDeclarationSyntax syntax)
		{
			var propertyDeclarationSyntax = syntax.Parent.Parent as PropertyDeclarationSyntax;
			var identifier = GetMethodIdentifier(propertyDeclarationSyntax);
			var parameters = GetParameters(propertyDeclarationSyntax);

			return string.Format("{0}.set{1} : void", identifier, parameters);
		}