public static ICollection GetProperties(ITypeDeclaration value, IVisibilityConfiguration visibility)
        {
            IPropertyDeclarationCollection properties = value.Properties;
            ICollection result;

            if (properties.Count > 0)
            {
                ArrayList arrayList = new ArrayList(0);
                foreach (object obj in properties)
                {
                    IPropertyDeclaration value2 = (IPropertyDeclaration)obj;
                    if (visibility == null || IsVisible(value2, visibility))
                    {
                        arrayList.Add(value2);
                    }
                }
                arrayList.Sort();
                result = arrayList;
            }
            else
            {
                result = new IPropertyDeclaration[0];
            }
            return(result);
        }
        protected override void ConvertProperty(
            PropertyConverter propertyConverter, IPropertyDeclaration propertyDeclaration)
        {
            Argument.IsNotNull(() => propertyConverter);

            propertyConverter.Convert(propertyDeclaration);
        }
Example #3
0
        public IBulbAction[] GetPropertyFixes(IPropertyDeclaration declaration)
        {
            var map    = new AddBsonElementAttribute(declaration);
            var ignore = new AddBsonIgnoreAttribute(declaration);
            var mapId  = new AddBsonIdAttribute(declaration);

            if (declaration.AccessorDeclarations.Count < 2)
            {
                return new IBulbAction[]
                       {
                           ignore,
                           map,
                           mapId
                       }
            }
            ;

            if (declaration.DeclaredName.ToLowerInvariant() == "id")
            {
                return new IBulbAction[]
                       {
                           mapId,
                           map,
                           ignore
                       }
            }
            ;

            return(new IBulbAction[]
            {
                map,
                mapId,
                ignore
            });
        }
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility visibility = MethodVisibility.Public;

            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethodReference = propertyDeclaration.SetMethod;
                IMethodDeclaration setMethod          = (setMethodReference == null) ? null : setMethodReference.Resolve();

                IMethodReference   getMethodReference = propertyDeclaration.GetMethod;
                IMethodDeclaration getMethod          = (getMethodReference == null) ? null : getMethodReference.Resolve();

                if ((setMethod != null) && (getMethod != null))
                {
                    if (getMethod.Visibility == setMethod.Visibility)
                    {
                        visibility = getMethod.Visibility;
                    }
                }
                else if (setMethod != null)
                {
                    visibility = setMethod.Visibility;
                }
                else if (getMethod != null)
                {
                    visibility = getMethod.Visibility;
                }
            }

            return(visibility);
        }
Example #5
0
        public SqlScriptIndexGeneratorContextAction(ICSharpContextActionDataProvider provider)
        {
            factory          = provider.ElementFactory;
            classDeclaration = provider.GetSelectedElement <IClassDeclaration>();

            propertyDeclaration = provider.GetSelectedElement <IPropertyDeclaration>();
        }
 private bool EnclosingClassImplementsINotifyPropertyChanged(IPropertyDeclaration propertyDeclaration)
 {
     return(propertyDeclaration.EnclosingClass
            .Type()
            .AllSuperTypesIncludingThis
            .Any(t => t.Is(NotifyPropertyChangedQualifiedTypeName)));
 }
Example #7
0
        private static bool HandleProperty(IPropertyDeclaration property, string propertyName, string requiredTypeName, string requiredMethodName, out string name)
        {
            name = null;
            if (!property.IsStatic)
            {
                return(false);
            }

            var accessors = property.AccessorDeclarations;

            if (accessors.Count != 1)
            {
                return(false);
            }

            if (accessors[0].Kind != AccessorKind.GETTER)
            {
                return(false);
            }

            if (property.DeclaredElement == null)
            {
                return(false);
            }

            var initializer = property.Initial;

            if (initializer is IExpressionInitializer exprInit && exprInit.Value is IInvocationExpression invocation)
            {
                return(HandleInvocation(invocation, propertyName, requiredTypeName, requiredMethodName, out name));
            }

            return(false);
        }
Example #8
0
        public override void VisitPropertyDeclaration(IPropertyDeclaration decl, SST context)
        {
            if (decl.DeclaredElement != null)
            {
                var name = decl.DeclaredElement.GetName <IPropertyName>();

                var propDecl = new PropertyDeclaration {
                    Name = name
                };
                context.Properties.Add(propDecl);

                if (decl == _marker.HandlingNode)
                {
                    var emptyCompletion = new ExpressionStatement {
                        Expression = new CompletionExpression()
                    };
                    if (_marker.Case == CompletionCase.InGetBody)
                    {
                        propDecl.Get.Add(emptyCompletion);
                    }
                    if (_marker.Case == CompletionCase.InSetBody)
                    {
                        propDecl.Set.Add(emptyCompletion);
                    }
                }

                AddAccessorDecl(decl, propDecl);
            }
        }
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility     result = MethodVisibility.Public;
            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethod          = propertyDeclaration.SetMethod;
                IMethodDeclaration methodDeclaration  = setMethod?.Resolve();
                IMethodReference   getMethod          = propertyDeclaration.GetMethod;
                IMethodDeclaration methodDeclaration2 = getMethod?.Resolve();
                if (methodDeclaration != null && methodDeclaration2 != null)
                {
                    if (methodDeclaration2.Visibility == methodDeclaration.Visibility)
                    {
                        result = methodDeclaration2.Visibility;
                    }
                }
                else if (methodDeclaration != null)
                {
                    result = methodDeclaration.Visibility;
                }
                else if (methodDeclaration2 != null)
                {
                    result = methodDeclaration2.Visibility;
                }
            }
            return(result);
        }
