Beispiel #1
0
 /// <nodoc/>
 public AccessorDeclarations(IAccessorDeclaration firstAccessor, IAccessorDeclaration secondAccessor, IAccessorDeclaration getAccessor, IAccessorDeclaration setAccessor)
 {
     FirstAccessor  = firstAccessor;
     SecondAccessor = secondAccessor;
     GetAccessor    = getAccessor;
     SetAccessor    = setAccessor;
 }
Beispiel #2
0
        /// <summary>
        /// Ensures if the declaration has more than 1 accessor that they are in the correct order.
        /// </summary>
        /// <param name="declarationNode">
        /// The node to use.
        /// </param>
        public static void CheckAccessorOrder(IAccessorOwnerDeclaration declarationNode)
        {
            TreeNodeCollection <IAccessorDeclaration> accessorDeclarations = declarationNode.AccessorDeclarations;

            if (accessorDeclarations.Count < 2)
            {
                // don't need to reorder because there's only 1 (or none)
                return;
            }

            // we now know we have 2 accessors
            IAccessorDeclaration firstAccessor  = accessorDeclarations[0];
            IAccessorDeclaration secondAccessor = accessorDeclarations[1];

            if (firstAccessor.Kind == AccessorKind.GETTER || firstAccessor.Kind == AccessorKind.ADDER)
            {
                return;
            }

            IAccessorDeclaration newAccessor = firstAccessor.CopyWithResolve();

            declarationNode.AddAccessorDeclarationAfter(newAccessor, secondAccessor);
            declarationNode.RemoveAccessorDeclaration(firstAccessor);

            LayoutRules.ClosingCurlyBracketMustBeFollowedByBlankLine(declarationNode);
        }
Beispiel #3
0
        public static AccessorDeclarations GetAllAccessorDeclarations(INodeArray <IDeclaration> declarations, IAccessorDeclaration accessor)
        {
            IAccessorDeclaration firstAccessor  = null;
            IAccessorDeclaration secondAccessor = null;
            IAccessorDeclaration getAccessor    = null;
            IAccessorDeclaration setAccessor    = null;

            if (HasDynamicName(accessor))
            {
                firstAccessor = accessor;
                if (accessor.Kind == SyntaxKind.GetAccessor)
                {
                    getAccessor = accessor;
                }
                else if (accessor.Kind == SyntaxKind.SetAccessor)
                {
                    setAccessor = accessor;
                }
                else
                {
                    Contract.Assert(false, "Accessor has wrong kind");
                }
            }
            else
            {
                NodeArrayExtensions.ForEach(declarations, member =>
                {
                    if ((member.Kind == SyntaxKind.GetAccessor || member.Kind == SyntaxKind.SetAccessor) &&
                        (member.Flags & NodeFlags.Static) == (accessor.Flags & NodeFlags.Static))
                    {
                        var memberName   = GetPropertyNameForPropertyNameNode(member.Name);
                        var accessorName = GetPropertyNameForPropertyNameNode(accessor.Name);
                        if (memberName == accessorName)
                        {
                            if (firstAccessor == null)
                            {
                                firstAccessor = member.Cast <IAccessorDeclaration>();
                            }
                            else if (secondAccessor == null)
                            {
                                secondAccessor = member.Cast <IAccessorDeclaration>();
                            }

                            if (member.Kind == SyntaxKind.GetAccessor && getAccessor == null)
                            {
                                getAccessor = member.Cast <IAccessorDeclaration>();
                            }

                            if (member.Kind == SyntaxKind.SetAccessor && setAccessor == null)
                            {
                                setAccessor = member.Cast <IAccessorDeclaration>();
                            }
                        }
                    }
                });
            }

            return(new AccessorDeclarations(firstAccessor, secondAccessor, getAccessor, setAccessor));
        }
        /// <summary>Inspects the control graf.</summary>
        /// <param name="getter">The getter.</param>
        /// <returns>Returns the control graf.</returns>
        public CodeAnnotationAttribute InspectControlGraf([NotNull] IAccessorDeclaration getter)
        {
            if (getter == null)
            {
                throw new ArgumentNullException("getter");
            }

            return(Inspect(getter));
        }
        public override void EnterAccessor(IAccessorDeclaration accessorDeclarationNode)
        {
            if (IsValid() == false)
            {
                return;
            }

            if (accessorDeclarationNode == null)
            {
                return;
            }

            var accessor = new AccessorDeclarationModel(AnalyzeUnit, accessorDeclarationNode, BlockModelsStack.Peek());

            Model.Accessors.Add(accessor);

            BlockModelsStack.Push(accessor);
        }
Beispiel #6
0
 public virtual void EnterAccessor(IAccessorDeclaration accessorDeclarationNode)
 {
 }
        /// <summary>Builds the value parameter.</summary>
        /// <param name="typeMember">The type member.</param>
        /// <param name="getter">The getter.</param>
        /// <param name="setter">The setter.</param>
        private void BuildValueParameter([NotNull] ITypeMemberDeclaration typeMember, [NotNull] IAccessorDeclaration getter, [CanBeNull] IAccessorDeclaration setter)
        {
            if (typeMember == null)
            {
                throw new ArgumentNullException("typeMember");
            }

            if (getter == null)
            {
                throw new ArgumentNullException("getter");
            }

            var returnType = getter.DeclaredElement.ReturnType;

            if (!returnType.IsReferenceType())
            {
                return;
            }

            var expectsAssertion  = false;
            var assertionCode     = string.Empty;
            var appliedAttribute  = this.AppliedReturn;
            var expectedAttribute = this.ExpectedReturn;

            if (appliedAttribute == CodeAnnotationAttribute.CanBeNull)
            {
            }
            else if (appliedAttribute == CodeAnnotationAttribute.NotNull || expectedAttribute == CodeAnnotationAttribute.NotNull)
            {
                if (this.GenerateAssertions)
                {
                    if (setter != null && setter.Body != null)
                    {
                        assertionCode = this.GetCode();
                        if (!string.IsNullOrEmpty(assertionCode))
                        {
                            assertionCode    = string.Format(assertionCode, "value").Trim();
                            expectsAssertion = true;
                        }
                    }
                }
            }

            var descriptor = new ParameterDescriptor(expectedAttribute, appliedAttribute, expectsAssertion, assertionCode);

            this.parameters.Add(descriptor);
        }
Beispiel #8
0
 public AccessorDeclarationCompiler(IAccessorDeclaration accessor, AbstractILCompilerParams myParams) : base(myParams)
 {
     myAccessor = accessor;
     MyParams.CreateMethod(accessor.DeclaredElement);
 }