Esempio n. 1
0
            protected override void WriteLocationDirective(State state, LayoutWidget widget)
            {
                EnsureArgument(state, nameof(state));
                EnsureArgument(widget, nameof(widget));

                // There might be several locations, we will write only the first one since we can have
                // only one and first is as good as any
                LayoutLocationInfo loc = widget.Locations?.FirstOrDefault();

                if (loc == null)
                {
                    return;
                }

                WriteLineIndent(state, $"#line {loc.Line} \"{loc.FilePath}\"");
                state.WriteLine();
            }
Esempio n. 2
0
        LayoutLocationInfo GetLocationInfo(XPathNavigator nav, string filePath)
        {
            var lineInfo = nav as IXmlLineInfo;
            var ret      = new LayoutLocationInfo {
                FilePath = filePath
            };

            if (lineInfo != null)
            {
                ret.Line   = lineInfo.LineNumber;
                ret.Column = lineInfo.LinePosition;
            }
            else
            {
                ret.Line   = 0;
                ret.Column = 0;
            }

            return(ret);
        }
Esempio n. 3
0
        void CreateWidget(XPathNavigator current, string filePath, string androidNS, string xamarinNS, string id, string parsedId, string name, string partialClasses, ref IDictionary <string, LayoutWidget> widgets)
        {
            bool   isFragment  = String.Compare("fragment", current.LocalName, StringComparison.Ordinal) == 0;
            string managedType = current.GetAttribute(XamarinManagedTypeAttribute, xamarinNS);
            string oldType     = null;

            if (String.IsNullOrEmpty(managedType))
            {
                bool mayNeedTypeFixup = true;
                if (isFragment)
                {
                    managedType = current.GetAttribute("name", androidNS)?.Trim();
                    if (String.IsNullOrEmpty(managedType))
                    {
                        mayNeedTypeFixup = false;
                        managedType      = "global::Android.App.Fragment";
                    }
                }
                else
                {
                    managedType = current.LocalName;
                }

                if (mayNeedTypeFixup)
                {
                    mayNeedTypeFixup = !FixUpTypeName(ref managedType);
                }

                int idx = managedType.IndexOf(',');
                if (idx >= 0)
                {
                    managedType = managedType.Substring(0, idx).Trim();
                }

                if (mayNeedTypeFixup && (idx = managedType.LastIndexOf('.')) >= 0)
                {
                    LogCodedWarning("XA1005", $"Attempting naive type name fixup for element with ID '{id}' and type '{managedType}'");
                    LogCodedWarning("XA1005", "If the above fixup fails, please add `xamarin:managedType` attribute to the element with fully qualified managed type name of the element");

                    oldType = managedType;
                    string ns      = managedType.Substring(0, idx);
                    string klass   = managedType.Substring(idx + 1);
                    string fixedNS = null;
                    if (FixUpNamespace(ns, out fixedNS))
                    {
                        LogMessage($"Fixed up a known namespace from '{ns}' to '{fixedNS}'");
                        managedType = $"{fixedNS}.{klass}";
                    }
                    else
                    {
                        LogMessage("Fixed up namespace by naive capitalization of the name");
                        managedType = $"{CapitalizeName (ns)}.{klass}";
                    }
                    LogMessage($"Element with ID '{id}' managed type fixed up to: '{managedType}'");
                }
            }

            LayoutWidget widget;
            bool         fresh = false;

            if (!widgets.TryGetValue(parsedId, out widget) || widget == null)
            {
                fresh  = true;
                widget = new LayoutWidget {
                    Id             = parsedId,
                    Type           = managedType,
                    Name           = name,
                    PartialClasses = partialClasses,
                    AllTypes       = new List <LayoutWidgetType> (),
                    Locations      = new List <LayoutLocationInfo> (),
                    WidgetType     = isFragment ? LayoutWidgetType.Fragment : LayoutWidgetType.View,
                };
                widgets [widget.Id] = widget;
            }

            LayoutLocationInfo location = GetLocationInfo(current, filePath);

            widget.AllTypes.Add(widget.WidgetType);
            widget.Locations.Add(location);
            if (oldType != null)
            {
                if (widget.TypeFixups == null)
                {
                    widget.TypeFixups = new List <LayoutTypeFixup> ();
                }
                widget.TypeFixups.Add(new LayoutTypeFixup {
                    OldType = oldType, Location = location
                });
            }

            if (fresh)
            {
                return;
            }

            if (widget.Type != null && String.Compare(widget.Type, managedType, StringComparison.Ordinal) == 0)
            {
                return;
            }

            widget.Type       = null;
            widget.WidgetType = LayoutWidgetType.Unknown;
            widget.AllTypes.Add(isFragment ? LayoutWidgetType.Fragment : LayoutWidgetType.View);
        }