Example #10
0
        public static PropertyContractInfo TryCreate(
            [NotNull] IPropertyDeclaration declaration,
            TreeTextRange selectedTreeRange,
            [NotNull] Func <IType, bool> isAvailableForType)
        {
            if (declaration.GetNameRange().Contains(selectedTreeRange) &&
                declaration.ArrowClause == null &&
                declaration.AccessorDeclarations.Any(accessorDeclaration => accessorDeclaration.AssertNotNull().ArrowClause == null))
            {
                var property = declaration.DeclaredElement;

                Debug.Assert(property != null);

                if (CanAcceptContracts(property) && isAvailableForType(property.Type))
                {
                    var contractKind = declaration.IsAuto ? (declaration.IsStatic ? (ContractKind?)null : ContractKind.Invariant) :
                                       property.IsReadable ? (property.IsWritable ? ContractKind.RequiresAndEnsures : ContractKind.Ensures) :
                                       (property.IsWritable ? (ContractKind?)ContractKind.Requires : null);
                    if (contractKind != null)
                    {
                        return(new PropertyContractInfo((ContractKind)contractKind, declaration, property.Type));
                    }
                }
            }

            return(null);
        }
Example #11
0
        private bool CheckPropertyDecl(IPropertyDeclaration o, IPropertyDeclaration n)
        {
            if (o.DeclaringType.ToString() != n.DeclaringType.ToString() ||
                !CheckExp(o.Initializer, n.Initializer) ||
                o.Name != n.Name ||
                o.PropertyType.ToString() != n.PropertyType.ToString() ||
                o.RuntimeSpecialName != n.RuntimeSpecialName)
            {
                return(false);
            }

            if (!o.Attributes.Compare(n.Attributes, CheckCustomAttribute) ||
                !o.Parameters.Compare(n.Parameters, CheckParameterDecl))
            {
                return(false);
            }

            if (
                !CompareIMethodReference(o.GetMethod, n.GetMethod) ||
                !CompareIMethodReference(o.SetMethod, n.SetMethod))
            {
                return(false);
            }

            return(true);
        }
Example #12
0
        private bool CheckPropertyDecl(IPropertyDeclaration o, IPropertyDeclaration n)
        {
            if (o.DeclaringType.ToString() != n.DeclaringType.ToString() ||
                !CheckExp(o.Initializer, n.Initializer) ||
                o.Name != n.Name ||
                o.PropertyType.ToString() != n.PropertyType.ToString() ||
                o.RuntimeSpecialName != n.RuntimeSpecialName)
            {
                return(false);
            }

            if (
                !CheckCollection <ICustomAttributeCollection, ICustomAttribute>(
                    CheckCustomAttribute, o.Attributes, n.Attributes) ||

                !CheckCollection <IParameterDeclarationCollection, IParameterDeclaration>(
                    CheckParameterDecl, o.Parameters, n.Parameters)
                )
            {
                return(false);
            }

            if (
                !CheckMethodReference(o.GetMethod, n.GetMethod) ||
                !CheckMethodReference(o.SetMethod, n.SetMethod))
            {
                return(false);
            }

            return(true);
        }
Example #13
0
        /// <summary>
        /// The execute transaction inner.
        /// </summary>
        /// <param name="solution">
        /// The solution.
        /// </param>
        /// <param name="textControl">
        /// The text control.
        /// </param>
        public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl)
        {
            ITreeNode element = Utils.GetElementAtCaret(solution, textControl);

            IPropertyDeclaration propertyDeclaration = element.GetContainingNode <IPropertyDeclaration>(true);

            new DocumentationRules().InsertValueElement(propertyDeclaration);
        }
