public override void VisitDocument(AXmlDocument document) { this.CompilationUnit.ErrorsDuringCompile = document.SyntaxErrors.Any(); this.document = document; base.VisitDocument(document); }
void AddTagComments(AXmlDocument xmlDocument, ParseInformation parseInfo, ITextSource fileContent) { IDocument document = null; foreach (var tag in TreeTraversal.PreOrder <AXmlObject>(xmlDocument, node => node.Children).OfType <AXmlTag>().Where(t => t.IsComment)) { int matchLength; string commentText = fileContent.GetText(tag.StartOffset, tag.Length); int index = commentText.IndexOfAny(TaskListTokens, 0, out matchLength); if (index > -1) { if (document == null) { document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent, parseInfo.FileName); } do { TextLocation startLocation = document.GetLocation(tag.StartOffset + index); int startOffset = index + tag.StartOffset; int endOffset = Math.Min(document.GetLineByOffset(startOffset).EndOffset, tag.EndOffset); string content = document.GetText(startOffset, endOffset - startOffset); parseInfo.TagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(parseInfo.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength))); index = commentText.IndexOfAny(TaskListTokens, endOffset - tag.StartOffset, out matchLength); } while (index > -1); } } }
/// <summary> Visit AXmlDocument </summary> public virtual void VisitDocument(AXmlDocument document) { foreach (AXmlObject child in document.Children) { child.AcceptVisitor(this); } }
Context(SourceFile file, AXmlDocument document, int caret) { _file = file; _document = document; _caret = caret; var root = document.Children.OfType <AXmlElement>().FirstOrDefault(); _root = root == null ? null : new ElementContext(file, root, null); _targetElement = _root == null ? null : FindTargetElement(); InitNamespaces(); }
void UpdateTree(AXmlDocument root) { if (treeView.Root == null) { treeView.Root = new XamlOutlineNode { ElementName = "Document Root", Name = Path.GetFileName(editor.FileName), Editor = editor }; } UpdateNode(treeView.Root as XamlOutlineNode, root); }
public static AXmlElement GetRoot(AXmlDocument xDoc) { AXmlObjectCollection <AXmlObject> elements = xDoc.Children; foreach (AXmlObject obj in elements) { if ((obj as AXmlElement) != null) {//첫번째 만나는 Tag가 Root이다. return(obj as AXmlElement); } } return(null); }
public XamlFullParseInformation(XamlUnresolvedFile unresolvedFile, AXmlDocument document, ITextSource text) : base(unresolvedFile, text.Version, true) { if (unresolvedFile == null) { throw new ArgumentNullException("unresolvedFile"); } if (document == null) { throw new ArgumentNullException("document"); } if (text == null) { throw new ArgumentNullException("text"); } this.document = document; this.text = text; }
public static List <AXmlObject> GetXmlElementPair(AXmlDocument xDoc, AXmlObject xmlObj) { List <AXmlObject> tsList = new List <AXmlObject>(); AXmlElement ele = FindOwnerElement(xmlObj, true); if (ele == null) { return(new List <AXmlObject>()); } if (ele.HasStartOrEmptyTag) { tsList.Add(ele.Children[0]); } if (ele.HasEndTag) { tsList.Add(ele.Children[ele.Children.Count - 1]); } return(tsList); }
/// <summary> /// get xml pair. if it is not pair(attribute or single tag), it returns just the tag or attribute. /// </summary> /// <param name="xDoc">AXmlDocument which is searched</param> /// <param name="xPath">XPath of the tag or attribute. /// if you want search attribute, use '@' character /// before the name of attribute. /// ex> Command/Data or Command/@Name </param> /// <param name="index">0 if you want get the first node. if the nodes are more than 1, use this index.</param> /// <returns>Pair of the tag or just single tag or attribute</returns> public static List <AXmlObject> GetXmlElementPair(AXmlDocument xDoc, String xPath, int index) { AXmlObject xmlObj; if (index == 0) { xmlObj = GetXmlObject(GetRoot(xDoc), xPath); } else { List <AXmlObject> list = new List <AXmlObject>(); GetXmlObject(GetRoot(xDoc), xPath, list); //해당 path의 list를 가져와서 if (index < list.Count) { xmlObj = list[index]; //순서를 가져온다. } else { return(new List <AXmlObject>()); } } return(GetXmlElementPair(xDoc, xmlObj)); }
public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document) { XamlUnresolvedFile file = new XamlUnresolvedFile(fileName); ReadOnlyDocument textDocument = new ReadOnlyDocument(fileContent, fileName); file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset)))); var visitor = new XamlDocumentVisitor(file, textDocument); visitor.VisitDocument(document); if (visitor.TypeDefinition != null) { file.topLevel = new[] { visitor.TypeDefinition } } ; else { file.topLevel = new IUnresolvedTypeDefinition[0]; } return(file); }
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); }
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> /// currentOffset을 기준으로 element의 pair를 가져온다. /// </summary> /// <param name="xDoc"></param> /// <param name="currentOffset"></param> /// <returns></returns> public static List <AXmlObject> GetXmlElementPair(AXmlDocument xDoc, int currentOffset) { AXmlObject xmlObj = xDoc.GetChildAtOffset(currentOffset); return(GetXmlElementPair(xDoc, xmlObj)); }