public AttributeWrapper(AXmlAttribute attribute)
 {
     this.LocalName = attribute.LocalName;
     this.Namespace = attribute.Namespace;
     this.Prefix    = attribute.Prefix;
     this.Value     = attribute.Value;
     this.Offset    = attribute.StartOffset;
 }
Exemple #2
0
 public override void VisitAttribute(AXmlAttribute attribute)
 {
     if (textSource.GetText(attribute.NameSegment) != attribute.Name)
     {
         throw new InvalidOperationException();
     }
     base.VisitAttribute(attribute);
 }
        public override void VisitAttribute(AXmlAttribute attribute)
        {
            Debug.Assert(document != null);

            if (attribute.ParentElement != null)
            {
                if (attribute.ParentElement.Parent == document && attribute.LocalName == "Class" &&
                    attribute.Namespace == CompletionDataHelper.XamlNamespace)
                {
                    this.generatedClass = AddClass(attribute.Value, attribute.ParentElement);
                }
                else if (generatedClass != null && attribute.LocalName == "Name")
                {
                    string name = attribute.Value;

                    if (!string.IsNullOrEmpty(name))
                    {
                        IReturnType type     = TypeFromXmlNode(CompilationUnit, attribute.ParentElement);
                        DomRegion   position = CreateRegion(attribute.ParentElement.StartOffset, attribute.ParentElement.StartOffset + attribute.ParentElement.Name.Length);

                        ModifierEnum fieldModifier = ModifierEnum.Internal;

                        string modifierValue = (attribute.ParentElement.GetAttributeValue(CompletionDataHelper.XamlNamespace, "FieldModifier") ?? string.Empty).Trim();

                        string publicString = currentAmbience.ConvertAccessibility(ModifierEnum.Public).Trim();

                        if (projectContent.Language.NameComparer.Compare(modifierValue, publicString) == 0)
                        {
                            fieldModifier = ModifierEnum.Public;
                        }

                        generatedClass.Fields.Add(new DefaultField(type, name, fieldModifier, position, generatedClass));
                    }
                }
            }

            base.VisitAttribute(attribute);
        }
        internal ResolveResult ResolveAttribute(AXmlAttribute attribute, int offset = -1, CancellationToken cancellationToken = default(CancellationToken))
        {
            IMember member = null, underlying = null;
            IType   type = null;

            if (attribute.Namespace == XamlConst.XamlNamespace)
            {
                switch (attribute.LocalName)
                {
                case "Name":
                    IUnresolvedTypeDefinition typeDefinition = parseInfo.UnresolvedFile.TypeDefinition;
                    if (typeDefinition != null)
                    {
                        type = typeDefinition.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                        IField field = type.GetFields(f => f.Name == attribute.Value).FirstOrDefault();
                        if (field != null)
                        {
                            return(new MemberResolveResult(null, field));
                        }
                    }
                    break;

                case "Class":
                    type = compilation.FindType(new FullTypeName(attribute.Value));
                    return(new TypeResolveResult(type));
                }
            }
            if (attribute.ParentElement == null)
            {
                return(ErrorResolveResult.UnknownError);
            }

            string propertyName = attribute.LocalName;

            if (propertyName.Contains("."))
            {
                string namespaceName = string.IsNullOrEmpty(attribute.Namespace) ? attribute.ParentElement.LookupNamespace("") : attribute.Namespace;
                string name          = propertyName.Substring(0, propertyName.IndexOf('.'));
                propertyName = propertyName.Substring(propertyName.IndexOf('.') + 1);
                ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
                type   = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                member = FindMember(type, propertyName);
                if (member == null)
                {
                    member = FindAttachedMember(type, propertyName, out underlying);
                }
            }
            else
            {
                ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(attribute.ParentElement.Namespace, attribute.ParentElement.LocalName);
                type   = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                member = FindMember(type, propertyName);
            }
            if (member == null)
            {
                return(new UnknownMemberResolveResult(type, propertyName, EmptyList <IType> .Instance));
            }
            if (offset > -1 && attribute.ValueSegment.Contains(offset, 1))
            {
                return(ResolveAttributeValue(member, attribute, cancellationToken));
            }
            if (underlying != null)
            {
                return(new AttachedMemberResolveResult(new TypeResolveResult(underlying.DeclaringType), underlying, member));
            }
            else
            {
                return(new MemberResolveResult(new TypeResolveResult(member.DeclaringType), member));
            }
        }
Exemple #5
0
 public Attribute(SourceFile file, AXmlAttribute attribute)
 {
     _file      = file;
     _attribute = attribute;
 }