Example #14
0
 public PropertyDefinition GetPropertyDefinition(IPropertyDeclaration item)
 {
     return(TryGetOrAdd(_propertycache, item, pdef =>
     {
         var tdef = GetTypeDefinition(item.DeclaringType as ITypeDeclaration);
         return tdef == null ? null : ReflectorHelper.FindMatchingProperty(tdef, pdef);
     }));
 }
		public PropertyDefinition GetPropertyDefinition(IPropertyDeclaration item)
		{
			return TryGetOrAdd(_propertycache, item, pdef =>
			{
				var tdef = GetTypeDefinition(item.DeclaringType as ITypeDeclaration);
				return tdef == null ? null : ReflectorHelper.FindMatchingProperty(tdef, pdef);
			});
		}
        /// <summary>Inspects the specified method.</summary>
        /// <param name="property">The method.</param>
        public void Inspect([NotNull] IPropertyDeclaration property)
        {
            this.CodeAnnotation = new CodeAnnotation(property);
            if (!this.CodeAnnotation.IsValid)
            {
                return;
            }

            if (property.IsExtern)
            {
                return;
            }

            this.TypeMember    = property;
            this.AppliedReturn = this.CodeAnnotation.GetAnnotation(property);

            var getter = property.AccessorDeclarations.FirstOrDefault(a => a.Kind == AccessorKind.GETTER);
            var setter = property.AccessorDeclarations.FirstOrDefault(a => a.Kind == AccessorKind.SETTER);

            if (this.AppliedReturn != CodeAnnotationAttribute.Undefined && this.AppliedReturn != CodeAnnotationAttribute.NotSet)
            {
                this.ExpectedReturn = this.AppliedReturn;
            }
            else if (getter != null)
            {
                var attribute = this.CodeAnnotation.InspectControlGraf(getter);
                if (attribute != CodeAnnotationAttribute.Undefined && attribute != CodeAnnotationAttribute.NotSet)
                {
                    this.ExpectedReturn = attribute;
                }
                else if (attribute == CodeAnnotationAttribute.NotSet)
                {
                    this.ExpectedReturn = CodeAnnotationAttribute.NotNull;
                }
            }

            if (getter != null)
            {
                this.BuildValueParameter(this.TypeMember, getter, setter);
            }

            if (setter == null)
            {
                return;
            }

            var body = setter.Body;

            if (body == null)
            {
                return;
            }

            this.Body = body;

            // this.BuildParameters(setter, false);
            this.BuildAssertions(body);
        }
        public sealed override bool IsAvailable()
        {
            this.Property = this.DataProvider.SelectedElement?.Parent as IPropertyDeclaration;

            return
                (this.Property != null &&
                 this.DataProvider.SelectedElement == this.Property?.NameIdentifier &&
                 IsAvailableCore());
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyWriter"/> class.
        /// </summary>
        /// <param name="itfPatternProperty">Interface property pattern.</param>
        /// <param name="itfDeclarationProperties">Interface declaration properties to implement.</param>
        /// <param name="typeTextExtractor">Type text extractor used for type substitution (Properties and fields).</param>
        public PropertyWriter(
            IPropertyDeclaration itfPatternProperty,
            IReadOnlyCollection <IPropertyDeclaration> itfDeclarationProperties,
            Func <string, string> typeTextExtractor = null)
        {
            this.declarationProperties = itfDeclarationProperties;
            this.itfPatternProperty    = itfPatternProperty;

            this.typeTextExtractor = typeTextExtractor ?? IdentityExtract;
        }
Example #19
0
        public static IMethodDeclaration GetGetMethod(IPropertyReference value)
        {
            IPropertyDeclaration declaration2 = value.Resolve();

            if (declaration2.GetMethod != null)
            {
                return(declaration2.GetMethod.Resolve());
            }
            return(null);
        }
Example #20
0
 object Find(IPropertyDeclaration propertyDecl)
 {
     if (String.Equals(element.MemberName, propertyDecl.Name, StringComparison.InvariantCulture) &&
         (element.MemberReturnType == null || Is(propertyDecl.PropertyType, element.MemberReturnType)) &&
         CheckParameters(element.MemberParameters, propertyDecl.Parameters))
     {
         return(propertyDecl);
     }
     return(null);
 }
Example #21
0
 /// <exception cref="BadSyntaxException">
 /// The <paramref name="declaration"/> does not fit to the syntax.
 /// </exception>
 public override void InitFromDeclaration(IPropertyDeclaration declaration)
 {
     if (declaration is ICSharpPropertyDeclaration sharpDeclaration)
     {
         InitFromDeclaration(sharpDeclaration);
     }
     else
     {
         throw new BadSyntaxException(Strings.ErrorInvalidDeclaration);
     }
 }
        /// <summary>Gets the annotation.</summary>
        /// <param name="property">The property.</param>
        /// <returns>Returns the annotation.</returns>
        public CodeAnnotationAttribute GetAnnotation([NotNull] IPropertyDeclaration property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var attributesOwner = property.DeclaredElement as IAttributesOwner;

            return(attributesOwner != null?this.GetAnnotation(attributesOwner) : CodeAnnotationAttribute.Undefined);
        }
        public static IMethodDeclaration GetSetMethod(IPropertyReference value)
        {
            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration.SetMethod != null)
            {
                return(propertyDeclaration.SetMethod.Resolve());
            }

            return(null);
        }
