XamlOutlineNode BuildNode(AXmlElement item)
        {
            XamlOutlineNode node = new XamlOutlineNode {
                Name        = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"),
                ElementName = item.Name,
                Marker      = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)),
                EndMarker   = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)),
                Editor      = editor
            };

            foreach (var child in item.Children.OfType <AXmlElement>())
            {
                node.Children.Add(BuildNode(child));
            }

            return(node);
        }
Пример #2
0
            public override void VisitElement(AXmlElement element)
            {
                string name = element.GetAttributeValue(XamlConst.XamlNamespace, "Name") ??
                              element.GetAttributeValue("Name");
                string modifier = element.GetAttributeValue(XamlConst.XamlNamespace, "FieldModifier");

                if (name != null && TypeDefinition != null)
                {
                    var field = new DefaultUnresolvedField(TypeDefinition, name);
                    field.Accessibility = Accessibility.Internal;
                    field.ReturnType    = CreateTypeReference(element.Namespace, element.LocalName);
                    field.Region        = new DomRegion(file.FileName, textDocument.GetLocation(element.StartOffset), textDocument.GetLocation(element.EndOffset));
                    if (modifier != null)
                    {
                        field.Accessibility = ParseAccessibility(modifier);
                    }
                    TypeDefinition.Members.Add(field);
                }

                base.VisitElement(element);
            }
        public override void VisitElement(AXmlElement element)
        {
            AXmlTag tag = element.Children.FirstOrDefault() as AXmlTag;

            if (tag != null && tag.IsStartOrEmptyTag)
            {
                NodeWrapper node = new NodeWrapper()
                {
                    ElementName = element.LocalName,
                    StartOffset = element.StartOffset,
                    EndOffset   = element.EndOffset,
                    Name        = element.GetAttributeValue("Name") ?? element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "Name"),
                    Children    = new List <NodeWrapper>()
                };

                if (CompilationUnit.TreeRootNode == null)
                {
                    CompilationUnit.TreeRootNode = node;
                    nodeStack.Push(CompilationUnit.TreeRootNode);
                }
                else
                {
                    if (nodeStack.Count > 0)
                    {
                        nodeStack.Peek().Children.Add(node);
                    }
                    if (!tag.IsEmptyTag)
                    {
                        nodeStack.Push(node);
                    }
                }
            }

            base.VisitElement(element);

            if (tag != null && tag.IsStartTag)
            {
                nodeStack.PopOrDefault();
            }
        }
        IClass AddClass(string className, AXmlElement element)
        {
            if (projectContent.Language == LanguageProperties.VBNet && projectContent.Project is IProject)
            {
                className = ((IProject)projectContent.Project).RootNamespace + "." + className;
            }

            DefaultClass c             = new DefaultClass(CompilationUnit, className);
            string       modifierValue = (element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "ClassModifier") ?? string.Empty).Trim();

            c.Modifiers = ModifierEnum.Partial;

            string internalString = currentAmbience.ConvertAccessibility(ModifierEnum.Internal).Trim();

            if (projectContent.Language.NameComparer.Compare(modifierValue, internalString) == 0)
            {
                c.Modifiers |= ModifierEnum.Internal;
            }
            else
            {
                c.Modifiers |= ModifierEnum.Public;
            }

            c.Region = CreateRegion(element.StartOffset, element.EndOffset);
            var baseType = TypeFromXmlNode(CompilationUnit, element);

            if (baseType != null)
            {
                c.BaseTypes.Add(baseType);
            }
            CompilationUnit.Classes.Add(c);

            DefaultMethod initializeComponent = new DefaultMethod(
                "InitializeComponent",
                projectContent.SystemTypes.Void,
                ModifierEnum.Public | ModifierEnum.Synthetic, c.Region, DomRegion.Empty,
                c);

            c.Methods.Add(initializeComponent);

            return(c);
        }
Пример #5
0
            public override void VisitDocument(AXmlDocument document)
            {
                currentDocument = document;
                AXmlElement rootElement = currentDocument.Children.OfType <AXmlElement>().FirstOrDefault();

                if (rootElement != null)
                {
                    string className = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "Class");
                    string modifier  = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "ClassModifier");
                    if (className != null)
                    {
                        TypeDefinition = new DefaultUnresolvedTypeDefinition(className)
                        {
                            Kind           = TypeKind.Class,
                            UnresolvedFile = file,
                            Accessibility  = Accessibility.Public,
                            Region         = new DomRegion(file.FileName, textDocument.GetLocation(rootElement.StartOffset), textDocument.GetLocation(rootElement.EndOffset))
                        };
                        TypeDefinition.Members.Add(
                            new DefaultUnresolvedMethod(TypeDefinition, "InitializeComponent")
                        {
                            Accessibility = Accessibility.Public,
                            ReturnType    = KnownTypeReference.Void
                        });
                        TypeDefinition.Members.Add(
                            new DefaultUnresolvedField(TypeDefinition, "_contentLoaded")
                        {
                            Accessibility = Accessibility.Private,
                            ReturnType    = KnownTypeReference.Boolean
                        });

                        var connectMember =
                            new DefaultUnresolvedMethod(TypeDefinition, "Connect")
                        {
                            Accessibility = Accessibility.Private,
                            ReturnType    = KnownTypeReference.Void
                        };
                        connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Int32, "connectionId"));
                        connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Object, "target"));
                        TypeDefinition.Members.Add(connectMember);
                        connectMember.ExplicitInterfaceImplementations.Add(
                            new DefaultMemberReference(SymbolKind.Method, new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName)), "Connect"));

                        var browsableAttribute = new DefaultUnresolvedAttribute(new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName)));

                        browsableAttribute.PositionalArguments.Add(
                            new SimpleConstantValue(
                                new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName)), System.ComponentModel.EditorBrowsableState.Never
                                ));

                        connectMember.Attributes.Add(browsableAttribute);
                        TypeDefinition.BaseTypes.Add(CreateTypeReference(rootElement.Namespace, rootElement.LocalName));
                        TypeDefinition.BaseTypes.Add(new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName)));
                        if (modifier != null)
                        {
                            TypeDefinition.Accessibility = ParseAccessibility(modifier);
                        }
                    }
                }
                base.VisitDocument(document);
            }