Exemple #6
0
        public void ActiveOnOffset(int textOffset)
        {
            SetCaretOffset(textOffset);
            AXmlObject xmlObj = xDoc.GetChildAtOffset(textOffset);

            backgroundRenderer.HighlightColor = Color.FromArgb(0x40, 0, 0, 0xFF);
            ActiveObject = xmlObj;

            _activeIndex = -1; //초기값..

            if (xmlObj is AXmlText)
            {
                if (xmlObj.Parent != null && xmlObj.Parent is AXmlTag)
                {
                    AXmlTag tag = xmlObj.Parent as AXmlTag;
                    if (tag.OpeningBracket.Equals("<!--"))//comment
                    {
                        ActiveComment = tag;
                        ActiveElement = null;
                        _activeIndex  = GetIndex(tag, true);
                    }
                    else
                    {
                        ActiveComment = null;
                    }
                }
                else
                {
                    ActiveComment = null;
                }
            }
            else if (xmlObj is AXmlTag)
            {
                AXmlTag tag = xmlObj as AXmlTag;
                if (tag.OpeningBracket.Equals("<!--"))//comment
                {
                    ActiveComment = tag;
                    ActiveElement = null;
                    _activeIndex  = GetIndex(tag, true);
                }
                else
                {
                    ActiveComment = null;
                }
            }
            else
            {
                ActiveComment = null;
            }

            if (ActiveComment == null)
            {
                ActiveElement = AXmlFinder.FindOwnerElement(xmlObj, true);
                if (ActiveElement != null)
                {
                    _activeIndex = GetIndex(ActiveElement, true);
                }
            }

            if (xmlObj is AXmlAttribute)
            {
                ActiveAttribute = xmlObj as AXmlAttribute;
            }
            else if ((xmlObj is AXmlElement) == false && (xmlObj is AXmlTag))
            {
                ActiveAttribute = null;
            }
            else
            {
                ActiveAttribute = null;
            }



            if (ActiveComment != null)
            {
                backgroundRenderer.HighlightObjects = new AXmlObject[] { ActiveComment }
            }
        public static XamlContext ResolveContext(FileName fileName, ITextSource fileContent, int offset)
        {
            XamlFullParseInformation info = SD.ParserService.Parse(fileName, fileContent) as XamlFullParseInformation;

            if (info == null)
            {
                throw new Exception("need full parse info!");
            }

            AXmlDocument document    = info.Document;
            AXmlObject   currentData = document.GetChildAtOffset(offset);

            string         attributeName = string.Empty, attributeValue = string.Empty;
            AttributeValue value                = null;
            bool           isRoot               = false;
            bool           wasAXmlElement       = false;
            int            offsetFromValueStart = -1;

            List <AXmlElement> ancestors             = new List <AXmlElement>();
            Dictionary <string, XamlNamespace> xmlns = new Dictionary <string, XamlNamespace>();
            List <string> ignored             = new List <string>();
            string        xamlNamespacePrefix = string.Empty;

            var         item = currentData;
            AXmlElement root = null;

            while (item != document)
            {
                if (item is AXmlElement)
                {
                    AXmlElement element = item as AXmlElement;
                    ancestors.Add(element);
                    foreach (var attr in element.Attributes)
                    {
                        if (attr.IsNamespaceDeclaration)
                        {
                            string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName;
                            if (!xmlns.ContainsKey(prefix))
                            {
                                xmlns.Add(prefix, new XamlNamespace(attr.Value));
                            }
                        }

                        if (attr.LocalName == "Ignorable" && attr.Namespace == XamlConst.MarkupCompatibilityNamespace)
                        {
                            ignored.AddRange(attr.Value.Split(' ', '\t'));
                        }

                        if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlConst.XamlNamespace)
                        {
                            xamlNamespacePrefix = attr.LocalName;
                        }
                    }

                    if (element.Parent is AXmlDocument)
                    {
                        root = element;
                        if (!wasAXmlElement)
                        {
                            isRoot = true;
                        }
                    }

                    wasAXmlElement = true;
                }

                item = item.Parent;
            }

            XamlContextDescription description = XamlContextDescription.None;

            AXmlElement active = null;
            AXmlElement parent = null;

            if (currentData is AXmlAttribute)
            {
                AXmlAttribute a = currentData as AXmlAttribute;
                int           valueStartOffset = a.ValueSegment.Offset + 1;
                attributeName  = a.Name;
                attributeValue = a.Value;
                value          = MarkupExtensionParser.ParseValue(attributeValue);

                if (offset >= valueStartOffset && (offset < a.EndOffset ||              // if length is < 2 one quote is missing
                                                   (a.ValueSegment.Length <= 1 && offset <= a.EndOffset)))
                {
                    offsetFromValueStart = offset - valueStartOffset;

                    description = XamlContextDescription.InAttributeValue;

                    if (value != null && !value.IsString)
                    {
                        description = XamlContextDescription.InMarkupExtension;
                    }
                    if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2)
                    {
                        description = XamlContextDescription.InAttributeValue;
                    }
                }
                else
                {
                    description = XamlContextDescription.InTag;
                }
                active = a.ParentElement;
            }
            else if (currentData is AXmlTag)
            {
                AXmlTag tag = currentData as AXmlTag;
                if (tag.IsStartOrEmptyTag || tag.IsEndTag)
                {
                    if (tag.NameSegment.EndOffset < offset)
                    {
                        description = XamlContextDescription.InTag;
                    }
                    else
                    {
                        description = XamlContextDescription.AtTag;
                    }
                }
                else if (tag.IsComment)
                {
                    description = XamlContextDescription.InComment;
                }
                else if (tag.IsCData)
                {
                    description = XamlContextDescription.InCData;
                }
                active = tag.Parent as AXmlElement;
            }

            if (active != ancestors.FirstOrDefault())
            {
                parent = ancestors.FirstOrDefault();
            }
            else
            {
                parent = ancestors.Skip(1).FirstOrDefault();
            }

            if (active == null)
            {
                active = parent;
            }

            var xAttribute = currentData as AXmlAttribute;

            var context = new XamlContext()
            {
                Description         = description,
                ActiveElement       = active,
                ParentElement       = parent,
                RootElement         = root,
                Ancestors           = ancestors.AsReadOnly(),
                Attribute           = xAttribute,
                InRoot              = isRoot,
                AttributeValue      = value,
                RawAttributeValue   = attributeValue,
                ValueStartOffset    = offsetFromValueStart,
                XmlnsDefinitions    = xmlns,
                ParseInformation    = info,
                IgnoredXmlns        = ignored.AsReadOnly(),
                XamlNamespacePrefix = xamlNamespacePrefix
            };

            return(context);
        }
 /// <summary> Visit AXmlAttribute </summary>
 public virtual void VisitAttribute(AXmlAttribute attribute)
 {
 }
 public static QualifiedNameWithLocation ToQualifiedName(this AXmlAttribute thisValue)
 {
     return(new QualifiedNameWithLocation(thisValue.LocalName, thisValue.Namespace, thisValue.Prefix, thisValue.StartOffset));
 }
 public static AttributeWrapper ToWrapper(this AXmlAttribute attribute)
 {
     return(new AttributeWrapper(attribute));
 }