Example #24
0
        public IBulbAction[] GetPropertyFixes(IPropertyDeclaration declaration)
        {
            var map    = new AddDataMemberAttribute(declaration);
            var ignore = new AddIgnoreDataMemberAttribute(declaration);

            return(new IBulbAction[]
            {
                map,
                ignore
            });
        }
        public static ICollection GetMethods(ITypeDeclaration value, IVisibilityConfiguration visibility)
        {
            IMethodDeclarationCollection methods = value.Methods;
            ICollection result;

            if (methods.Count > 0)
            {
                ArrayList arrayList = new ArrayList(0);
                foreach (object obj in methods)
                {
                    IMethodDeclaration value2 = (IMethodDeclaration)obj;
                    if (visibility == null || IsVisible(value2, visibility))
                    {
                        arrayList.Add(value2);
                    }
                }
                foreach (object obj2 in value.Properties)
                {
                    IPropertyDeclaration propertyDeclaration = (IPropertyDeclaration)obj2;
                    if (propertyDeclaration.SetMethod != null)
                    {
                        arrayList.Remove(propertyDeclaration.SetMethod.Resolve());
                    }
                    if (propertyDeclaration.GetMethod != null)
                    {
                        arrayList.Remove(propertyDeclaration.GetMethod.Resolve());
                    }
                }
                foreach (object obj3 in value.Events)
                {
                    IEventDeclaration eventDeclaration = (IEventDeclaration)obj3;
                    if (eventDeclaration.AddMethod != null)
                    {
                        arrayList.Remove(eventDeclaration.AddMethod.Resolve());
                    }
                    if (eventDeclaration.RemoveMethod != null)
                    {
                        arrayList.Remove(eventDeclaration.RemoveMethod.Resolve());
                    }
                    if (eventDeclaration.InvokeMethod != null)
                    {
                        arrayList.Remove(eventDeclaration.InvokeMethod.Resolve());
                    }
                }
                arrayList.Sort();
                result = arrayList;
            }
            else
            {
                result = new IMethodDeclaration[0];
            }
            return(result);
        }
        public static FieldOrPropertyDeclaration FromPropertyDeclaration(IPropertyDeclaration propertyDeclaration)
        {
            Contract.Requires(propertyDeclaration != null);

            return new FieldOrPropertyDeclaration
            {
                IsStatic = propertyDeclaration.IsStatic,
                Name = propertyDeclaration.NameIdentifier.Name,
                Type = propertyDeclaration.DeclaredElement.Type,
                Property = propertyDeclaration,
            };
        }
Example #27
0
        public static IPropertyDeclaration WithPrivateSetter([NotNull] this IPropertyDeclaration declaration,
                                                             CSharpElementFactory factory)
        {
            if (declaration == null)
            {
                throw new ArgumentNullException(nameof(declaration));
            }
            var setter = factory.CreateAccessorDeclaration(AccessorKind.SETTER, false);

            declaration.AddAccessorDeclarationBefore(setter, null);
            return(declaration);
        }
Example #28
0
        public IPropertyDeclaration Anonymize(IPropertyDeclaration d)
        {
            var defaultName   = Names.UnknownProperty;
            var isDefaultName = defaultName.Equals(d.Name);

            return(new PropertyDeclaration
            {
                Name = isDefaultName ? defaultName : d.Name.ToAnonymousName(),
                Get = _statementAnon.Anonymize(d.Get),
                Set = _statementAnon.Anonymize(d.Set)
            });
        }
        public static Action <ITextControl> Execute([CanBeNull] IPropertyDeclaration propertyDeclaration, ISolution solution, CSharpElementFactory elementFactory)
        {
            if (propertyDeclaration == null)
            {
                return(null);
            }

            var fieldDeclaration = AutomaticToBackingFieldAction.Execute(propertyDeclaration);

            AttributeUtil.AddAttributeToSingleDeclaration(fieldDeclaration, KnownTypes.SerializeField, propertyDeclaration.GetPsiModule(), elementFactory);
            return(AutomaticToBackingFieldAction.PostExecute(propertyDeclaration, fieldDeclaration, solution));
        }
        public static FieldOrPropertyDeclaration FromPropertyDeclaration(IPropertyDeclaration propertyDeclaration)
        {
            Contract.Requires(propertyDeclaration != null);

            return(new FieldOrPropertyDeclaration
            {
                IsStatic = propertyDeclaration.IsStatic,
                Name = propertyDeclaration.NameIdentifier.Name,
                Type = propertyDeclaration.DeclaredElement.Type,
                Property = propertyDeclaration,
            });
        }
Example #31
0
        /// <summary>
        /// Returns an IAccessor for the Setter.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// An IAccessor for the setter.
        /// </returns>
        public static IAccessor Setter(this IPropertyDeclaration propertyDeclaration)
        {
            foreach (IAccessorDeclaration declaration in propertyDeclaration.AccessorDeclarations)
            {
                IAccessor accessor = (IAccessor)declaration.DeclaredElement;

                if (accessor != null && accessor.Kind == AccessorKind.SETTER)
                {
                    return(accessor);
                }
            }

            return(null);
        }
Example #32
0
        public DialogReorder(IPropertyDeclaration[] attributes)
        {
            this.attributes = attributes;

            InitializeComponent();

            listOfOrder = new List<PropertyInOrder>();
            for (var i = 0; i < attributes.Length; i++)
            {
                listOfOrder.Add(new PropertyInOrder(attributes[i]) { Order = i });
            }

            this.dataGridViewOrders.DataSource = listOfOrder;
        }
Example #33
0
        public static bool HasGetSet([NotNull] this IPropertyDeclaration src)
        {
            if (src.AccessorDeclarations.All(x => x.Kind != AccessorKind.GETTER))
            {
                return(false);
            }

            if (src.AccessorDeclarations.All(x => x.Kind != AccessorKind.SETTER))
            {
                return(false);
            }

            return(true);
        }
