Esempio n. 1
0
		public override IUnresolvedEntity VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
		{
			DefaultUnresolvedProperty p = new DefaultUnresolvedProperty(currentTypeDefinition, "Item");
			p.EntityType = EntityType.Indexer;
			p.Region = MakeRegion(indexerDeclaration);
			p.BodyRegion = MakeBraceRegion(indexerDeclaration);
			ApplyModifiers(p, indexerDeclaration.Modifiers);
			p.ReturnType = indexerDeclaration.ReturnType.ToTypeReference();
			ConvertAttributes(p.Attributes, indexerDeclaration.Attributes);
			
			ConvertParameters(p.Parameters, indexerDeclaration.Parameters);
			p.Getter = ConvertAccessor(indexerDeclaration.Getter, p, "get_");
			p.Setter = ConvertAccessor(indexerDeclaration.Setter, p, "set_");
			
			if (!indexerDeclaration.PrivateImplementationType.IsNull) {
				p.Accessibility = Accessibility.None;
				p.IsExplicitInterfaceImplementation = true;
				p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
					p.EntityType, indexerDeclaration.PrivateImplementationType.ToTypeReference(), p.Name, 0, GetParameterTypes(p.Parameters)));
			}
			
			currentTypeDefinition.Members.Add(p);
			if (interningProvider != null) {
				p.ApplyInterningProvider(interningProvider);
			}
			return p;
		}
Esempio n. 2
0
        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));
            }
                    )
                );
        }
Esempio n. 3
0
        ParsedDocument ITypeSystemParser.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);
        }
Esempio n. 4
0
        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));
        }