Ejemplo n.º 1
0
        public static ParseInformation ParseFile(IProjectContent fileProjectContent, string fileName, string fileContent, bool updateCommentTags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            IParser parser = GetParser(fileName);

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

            ICompilationUnit parserOutput = null;

            try {
                if (fileProjectContent == null)
                {
                    // GetProjectContent is expensive because it compares all file names, so
                    // we accept the project content as optional parameter.
                    fileProjectContent = GetProjectContent(fileName);
                    if (fileProjectContent == null)
                    {
                        fileProjectContent = DefaultProjectContent;
                    }
                }

                if (fileContent == null)
                {
                    if (!File.Exists(fileName))
                    {
                        return(null);
                    }
                    fileContent = GetParseableFileContent(fileName);
                }
                parserOutput = parser.Parse(fileProjectContent, fileName, fileContent);

                if (parsings.ContainsKey(fileName))
                {
                    ParseInformation parseInformation = parsings[fileName];
                    fileProjectContent.UpdateCompilationUnit(parseInformation.MostRecentCompilationUnit, parserOutput, fileName);
                }
                else
                {
                    fileProjectContent.UpdateCompilationUnit(null, parserOutput, fileName);
                }
                if (updateCommentTags)
                {
                    TaskService.UpdateCommentTags(fileName, parserOutput.TagComments);
                }
                return(UpdateParseInformation(parserOutput, fileName, updateCommentTags));
            } catch (Exception e) {
                MessageService.ShowError(e);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds Visual Basic's "My" namespace for the specified project.
        /// </summary>
        public static void BuildNamespace(VBNetProject project, IProjectContent pc)
        {
            ICompilationUnit cu = new DefaultCompilationUnit(pc);
            //cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854
            string ns;

            if (project.RootNamespace == null || project.RootNamespace.Length == 0)
            {
                ns = "My";
            }
            else
            {
                ns = project.RootNamespace + ".My";
            }
            IClass myApp  = CreateMyApplication(cu, project, ns);
            IClass myComp = CreateMyComputer(cu, project, ns);

            cu.Classes.Add(myApp);
            cu.Classes.Add(myComp);

            IClass myForms = null;

            if (project.OutputType == OutputType.WinExe)
            {
                myForms = CreateMyForms(cu, project, ns);
                cu.Classes.Add(myForms);
            }
            DefaultClass c = new DefaultClass(cu, ns + ".MyProject");

            c.ClassType = ClassType.Module;
            c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic;
            c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));

            // we need to use GetClassReturnType instead of DefaultReturnType because we need
            // a reference to the compound class.
            c.Properties.Add(new DefaultProperty("Application",
                                                 new GetClassReturnType(pc, myApp.FullyQualifiedName, 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            c.Properties.Add(new DefaultProperty("Computer",
                                                 new GetClassReturnType(pc, myComp.FullyQualifiedName, 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            if (myForms != null)
            {
                c.Properties.Add(new DefaultProperty("Forms",
                                                     new GetClassReturnType(pc, myForms.FullyQualifiedName, 0),
                                                     ModifierEnum.Public | ModifierEnum.Static,
                                                     DomRegion.Empty, DomRegion.Empty, c));
            }
            c.Properties.Add(new DefaultProperty("User",
                                                 new GetClassReturnType(pc, "Microsoft.VisualBasic.ApplicationServices.User", 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            cu.Classes.Add(c);
            pc.UpdateCompilationUnit(null, cu, cu.FileName);
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Builds Visual Basic's "My" namespace for the specified project.
		/// </summary>
		public static void BuildNamespace(VBNetProject project, IProjectContent pc)
		{
			if ("custom".Equals(project.GetEvaluatedProperty("MyType"), StringComparison.OrdinalIgnoreCase))
				return;
			
			ICompilationUnit cu = new DefaultCompilationUnit(pc);
			//cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854
			string ns;
			if (project.RootNamespace == null || project.RootNamespace.Length == 0)
				ns = "My";
			else
				ns = project.RootNamespace + ".My";
			IClass myApp = CreateMyApplication(cu, project, ns);
			IClass myComp = CreateMyComputer(cu, ns);
			
			cu.Classes.Add(myApp);
			cu.Classes.Add(myComp);
			
			IClass myForms = null;
			if (project.OutputType == OutputType.WinExe) {
				myForms = CreateMyForms(cu, ns);
				cu.Classes.Add(myForms);
			}
			DefaultClass c = new DefaultClass(cu, ns + ".MyProject");
			c.ClassType = ClassType.Module;
			c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic;
			c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));
			
			// we need to use GetClassReturnType instead of DefaultReturnType because we need
			// a reference to the compound class.
			c.Properties.Add(new DefaultProperty("Application",
			                                     new GetClassReturnType(pc, myApp.FullyQualifiedName, 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			c.Properties.Add(new DefaultProperty("Computer",
			                                     new GetClassReturnType(pc, myComp.FullyQualifiedName, 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			if (myForms != null) {
				c.Properties.Add(new DefaultProperty("Forms",
				                                     new GetClassReturnType(pc, myForms.FullyQualifiedName, 0),
				                                     ModifierEnum.Public | ModifierEnum.Static,
				                                     DomRegion.Empty, DomRegion.Empty, c));
			}
			c.Properties.Add(new DefaultProperty("User",
			                                     new GetClassReturnType(pc, "Microsoft.VisualBasic.ApplicationServices.User", 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			cu.Classes.Add(c);
			pc.UpdateCompilationUnit(null, cu, cu.FileName);
		}
Ejemplo n.º 4
0
        public static ParseInformation ParseProjectContents(string fileName, string Content, bool IsOpened)
        {
            if (projContentInfo.ContainsKey(fileName) == false)
            {
                projContentInfo[fileName] = new ProjectContentItem(fileName, Content, IsOpened);
            }

            projContentInfo[fileName].Contents = Content;

            IParser parser = GetParser(fileName);

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

            ICompilationUnit parserOutput = null;

            parserOutput    = parser.Parse(projectContent, fileName, Content);
            lastParserError = parser.LastErrors;

            if (projContentInfo.ContainsKey(fileName))
            {
                ParseInformation parseInformation = projContentInfo[fileName].ParsedContents;
                if (parseInformation == null)
                {
                    parseInformation = new ParseInformation();
                    projContentInfo[fileName].ParsedContents = parseInformation;
                }
                projectContent.UpdateCompilationUnit(parseInformation.MostRecentCompilationUnit, parserOutput, fileName);
            }
            else
            {
                projectContent.UpdateCompilationUnit(null, parserOutput, fileName);
            }

            return(UpdateParseInformation(parserOutput, fileName));
        }
Ejemplo n.º 5
0
        public static ParseInformation ParseFile(IProjectContent fileProjectContent, string fileName, string fileContent, bool updateCommentTags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            IParser parser = GetParser(fileName);

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

            ICompilationUnit parserOutput = null;

            try {
                if (fileProjectContent == null)
                {
                    // GetProjectContent is expensive because it compares all file names, so
                    // we accept the project content as optional parameter.
                    fileProjectContent = GetProjectContent(fileName);
                    if (fileProjectContent == null)
                    {
                        fileProjectContent = DefaultProjectContent;
                    }
                }

                if (fileContent == null)
                {
                    if (!File.Exists(fileName))
                    {
                        return(null);
                    }
                    fileContent = GetParseableFileContent(fileName);
                }
                parserOutput = parser.Parse(fileProjectContent, fileName, fileContent);
                parserOutput.Freeze();

                ParseInformation parseInformation;
                lock (parsings) {
                    if (!parsings.TryGetValue(fileName, out parseInformation))
                    {
                        parsings[fileName] = parseInformation = new ParseInformation();
                    }
                }
                ICompilationUnit oldUnit = parseInformation.MostRecentCompilationUnit;
                fileProjectContent.UpdateCompilationUnit(oldUnit, parserOutput, fileName);
                parseInformation.SetCompilationUnit(parserOutput);
                if (updateCommentTags)
                {
                    TaskService.UpdateCommentTags(fileName, parserOutput.TagComments);
                }
                try {
                    OnParseInformationUpdated(new ParseInformationEventArgs(fileName, fileProjectContent, oldUnit, parserOutput));
                } catch (Exception e) {
                    MessageService.ShowError(e);
                }
                return(parseInformation);
            } catch (Exception e) {
                MessageService.ShowError(e, "Error parsing " + fileName);
            }
            return(null);
        }
Ejemplo n.º 6
0
		public static ParseInformation ParseFile(IProjectContent fileProjectContent, string fileName, string fileContent, bool updateCommentTags)
		{
			if (fileName == null) throw new ArgumentNullException("fileName");
			
			IParser parser = GetParser(fileName);
			if (parser == null) {
				return null;
			}
			
			ICompilationUnit parserOutput = null;
			
			try {
				if (fileProjectContent == null) {
					// GetProjectContent is expensive because it compares all file names, so
					// we accept the project content as optional parameter.
					fileProjectContent = GetProjectContent(fileName);
					if (fileProjectContent == null) {
						fileProjectContent = DefaultProjectContent;
					}
				}
				
				if (fileContent == null) {
					if (!File.Exists(fileName)) {
						return null;
					}
					fileContent = GetParseableFileContent(fileName);
				}
				parserOutput = parser.Parse(fileProjectContent, fileName, fileContent);
				
				if (parsings.ContainsKey(fileName)) {
					ParseInformation parseInformation = parsings[fileName];
					fileProjectContent.UpdateCompilationUnit(parseInformation.MostRecentCompilationUnit, parserOutput, fileName);
				} else {
					fileProjectContent.UpdateCompilationUnit(null, parserOutput, fileName);
				}
				if (updateCommentTags) {
					TaskService.UpdateCommentTags(fileName, parserOutput.TagComments);
				}
				return UpdateParseInformation(parserOutput, fileName, updateCommentTags);
			} catch (Exception e) {
				MessageService.ShowError(e);
			}
			return null;
		}
Ejemplo n.º 7
0
		public static ParseInformation ParseFile(IProjectContent fileProjectContent, string fileName, string fileContent, bool updateCommentTags)
		{
			if (fileName == null) throw new ArgumentNullException("fileName");
			
			IParser parser = GetParser(fileName);
			if (parser == null) {
				return null;
			}
			
			ICompilationUnit parserOutput = null;
			
			try {
				if (fileProjectContent == null) {
					// GetProjectContent is expensive because it compares all file names, so
					// we accept the project content as optional parameter.
					fileProjectContent = GetProjectContent(fileName);
					if (fileProjectContent == null) {
						fileProjectContent = DefaultProjectContent;
					}
				}
				
				if (fileContent == null) {
					if (!File.Exists(fileName)) {
						return null;
					}
					fileContent = GetParseableFileContent(fileName);
				}
				parserOutput = parser.Parse(fileProjectContent, fileName, fileContent);
				parserOutput.Freeze();
				
				ParseInformation parseInformation;
				lock (parsings) {
					if (!parsings.TryGetValue(fileName, out parseInformation)) {
						parsings[fileName] = parseInformation = new ParseInformation();
					}
				}
				ICompilationUnit oldUnit = parseInformation.MostRecentCompilationUnit;
				fileProjectContent.UpdateCompilationUnit(oldUnit, parserOutput, fileName);
				parseInformation.SetCompilationUnit(parserOutput);
				if (updateCommentTags) {
					TaskService.UpdateCommentTags(fileName, parserOutput.TagComments);
				}
				try {
					OnParseInformationUpdated(new ParseInformationEventArgs(fileName, fileProjectContent, oldUnit, parserOutput));
				} catch (Exception e) {
					MessageService.ShowError(e);
				}
				return parseInformation;
			} catch (Exception e) {
				MessageService.ShowError(e, "Error parsing " + fileName);
			}
			return null;
		}
Ejemplo n.º 8
0
            public ParseInformation ParseFile(IProjectContent parentProjectContent, ITextBuffer fileContent)
            {
                if (parser == null)
                {
                    return(null);
                }

                if (fileContent == null)
                {
                    // GetParseableFileContent must not be called inside any lock
                    // (otherwise we'd risk deadlocks because GetParseableFileContent must invoke on the main thread)
                    try
                    {
                        fileContent = GetParseableFileContent(fileName);
                    }
                    catch (System.Reflection.TargetInvocationException ex)
                    {
                        // It is possible that the file gets deleted/becomes inaccessible while a background parse
                        // operation is enqueued, so we have to handle IO exceptions.
                        if (ex.InnerException is IOException || ex.InnerException is UnauthorizedAccessException)
                        {
                            return(null);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (IOException)
                    {
                        return(null);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        return(null);
                    }
                }

                ITextBufferVersion     fileContentVersion = fileContent.Version;
                List <IProjectContent> projectContents;

                lock (this)
                {
                    if (this.disposed)
                    {
                        return(null);
                    }

                    if (fileContentVersion != null && this.bufferVersion != null && this.bufferVersion.BelongsToSameDocumentAs(fileContentVersion))
                    {
                        if (this.bufferVersion.CompareAge(fileContentVersion) >= 0)
                        {
                            // Special case: (necessary due to parentProjectContent optimization)
                            // Detect when a file belongs to multiple projects but the ParserService hasn't realized
                            // that, yet. In this case, do another parse run to detect all parent projects.
                            if (!(parentProjectContent != null && this.oldUnits.Length == 1 && this.oldUnits[0].ProjectContent != parentProjectContent))
                            {
                                return(this.parseInfo);
                            }
                        }
                    }

                    if (parentProjectContent != null && (oldUnits.Length == 0 || (oldUnits.Length == 1 && oldUnits[0].ProjectContent == parentProjectContent)))
                    {
                        // Optimization: if parentProjectContent is specified and doesn't conflict with what we already know,
                        // we will use it instead of doing an expensive GetProjectContents call.
                        projectContents = new List <IProjectContent>();
                        projectContents.Add(parentProjectContent);
                    }
                    else
                    {
                        projectContents = GetProjectContents(fileName);
                    }
                }
                // We now leave the lock to do the actual parsing.
                // This is done to allow IParser implementations to invoke methods on the main thread without
                // risking deadlocks.

                // parse once for each project content that contains the file
                ICompilationUnit[] newUnits   = new ICompilationUnit[projectContents.Count];
                ICompilationUnit   resultUnit = null;

                for (int i = 0; i < newUnits.Length; i++)
                {
                    IProjectContent pc = projectContents[i];
                    try
                    {
                        newUnits[i] = parser.Parse(pc, fileName, fileContent);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error parsing " + fileName, ex);
                    }
                    if (i == 0 || pc == parentProjectContent)
                    {
                        resultUnit = newUnits[i];
                    }
                }
                lock (this)
                {
                    if (this.disposed)
                    {
                        return(null);
                    }

                    // ensure we never go backwards in time (we need to repeat this check after we've reacquired the lock)
                    if (fileContentVersion != null && this.bufferVersion != null && this.bufferVersion.BelongsToSameDocumentAs(fileContentVersion))
                    {
                        if (this.bufferVersion.CompareAge(fileContentVersion) >= 0)
                        {
                            if (parentProjectContent != null && parentProjectContent != parseInfo.CompilationUnit.ProjectContent)
                            {
                                ICompilationUnit oldUnit = oldUnits.FirstOrDefault(o => o.ProjectContent == parentProjectContent);
                                if (oldUnit != null)
                                {
                                    return(new ParseInformation(oldUnit));
                                }
                            }
                            return(this.parseInfo);
                        }
                    }

                    ParseInformation newParseInfo = new ParseInformation(resultUnit);

                    for (int i = 0; i < newUnits.Length; i++)
                    {
                        IProjectContent pc = projectContents[i];
                        // update the compilation unit
                        ICompilationUnit oldUnit = oldUnits.FirstOrDefault(o => o.ProjectContent == pc);
                        pc.UpdateCompilationUnit(oldUnit, newUnits[i], fileName);
                        ParseInformation newUnitParseInfo = (newUnits[i] == resultUnit) ? newParseInfo : new ParseInformation(newUnits[i]);
                        RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, pc, oldUnit, newUnitParseInfo, newUnits[i] == resultUnit));
                    }

                    // remove all old units that don't exist anymore
                    foreach (ICompilationUnit oldUnit in oldUnits)
                    {
                        if (!newUnits.Any(n => n.ProjectContent == oldUnit.ProjectContent))
                        {
                            oldUnit.ProjectContent.RemoveCompilationUnit(oldUnit);
                            RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null, false));
                        }
                    }

                    this.bufferVersion = fileContentVersion;
                    this.oldUnits      = newUnits;
                    this.parseInfo     = newParseInfo;
                    return(newParseInfo);
                }
            }
Ejemplo n.º 9
0
        public static ParseInformation ParseProjectContents(string fileName, string Content, bool IsOpened)
        {
            //try
            //   {

            lock (s_obs)
            {
                if (s_projContentInfo == null)
                {
                    s_projContentInfo = new Dictionary <string, ProjectContentItem>();
                }

                if (s_projContentInfo.ContainsKey(fileName) == false)
                {
                    s_projContentInfo[fileName] = new ProjectContentItem(fileName, Content, IsOpened);
                }

                s_projContentInfo[fileName].Contents = Content;

                IParser parser = GetParser(fileName);
                if (parser == null)
                {
                    MessageBox.Show("Parser errors..");
                    return(null);
                }

                ICompilationUnit parserOutput = null;
                parserOutput = parser.Parse(s_projectContent, fileName, Content);

                if (parserOutput == null)
                {
                    MessageBox.Show("Parser errors..");
                    return(null);
                }

                s_lastParserError = parser.LastErrors;

                if (s_projContentInfo.ContainsKey(fileName))
                {
                    ParseInformation parseInformation = s_projContentInfo[fileName].ParsedContents;
                    if (parseInformation == null)
                    {
                        parseInformation = new ParseInformation();
                        s_projContentInfo[fileName].ParsedContents = parseInformation;
                    }
                    s_projectContent.UpdateCompilationUnit(parseInformation.MostRecentCompilationUnit, parserOutput, fileName);
                }
                else
                {
                    s_projectContent.UpdateCompilationUnit(null, parserOutput, fileName);
                }



                return(UpdateParseInformation(parserOutput, fileName));

                //   }
                //}
                //catch (Exception ex)
                //{

                //}
                //finally
                //{


                //}
                //return null;
            }
        }