Exemple #11
0
        /// <summary>
        /// get the first xmlobject from baseNode by xpath. <br/>
        /// if there are multiple objects in baseNode, <br/>
        /// fill list argument. this function will fill this list with all xml objects<br/>
        /// that have the path.<br/>
        /// </summary>
        /// <param name="baseNode">if you don't know root, call GetRoot(AXmlDocument xDoc) static method.</param>
        /// <param name="xPath">seperator is '/'. ex>Command/Data</param>
        /// <param name="list">if null, this function just return the first Node and end. but if not null, all reference will be inserted in this list</param>
        /// <returns>the first XmlNode which has the path of xPath, formatted of AXmlObject</returns>
        public static AXmlObject GetXmlObject(AXmlElement baseNode, String xPath, List <AXmlObject> list = null)
        {
            String     firstNodeName = xPath; // '/'가 없는 문자열일 경우 그 자체가 이름..
            String     lastPath      = "";
            AXmlObject selectedObj   = null;
            AXmlObject firstSelected = null;

            if (baseNode == null)
            {
                return(null);
            }

            if (xPath.Contains('/'))
            {
                firstNodeName = xPath.Substring(0, xPath.IndexOf("/"));
                lastPath      = xPath.Substring(xPath.IndexOf('/') + 1);

                if (firstNodeName.Equals(baseNode.Name))
                {
                    if (lastPath.Contains('/'))
                    {
                        firstNodeName = lastPath.Substring(0, lastPath.IndexOf("/"));
                        lastPath      = lastPath.Substring(lastPath.IndexOf('/') + 1);
                    }
                    else
                    {
                        firstNodeName = lastPath;
                        lastPath      = "";
                    }
                }
            }

            if (lastPath.Length == 0 && baseNode.Name.ToLower().Equals(firstNodeName.ToLower()))
            {
                list.Add(baseNode);
                return(baseNode);
            }
            else
            {
                foreach (AXmlObject obj in baseNode.Children)
                {
                    if (obj is AXmlElement)
                    {
                        AXmlElement element = (obj as AXmlElement);
                        if (element.Name.Equals(firstNodeName))
                        {//첫 노드를 찾았으니 다음으로 넘어가야 한다.
                            if (lastPath.Length == 0)
                            {
                                selectedObj = element;
                            }
                            else
                            {
                                selectedObj = GetXmlObject(element, lastPath, list);
                            }

                            if (selectedObj != null)
                            {
                                if (list == null)
                                {
                                    return(selectedObj);
                                }
                                else
                                {
                                    if (firstSelected == null)
                                    {
                                        firstSelected = selectedObj;
                                    }
                                    list.Add(selectedObj);
                                }
                            }
                        }
                    }
                    else if (obj is AXmlAttribute && firstNodeName[0].Equals('@'))//Attribute일 경우, XPath의 첫글자는 @로 시작해야 한다.
                    {
                        AXmlAttribute attr = (obj as AXmlAttribute);
                        if (attr.Name.Equals(firstNodeName))
                        {//첫 노드를 찾았으니 다음으로 넘어가야 한다.
                            selectedObj = attr;
                            if (selectedObj != null)
                            {
                                if (list == null)
                                {
                                    return(selectedObj);
                                }
                                else
                                {
                                    if (firstSelected == null)
                                    {
                                        firstSelected = selectedObj;
                                    }
                                    list.Add(selectedObj);
                                }
                            }
                        }
                    }
                }
            }
            return(firstSelected);
        }