Ejemplo n.º 1
0
        void AddMemberToTarget(Member member, DataType parentDataType, HashSet <DocumentViewModel> target)
        {
            // If this is some kind of overridden member, try to resolve the original declaration as it's the one that's
            // interesting to us
            member = ResolveOriginalDeclaration(member);

            // NOTE: Instead of just using GetUri and GetId directly on the entity to generate the ID, we use the
            // signature variants of the uri/id methods instead and prefix it with the uri and id of the containing
            // data type.
            //
            // This is done to properly support flattening inherited members into the data exchange format used by the
            // compiler backend; while the ToString() method on a type that inherits from Uno.Object without overriding
            // ToString() directly will have the ToString() method listed when using the EnumerateFlattenedMethods()
            // extension method, that method will still belong to Uno.Object and not the type that inherited the method.
            //
            // The data structure requires the type to own its own inherited methods, hence we do it like this.
            var id  = parentDataType.GetUri() + "/" + member.GetUriSignature();
            var uri = GetMemberUri(member, parentDataType);

            var comment = _commentParser.Read(member);
            var ns      = parentDataType.FindNamespace();
            var titles  = new TitlesViewModel(Naming.GetPageTitle(member),
                                              Naming.GetIndexTitle(member),
                                              Naming.GetFullIndexTitle(member),
                                              Naming.GetNavigationTitle(member),
                                              member.FullName);
            var syntax       = new SyntaxViewModel(Syntax.BuildUnoSyntax(member, parentDataType), Syntax.BuildUxSyntax(member));
            var location     = new LocationViewModel(ns.FullName, ns.GetUri(), member.Source.Package.Name, member.Source.Package.Version);
            var declaredIn   = new DataTypeBuilder(Naming, Syntax, Exportable, AttachedMembers, _commentParser).BuildReference(member.DeclaringType);
            var parameters   = GetParameters(member);
            var returns      = GetReturns(member);
            var uxProperties = GetUxProperties(member);
            var values       = BuildValues(member);
            var flags        = BuildFlags(member);
            var attributes   = BuildAttributes(member);

            var type      = GetTypeName(member, comment, uxProperties);
            var isVirtual = uri == null;

            var viewModel = new MemberViewModel(new DocumentIdViewModel(id, parentDataType.GetUri(), type, member.GetModifierNames()),
                                                new DocumentUriViewModel(id, member.GetUri(), isVirtual),
                                                titles,
                                                syntax,
                                                location,
                                                declaredIn,
                                                parameters,
                                                returns,
                                                uxProperties,
                                                values,
                                                flags,
                                                new CommentViewModel(comment),
                                                attributes,
                                                member);

            target.AddIfNotExists(viewModel);
        }
Ejemplo n.º 2
0
        void AddAttachedMemberToTarget(string name, MemberType memberType, Method underlyingMethod, DataType returnType, DataType parentDataType, HashSet <DocumentViewModel> target)
        {
            var uxAttribute = underlyingMethod.Attributes.SingleOrDefault(e => e.ReturnType.QualifiedName == ExportConstants.UxAttachedPropertySetterAttributeName ||
                                                                          e.ReturnType.QualifiedName == ExportConstants.UxAttachedEventAdderAttributeName);

            if (uxAttribute == null)
            {
                throw new ArgumentException($"UX attached attribute not found on {underlyingMethod.UnoName}");
            }

            var uxAttributeName = uxAttribute.Arguments.Length == 0 ? null : uxAttribute.Arguments[0].ConstantString;

            if (string.IsNullOrWhiteSpace(uxAttributeName))
            {
                throw new ArgumentException($"UX attached attribute did not contain any on {underlyingMethod.UnoName}");
            }
            uxAttributeName = uxAttributeName.ToLowerInvariant()
                              .Replace(".", "_");

            var id     = parentDataType.GetUri() + "/" + uxAttributeName + "_" + underlyingMethod.GetUriSignature();
            var titles = new TitlesViewModel(Naming.GetPageTitle(underlyingMethod),
                                             uxAttribute.Arguments[0].ConstantString,
                                             uxAttribute.Arguments[0].ConstantString,
                                             Naming.GetNavigationTitle(underlyingMethod),
                                             Naming.GetFullIndexTitle(underlyingMethod));
            var declaredIn = new DataTypeBuilder(Naming, Syntax, Exportable, AttachedMembers, _commentParser).BuildReference(underlyingMethod.DeclaringType);
            var parameters = GetParameters(underlyingMethod);
            var returns    = GetReturns(underlyingMethod, returnType);
            var values     = BuildValues(returnType);
            var source     = new AttachedMemberSourceViewModel(underlyingMethod.DeclaringType.GetUri(), Naming.GetIndexTitle(underlyingMethod.DeclaringType));
            var comment    = _commentParser.Read(underlyingMethod);

            if (!Exportable.IsExportableAndVisible(underlyingMethod.DeclaringType))
            {
                throw new Exception($"Found attached UX member {underlyingMethod.FullName} declared inside non-exportable class {underlyingMethod.DeclaringType.FullName}");
            }

            var viewModel = new AttachedMemberViewModel(new DocumentIdViewModel(id, parentDataType.GetUri(), "AttachedUx" + memberType.ToString("G"), new List <string>()),
                                                        new DocumentUriViewModel(id, underlyingMethod.GetUri(), true),
                                                        titles,
                                                        declaredIn,
                                                        parameters,
                                                        returns,
                                                        values,
                                                        source,
                                                        new CommentViewModel(comment),
                                                        underlyingMethod);

            target.AddIfNotExists(viewModel);
        }
Ejemplo n.º 3
0
        AttributesViewModel BuildAttributes(Member member)
        {
            var models = new List <AttributeViewModel>();

            foreach (var attr in member.Attributes ?? new NewObject[0])
            {
                if (!Exportable.IsExportableAndVisible(attr.ReturnType))
                {
                    continue;
                }

                var parameters = attr.Arguments.Select(e => e.ConstantString).ToList();
                var reference  = new DataTypeBuilder(Naming, Syntax, Exportable, AttachedMembers, _commentParser).BuildReference(attr.ReturnType);
                models.Add(new AttributeViewModel(reference.Id, reference.Uri, reference.Titles, parameters));
            }

            return(new AttributesViewModel(models));
        }