示例#1
0
		public override ParsedDocument Parse (bool storeAst, string fileName, TextReader textReader, Project project = null)
		{
			var doc = new DefaultParsedDocument (fileName);
			
			DefaultUnresolvedTypeDefinition currentFile = null;
			DefaultUnresolvedProperty currentRegion = null;
			
			string eol = Environment.NewLine;
			string content = textReader.ReadToEnd ();
			Match eolMatch = eolExpression.Match (content);
			if (eolMatch != null && eolMatch.Success)
				eol = eolMatch.Groups ["eol"].Value;
			
			string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None);
			int linenum = 1;
			Match lineMatch;
			foreach (string line in lines) {
				lineMatch = fileHeaderExpression.Match (line.Trim ());
				if (lineMatch != null && lineMatch.Success) {
					if (currentFile != null) // Close out previous file region
						currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
						                                        currentFile.BodyRegion.BeginColumn,
						                                        linenum - 1, int.MaxValue);
					if (currentRegion != null) // Close out previous chunk region
						currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
						                                          currentRegion.BodyRegion.BeginColumn,
						                                          linenum - 1, int.MaxValue);
					
					// Create new file region
					currentFile = new DefaultUnresolvedTypeDefinition (string.Empty, string.Empty);
					currentFile.Region = currentFile.BodyRegion = new DomRegion (lastToken (lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
					doc.TopLevelTypeDefinitions.Add (currentFile);
				} else {
					lineMatch = chunkExpression.Match (line);
					if (lineMatch != null && lineMatch.Success && currentFile != null) {
						if (currentRegion != null) // Close out previous chunk region
							currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
							                                          currentRegion.BodyRegion.BeginColumn,
							                                          linenum - 1, int.MaxValue);
						
						// Create new chunk region
						currentRegion = new DefaultUnresolvedProperty (currentFile, lineMatch.Groups ["chunk"].Value);
						currentRegion.Region = currentRegion.BodyRegion = new DomRegion (currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
						currentFile.Members.Add (currentRegion);
					}
				}
				++linenum;
			}
			
			// Close out trailing regions
			if (currentFile != null)
				currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
				                                        currentFile.BodyRegion.BeginColumn, 
				                                        Math.Max (1, linenum - 2), int.MaxValue);
			if (currentRegion != null)
				currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
				                                          currentRegion.BodyRegion.BeginColumn, 
				                                          Math.Max (1, linenum - 2), int.MaxValue);
			
			return doc;
		}
示例#2
0
        public IUnresolvedProperty ReadProperty(PropertyInfo property, IUnresolvedTypeDefinition parentType, EntityType propertyType = EntityType.Property)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            if (parentType == null)
                throw new ArgumentNullException("parentType");

            var p = new DefaultUnresolvedProperty(parentType, property.Name);
            p.EntityType = propertyType;
            TranslateModifiers(property.GetMethod ?? property.SetMethod, p);
            if (property.GetMethod != null && property.SetMethod != null)
                p.Accessibility = MergePropertyAccessibility (GetAccessibility (property.GetMethod.Attributes), GetAccessibility (property.SetMethod.Attributes));
            p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property.CustomAttributes);

            p.Getter = ReadMethod(property.GetMethod, parentType, EntityType.Accessor, p);
            p.Setter = ReadMethod(property.SetMethod, parentType, EntityType.Accessor, p);

            foreach (var par in property.GetIndexParameters ()) {
                p.Parameters.Add(ReadParameter(par));
            }

            AddAttributes(property, p);

            var accessor = p.Getter ?? p.Setter;
            if (accessor != null && accessor.IsExplicitInterfaceImplementation) {
                p.Name = property.Name.Substring(property.Name.LastIndexOf('.') + 1);
                p.IsExplicitInterfaceImplementation = true;
                foreach (var mr in accessor.ExplicitInterfaceImplementations) {
                    p.ExplicitInterfaceImplementations.Add(new AccessorOwnerMemberReference(mr));
                }
            }

            FinishReadMember(p, property);
            return p;
        }
		public static void AddAttachedProperties(ITypeDefinition td, List<ICompletionItem> result)
		{
			var attachedProperties = td.Fields.Where(f => f.IsAttached(true, false));
			var unresolvedType = td.Parts.First();
			var resolveContext = new SimpleTypeResolveContext(td);
			
			result.AddRange(
				attachedProperties.Select(
					property => {
						string propertyName = property.Name.Remove(property.Name.Length - "Property".Length);
						IUnresolvedProperty item = new DefaultUnresolvedProperty(unresolvedType, propertyName);
						IMember entity = item.CreateResolved(resolveContext);
						return new XamlCompletionItem(propertyName, entity);
					}
				)
			);
		}
		public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken)
		{
			ParsedDocument doc = new DefaultParsedDocument (parseOptions.FileName);
			
			DefaultUnresolvedTypeDefinition currentFile = null;
			DefaultUnresolvedProperty currentRegion = null;
			
			string eol = Environment.NewLine;
			string content = parseOptions.Content.Text;
			Match eolMatch = eolExpression.Match (content);
			if (eolMatch != null && eolMatch.Success)
				eol = eolMatch.Groups ["eol"].Value;
			
			string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None);
			int linenum = 1;
			Match lineMatch;
			foreach (string line in lines) {
				lineMatch = fileHeaderExpression.Match (line.Trim ());
				if (lineMatch != null && lineMatch.Success) {
					if (currentFile != null) // Close out previous file region
						currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
						                                        currentFile.BodyRegion.BeginColumn,
						                                        linenum - 1, int.MaxValue);
					if (currentRegion != null) // Close out previous chunk region
						currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
						                                          currentRegion.BodyRegion.BeginColumn,
						                                          linenum - 1, int.MaxValue);
					
					// Create new file region
					currentFile = new DefaultUnresolvedTypeDefinition (string.Empty, string.Empty);
					currentFile.Region = currentFile.BodyRegion = new DomRegion (lastToken (lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
					// doc.TopLevelTypeDefinitions.Add (currentFile);
				} else {
					lineMatch = chunkExpression.Match (line);
					if (lineMatch != null && lineMatch.Success && currentFile != null) {
						if (currentRegion != null) // Close out previous chunk region
							currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
							                                          currentRegion.BodyRegion.BeginColumn,
							                                          linenum - 1, int.MaxValue);
						
						// Create new chunk region
						currentRegion = new DefaultUnresolvedProperty (currentFile, lineMatch.Groups ["chunk"].Value);
						currentRegion.Region = currentRegion.BodyRegion = new DomRegion (currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
						currentFile.Members.Add (currentRegion);
					}
				}
				++linenum;
			}
			
			// Close out trailing regions
			if (currentFile != null)
				currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
				                                        currentFile.BodyRegion.BeginColumn, 
				                                        Math.Max (1, linenum - 2), int.MaxValue);
			if (currentRegion != null)
				currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
				                                          currentRegion.BodyRegion.BeginColumn, 
				                                          Math.Max (1, linenum - 2), int.MaxValue);
			
			return System.Threading.Tasks.Task.FromResult (doc);
		}