Example #34
0
 public static PropertyInfo GetPropertyInfo([NotNull] this IPropertyDeclaration propertyDeclaration)
 {
     return(new PropertyInfo
     {
         ColumnName = propertyDeclaration.Attributes.FindAttribute(Constants.Column)?.Arguments.FirstOrDefault().GetLiteralText() ?? "TODOColumnName",
         Required = propertyDeclaration.Attributes.HasAttribute(Constants.Required),
         Key = propertyDeclaration.Attributes.HasAttribute(Constants.Key),
         MaxLength = propertyDeclaration.Attributes.FindAttribute(Constants.MaxLength)?.Arguments.FirstOrDefault().GetLiteralText(),
         Precision1 = propertyDeclaration.Attributes.FindAttribute(Constants.DecimalPrecision)?.Arguments.FirstOrDefault().GetLiteralText(),
         Precision2 = propertyDeclaration.Attributes.FindAttribute(Constants.DecimalPrecision)?.Arguments.LastOrDefault().GetLiteralText(),
         IsTimestamp = propertyDeclaration.Attributes.FindAttribute(Constants.TimestampAttribute) != null,
         Declaration = propertyDeclaration
     });
 }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            ClassDeclaration = null;
            PropertyDeclaration = null;
            FieldDeclaration = null;

            using (ReadLockCookie.Create())
            {
                ITreeNode selectedElement = Provider.SelectedElement;
                if (selectedElement != null && selectedElement.Parent != null
                    && selectedElement.Parent is IFieldDeclaration)
                {
                    FieldDeclaration = selectedElement.Parent as IFieldDeclaration;
                    if (FieldDeclaration.Parent != null && FieldDeclaration.Parent.Parent != null
                        && FieldDeclaration.Parent.Parent.Parent is IClassDeclaration)
                    {
                        ClassDeclaration = FieldDeclaration.Parent.Parent.Parent as IClassDeclaration;
                        var classDeclaredElement = ClassDeclaration.DeclaredElement;
                        if (classDeclaredElement != null && (classDeclaredElement.IsDescendantOf(CatelCore.GetDataObjectBaseTypeElement(Provider.PsiModule, selectedElement.GetResolveContext())) || classDeclaredElement.IsDescendantOf(CatelCore.GetModelBaseTypeElement(Provider.PsiModule, selectedElement.GetResolveContext()))) && (FieldDeclaration.IsStatic && FieldDeclaration.Initial is IExpressionInitializer))
                        {
                            var expressionInitializer = FieldDeclaration.Initial as IExpressionInitializer;
                            if (expressionInitializer.Value is IInvocationExpression)
                            {
                                var invocationExpression = expressionInitializer.Value as IInvocationExpression;
                                if (invocationExpression.InvokedExpression is IReferenceExpression)
                                {
                                    var referenceExpression = invocationExpression.InvokedExpression as IReferenceExpression;
                                    if (referenceExpression.NameIdentifier != null && referenceExpression.NameIdentifier.GetText() == RegisterPropertyExpressionHelper.RegisterPropertyMethodName)
                                    {
                                        PropertyDeclaration = RegisterPropertyExpressionHelper.GetPropertyDeclaration(ClassDeclaration, invocationExpression);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return ClassDeclaration != null && FieldDeclaration != null && PropertyDeclaration != null
                   && IsAvailable();
        }
        public override sealed bool IsAvailable(IUserDataHolder cache)
        {
            using (ReadLockCookie.Create())
            {
                var selectedElement = Provider.SelectedElement;
                var moduleReferenceResolveContext = selectedElement.GetResolveContext();
                if (selectedElement != null && selectedElement.Parent is IPropertyDeclaration)
                {
                    _propertyDeclaration = selectedElement.Parent as IPropertyDeclaration;
                    if (_propertyDeclaration.IsAuto && _propertyDeclaration.Parent != null
                        && _propertyDeclaration.Parent.Parent is IClassDeclaration)
                    {
                        _classDeclaration = _propertyDeclaration.Parent.Parent as IClassDeclaration;
                    }
                }
            }

            return _classDeclaration != null && _classDeclaration.DeclaredElement != null
                   && (_classDeclaration.DeclaredElement.IsDescendantOf(CatelCore.GetDataObjectBaseTypeElement(Provider.PsiModule, _classDeclaration.GetResolveContext()))
                       || _classDeclaration.DeclaredElement.IsDescendantOf(CatelCore.GetModelBaseTypeElement(Provider.PsiModule, _classDeclaration.GetResolveContext())));
        }
        /// <summary>
        /// Creates a valid value element for a property declaration.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// A valid value string for the property passed in.
        /// </returns>
        public static string CreateValueDocumentationForProperty(IPropertyDeclaration propertyDeclaration)
        {
            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, propertyDeclaration.GetSolution());
            if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                return string.Empty;
            }

            return string.Format("<value>The {0}.</value>", ConvertTextToSentence(propertyDeclaration.DeclaredName).ToLower());
        }
Example #38
0
        private bool CheckPropertyDecl(IPropertyDeclaration o, IPropertyDeclaration n)
        {
            if (o.DeclaringType.ToString() != n.DeclaringType.ToString() ||
                !CheckExp(o.Initializer, n.Initializer) ||
                o.Name != n.Name ||
                o.PropertyType.ToString() != n.PropertyType.ToString() ||
                o.RuntimeSpecialName != n.RuntimeSpecialName)
            {
                return false;
            }

            if (!o.Attributes.Compare(n.Attributes, CheckCustomAttribute) ||
                !o.Parameters.Compare(n.Parameters,CheckParameterDecl))
            {
                return false;
            }

            if (
                !CompareIMethodReference(o.GetMethod, n.GetMethod) ||
                !CompareIMethodReference(o.SetMethod, n.SetMethod))
            {
                return false;
            }

            return true;
        }
Example #39
0
		internal static PropertyDefinition FindMatchingProperty(TypeDefinition typedef, IPropertyDeclaration pdec)
		{
			return typedef.Properties.FirstOrDefault(pdef => PropertyMatches(pdef, pdec));
		}
        private void AdjustPropertyVisibility(PropertyInfo propertyInfo, IPropertyDeclaration propertyDeclaration)
        {
            var firstAccessor = propertyDeclaration.GetMethod == null ? null : propertyDeclaration.GetMethod.Resolve();
            var secondAccessor = propertyDeclaration.SetMethod == null ? null : propertyDeclaration.SetMethod.Resolve();
            if (firstAccessor == null)
            {
                firstAccessor = secondAccessor;
            }
            else if (secondAccessor == null)
            {
                secondAccessor = firstAccessor;
            }

            if (firstAccessor.Visibility == MethodVisibility.Public || secondAccessor.Visibility == MethodVisibility.Public)
            {
                propertyInfo.IsPublic = true;
                return;
            }
            if (firstAccessor.Visibility == MethodVisibility.Family || secondAccessor.Visibility == MethodVisibility.Family)
            {
                propertyInfo.IsProtected = true;
                return;
            }
            if (firstAccessor.Visibility == MethodVisibility.FamilyOrAssembly || secondAccessor.Visibility == MethodVisibility.FamilyOrAssembly)
            {
                propertyInfo.IsProtectedOrInternal = true;
                return;
            }
            if (firstAccessor.Visibility == MethodVisibility.Assembly || secondAccessor.Visibility == MethodVisibility.Assembly)
            {
                propertyInfo.IsInternal = true;
                return;
            }
            if (firstAccessor.Visibility == MethodVisibility.FamilyAndAssembly || secondAccessor.Visibility == MethodVisibility.FamilyAndAssembly)
            {
                propertyInfo.IsProtectedAndInternal = true;
                return;
            }
            propertyInfo.IsPrivate = true;
        }
 public PropertySetterMustBePrivateInTestContextSpecificationHighlighting(IPropertyDeclaration propertyDeclaration)
 {
     this.PropertyDeclaration = propertyDeclaration;
     this.ToolTip = "Properties used in a test context are only allowed to have a private setter.";
     this.ErrorStripeToolTip = "Property setter must be private.";
 }
Example #42
0
 protected override void InitializeForCodeGeneration()
 {
     base.InitializeForCodeGeneration();
     NodeType = NodeType.Property;
     Member = default(IPropertyDeclaration);
 }
        private void SetOrder(IPropertyDeclaration propertyDeclaration, int i)
        {
            CSharpElementFactory factory = CSharpElementFactory.GetInstance(this._actionDataProvider.PsiModule);

            IAttribute attribute = propertyDeclaration.Attributes.SingleOrDefault(IsDataMemberAttribute);

            if (null == attribute)
            {
                return;
            }

            IPropertyAssignment orderProperty =
                attribute.PropertyAssignments.FirstOrDefault(p => p.PropertyNameIdentifier.Name == "Order");

            if (null != orderProperty)
            {
                attribute.RemovePropertyAssignment(orderProperty);
            }

            IPropertyAssignment replacement = factory.CreatePropertyAssignment(
                "Order",
                factory.CreateExpressionByConstantValue(
                    new ConstantValue(i, attribute.GetPsiModule(), attribute.GetResolveContext())));

            attribute.AddPropertyAssignmentAfter(replacement, null);

            //var anchor = attribute.Children().FirstOrDefault(n => n.NodeType == CSharpTokenType.LPARENTH);

            //if (null != anchor)
            //{
            //    var orderPara = attribute.PropertyAssignments.SingleOrDefault(a => a.Reference.GetName() == "Order");

            //    if (null != orderPara)
            //    {
            //        ModificationUtil.DeleteChild(orderPara);
            //    }

            //    var orderNew = factory.CreateExpression(String.Format("Order={0}", i)); //.CreateObjectCreationExpressionMemberInitializer("Order", factory.CreateExpression(""));

            //    ModificationUtil.AddChildAfter(anchor, orderNew);
            //}
        }
Example #44
0
 protected internal PropertyFormula(Formula instance, IPropertyDeclaration property)
     : base(NodeType.Property, property.PropertyType, instance, property)
 {
 }
Example #45
0
 public static PropertyFormula Property(Formula instance, IPropertyDeclaration property)
 {
     return new PropertyFormula(instance, property);
 }
 private bool EnclosingClassImplementsINotifyPropertyChanged(IPropertyDeclaration propertyDeclaration)
 {
     return propertyDeclaration.EnclosingClass
                               .Type()
                               .AllSuperTypesIncludingThis
                               .Any(t => t.Is(NotifyPropertyChangedQualifiedTypeName));
 }
 private bool IsFieldBackedPropertyWithSetterInsideClass(IPropertyDeclaration propertyDeclaration)
 {
     return propertyDeclaration.ExistsTextuallyInFile && propertyDeclaration.HasSetter() &&
            propertyDeclaration.IsFieldBacked() && propertyDeclaration.EnclosingClass.IsClass;
 }
        /// <summary>
        /// Creates a summary for the property.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// A String summary of the property.
        /// </returns>
        public static string CreateSummaryDocumentationForProperty(IPropertyDeclaration propertyDeclaration)
        {
            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, propertyDeclaration.GetSolution());
            if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                return string.Empty;
            }

            IAccessor getter = propertyDeclaration.Getter();
            IAccessor setter = propertyDeclaration.Setter();
            string summaryText = string.Empty;

            string midText = IsPropertyBoolean(propertyDeclaration) ? "a value indicating whether " : string.Empty;

            if (getter != null)
            {
                summaryText = "Gets {0}{1}.";
            }

            if (setter != null)
            {
                AccessRights setterAccessRight = setter.GetAccessRights();

                if ((setterAccessRight == AccessRights.PRIVATE && propertyDeclaration.GetAccessRights() == AccessRights.PRIVATE)
                    || setterAccessRight == AccessRights.PUBLIC || setterAccessRight == AccessRights.PROTECTED || setterAccessRight == AccessRights.PROTECTED_OR_INTERNAL
                    || setterAccessRight == AccessRights.INTERNAL)
                {
                    if (string.IsNullOrEmpty(summaryText))
                    {
                        summaryText = "Sets {0}{1}.";
                    }
                    else
                    {
                        summaryText = "Gets or sets {0}{1}.";
                    }
                }
            }

            return string.Format(summaryText, midText, propertyDeclaration.DeclaredName);
        }
 protected abstract void ConvertProperty(
     PropertyConverter propertyConverter, IPropertyDeclaration propertyDeclaration);
 /// <summary>
 /// Visits the property declaration.
 /// </summary>
 /// <param name="propertyDeclaration">The property declaration.</param>
 /// <param name="consumer">The consumer.</param>
 /// <returns></returns>
 public override object VisitPropertyDeclaration(IPropertyDeclaration propertyDeclaration, IHighlightingConsumer consumer)
 {
     this.VisitTypeMember(propertyDeclaration, consumer);
       return base.VisitPropertyDeclaration(propertyDeclaration, consumer);
 }
        /// <summary>
        /// Inserts a value element to the element if its missing.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The <see cref="IPropertyDeclaration"/> to check and fix.
        /// </param>
        public void InsertValueElement(IPropertyDeclaration propertyDeclaration)
        {
            DeclarationHeader declarationHeader = new DeclarationHeader(propertyDeclaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            XmlNode xmlNode = declarationHeader.XmlNode;

            string valueText = string.Empty;

            XmlNode valueXmlNode = declarationHeader.ValueXmlNode;

            if (StyleCopOptions.Instance.InsertTextIntoDocumentation)
            {
                valueText = string.Format("The {0}.", Utils.ConvertTextToSentence(propertyDeclaration.DeclaredName).ToLower());
            }

            if (declarationHeader.HasValue)
            {
                if (string.IsNullOrEmpty(valueXmlNode.InnerText.Trim()))
                {
                    valueXmlNode.InnerText = valueText;
                    declarationHeader.Update();
                }
                else
                {
                    return;
                }
            }
            else
            {
                XmlNode valueNode = CreateNode(xmlNode, "value");
                valueNode.InnerText = valueText;
                xmlNode.AppendChild(valueNode);
                declarationHeader.Update();
            }
        }
 private bool HasDataMember(IPropertyDeclaration propertyDeclaration)
 {
     return propertyDeclaration.Attributes.Any(IsDataMemberAttribute);
 }
        /// <summary>
        /// Inserts a value element to the element if its missing.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The <see cref="IPropertyDeclaration"/> to check and fix.
        /// </param>
        public void InsertValueElement(IPropertyDeclaration propertyDeclaration)
        {
            DeclarationHeader declarationHeader = new DeclarationHeader(propertyDeclaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            XmlNode xmlNode = declarationHeader.XmlNode;

            string valueText = string.Empty;

            XmlNode valueXmlNode = declarationHeader.ValueXmlNode;

            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, propertyDeclaration.GetSolution());
            if (settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                valueText = string.Format("The {0}.", Utils.ConvertTextToSentence(propertyDeclaration.DeclaredName).ToLower());
            }

            if (declarationHeader.HasValue)
            {
                if (string.IsNullOrEmpty(valueXmlNode.InnerText.Trim()))
                {
                    valueXmlNode.InnerText = valueText;
                    declarationHeader.Update();
                }
            }
            else
            {
                XmlNode valueNode = CreateNode(xmlNode, "value");
                valueNode.InnerText = valueText;
                xmlNode.AppendChild(valueNode);
                declarationHeader.Update();
            }
        }
        /// <summary>
        /// Indicates whether the property is a Boolean type.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property to check.
        /// </param>
        /// <returns>
        /// True if the property is a Boolean.
        /// </returns>
        public static bool IsPropertyBoolean(IPropertyDeclaration propertyDeclaration)
        {
            if (propertyDeclaration.DeclaredElement == null)
            {
                return false;
            }

            DeclaredTypeFromCLRName declaredType = propertyDeclaration.DeclaredElement.Type as DeclaredTypeFromCLRName;

            if (declaredType == null)
            {
                return false;
            }

            return declaredType.GetClrName().FullName == "System.Boolean";
        }
        public PropertyInfo Property(IPropertyDeclaration propertyDeclaration)
        {
            if (_propertyCorrespondence.ContainsKey(propertyDeclaration))
            {
                return _propertyCorrespondence[propertyDeclaration];
            }

            var getMethod = propertyDeclaration.GetMethod == null ? null : propertyDeclaration.GetMethod.Resolve();
            var setMethod = propertyDeclaration.SetMethod == null ? null : propertyDeclaration.SetMethod.Resolve();

            var propertyInfo = new PropertyInfo
            {
                Text = propertyDeclaration.ToString(),
                Name = propertyDeclaration.Name,
                FullName = propertyDeclaration.Name,
                IsVirtual = getMethod != null && getMethod.Virtual
                            || setMethod != null && setMethod.Virtual,
                IsOverride = getMethod != null
                             && getMethod.Virtual
                             && !getMethod.NewSlot
                             || setMethod != null
                             && setMethod.Virtual
                             && !setMethod.NewSlot,
                IsStatic = getMethod != null && getMethod.Static
                           || setMethod != null && setMethod.Static,
                IsFinal = getMethod != null && getMethod.Final
                          || setMethod != null && setMethod.Final,
                MemberReference = propertyDeclaration
            };
            AdjustPropertyVisibility(propertyInfo, propertyDeclaration);

            _propertyCorrespondence.Add(propertyDeclaration, propertyInfo);

            propertyInfo.Icon = Images.Images.GetPropertyIcon(propertyInfo);

            return propertyInfo;
        }
        /// <summary>
        /// Creates a summary for the property.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// A String summary of the property.
        /// </returns>
        public static string CreateSummaryDocumentationForProperty(IPropertyDeclaration propertyDeclaration)
        {
            if (!StyleCopOptions.Instance.InsertTextIntoDocumentation)
            {
                return string.Empty;
            }

            IAccessor getter = propertyDeclaration.Getter();
            IAccessor setter = propertyDeclaration.Setter();
            string summaryText = string.Empty;

            string midText = Utils.IsPropertyBoolean(propertyDeclaration) ? "a value indicating whether " : string.Empty;

            if (getter != null)
            {
                summaryText = "Gets {0}{1}.";
            }

            if (setter != null)
            {
                AccessRights setterAccessRight = setter.GetAccessRights();

                if ((setterAccessRight == AccessRights.PRIVATE && propertyDeclaration.GetAccessRights() == AccessRights.PRIVATE)
                    || setterAccessRight == AccessRights.PUBLIC || setterAccessRight == AccessRights.PROTECTED || setterAccessRight == AccessRights.PROTECTED_OR_INTERNAL
                    || setterAccessRight == AccessRights.INTERNAL)
                {
                    if (string.IsNullOrEmpty(summaryText))
                    {
                        summaryText = "Sets {0}{1}.";
                    }
                    else
                    {
                        summaryText = "Gets or sets {0}{1}.";
                    }
                }
            }

            return string.Format(summaryText, midText, propertyDeclaration.DeclaredName);
        }
Example #57
0
		private static bool PropertyMatches(PropertyDefinition pdef, IPropertyDeclaration pdec)
		{
			// Compatible with alteration feature !!!
			// Called only the first time then in cache, so even if code is altered, this will work
			// No need to check the declaring type, if we are here, they are in sync
			if (pdef == null || pdec == null)
				return false;

			if (!IsSameName(pdef.Name, pdec.Name) || pdef.Parameters.Count != pdec.Parameters.Count ||
			    !TypeMatches(pdef.PropertyType, pdec.PropertyType))
				return false;

			if (pdef.GetMethod != null)
			{
				if (!MethodMatches(pdef.GetMethod, pdec.GetMethod as IMethodDeclaration))
					return false;
			}
			else
			{
				if (pdec.GetMethod != null)
					return false;
			}

			if (pdef.SetMethod != null)
			{
				if (!MethodMatches(pdef.SetMethod, pdec.SetMethod as IMethodDeclaration))
					return false;
			}
			else
			{
				if (pdec.SetMethod != null)
					return false;
			}

			return true;
		}
        /// <summary>
        /// Creates a valid value element for a property declaration.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// A valid value string for the property passed in.
        /// </returns>
        public static string CreateValueDocumentationForProperty(IPropertyDeclaration propertyDeclaration)
        {
            if (!StyleCopOptions.Instance.InsertTextIntoDocumentation)
            {
                return string.Empty;
            }

            return string.Format("<value>The {0}.</value>", Utils.ConvertTextToSentence(propertyDeclaration.DeclaredName).ToLower());
        }
 private static bool IsPropertyDeclarationValid(IPropertyDeclaration propertyDeclaration)
 {
     // TODO: when property is valid?
     return true;
 }
 private static IPropertyDeclaration[] ReorderNodes(IPropertyDeclaration[] properties)
 {
     var orderer = new DialogReorder(properties);
     return DialogResult.OK == orderer.ShowDialog() ? orderer.PropertiesInOrder : null;
 }