示例#1
0
        void DomLoaded(ProjectDom dom)
        {
            //make sure it's up to date, or it might still be parsing
            dom.ForceUpdate(true);

            foreach (var type in GetRegisteredObjects(dom))
            {
                if (objcTypes.ContainsKey(type.ObjCName))
                {
                    Console.WriteLine("Duplicate obj-c type '{0}'", type.ObjCName);
                }
                else
                {
                    objcTypes.Add(type.ObjCName, type);
                }
                if (cliTypes.ContainsKey(type.CliName))
                {
                    Console.WriteLine("Duplicate CLI type '{0}'", type.CliName);
                }
                else
                {
                    cliTypes.Add(type.CliName, type);
                }
            }

            foreach (var type in objcTypes.Values)
            {
                ResolveTypes(dom, type);
            }

            if (TypesLoaded != null)
            {
                TypesLoaded(this, EventArgs.Empty);
            }
        }
示例#2
0
        public ProjectDom GetParserContext()
        {
            ProjectDom dom = ProjectDomService.GetProjectDom(Project);

            if (dom != null && needsUpdate)
            {
                needsUpdate = false;
                dom.ForceUpdate();
            }
            return(dom);
        }
示例#3
0
        public override void Setup()
        {
            base.Setup();
            string solFile = Util.GetSampleProject("completion-db-test", "CompletionDbTest.sln");

            solution = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);
            ProjectDomService.Load(solution);

            Project prj;

            prj  = solution.FindProjectByName("Library2");
            lib2 = ProjectDomService.GetProjectDom(prj);
            lib2.ForceUpdate(true);
            prj  = solution.FindProjectByName("Library1");
            lib1 = ProjectDomService.GetProjectDom(prj);
            lib1.ForceUpdate(true);
            prj         = solution.FindProjectByName("CompletionDbTest");
            mainProject = ProjectDomService.GetProjectDom(prj);
            mainProject.ForceUpdate(true);
        }
        internal static RefactoringOptions CreateRefactoringOptions(string text)
        {
            int cursorPosition = -1;
            int endPos         = text.IndexOf('$');

            if (endPos >= 0)
            {
                cursorPosition = endPos;
                text           = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }

            int selectionStart = -1;
            int selectionEnd   = -1;
            int idx            = text.IndexOf("<-");

            if (idx >= 0)
            {
                selectionStart = idx;
                text           = text.Substring(0, idx) + text.Substring(idx + 2);
                selectionEnd   = idx = text.IndexOf("->");

                text = text.Substring(0, idx) + text.Substring(idx + 2);
                if (cursorPosition < 0)
                {
                    cursorPosition = selectionEnd - 1;
                }
            }

            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            TestViewContent     sev = new TestViewContent();
            //		return new RefactoringOptions ();

            DotNetProject project  = new DotNetAssemblyProject("C#");
            Solution      solution = new Solution();

            solution.RootFolder.Items.Add(project);
            project.FileName = GetTempFile(".csproj");
            string file = GetTempFile(".cs");

            project.AddFile(file);
            string parsedText = text;
            string editorText = text;

            ProjectDomService.Load(project);
            ProjectDom dom = ProjectDomService.GetProjectDom(project);

            dom.ForceUpdate(true);
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });

            sev.Project        = project;
            sev.ContentName    = file;
            sev.Text           = editorText;
            sev.CursorPosition = cursorPosition;

            tww.ViewContent = sev;
            var doc = new MonoDevelop.Ide.Gui.Document(tww);

            doc.Editor.Document.MimeType = "text/x-csharp";
            doc.Editor.Document.FileName = file;
            doc.ParsedDocument           = new McsParser().Parse(null, sev.ContentName, parsedText);
            foreach (var e in doc.ParsedDocument.Errors)
            {
                Console.WriteLine(e);
            }
            if (cursorPosition >= 0)
            {
                doc.Editor.Caret.Offset = cursorPosition;
            }
            if (selectionStart >= 0)
            {
                doc.Editor.SetSelection(selectionStart, selectionEnd);
            }

            NRefactoryResolver resolver = new NRefactoryResolver(dom,
                                                                 doc.ParsedDocument.CompilationUnit,
                                                                 sev.Data,
                                                                 file);

            ExpressionResult expressionResult;

            if (selectionStart >= 0)
            {
                expressionResult = new ExpressionResult(editorText.Substring(selectionStart, selectionEnd - selectionStart).Trim());
                endPos           = selectionEnd;
            }
            else
            {
                expressionResult = new NewCSharpExpressionFinder(dom).FindFullExpression(doc.Editor, cursorPosition + 1);
            }
            ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve(expressionResult, new DomLocation(doc.Editor.Caret.Line, doc.Editor.Caret.Column)) : null;

            RefactoringOptions result = new RefactoringOptions {
                Document      = doc,
                Dom           = dom,
                ResolveResult = resolveResult,
                SelectedItem  = null
            };

            if (resolveResult is MemberResolveResult)
            {
                result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember;
            }
            if (resolveResult is LocalVariableResolveResult)
            {
                result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable;
            }
            if (resolveResult is ParameterResolveResult)
            {
                result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter;
            }
            result.TestFileProvider = new FileProvider(result);
            return(result);
        }
示例#5
0
        public static CompletionDataList CreateProvider(string text, string extension, bool isCtrlSpace)
        {
            string parsedText;
            string editorText;
            int    cursorPosition = text.IndexOf('$');
            int    endPos         = text.IndexOf('$', cursorPosition + 1);

            if (endPos == -1)
            {
                parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }
            else
            {
                parsedText     = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1);
                editorText     = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
                cursorPosition = endPos - 1;
            }
            var tww     = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow();
            var sev     = new MonoDevelop.CSharpBinding.Tests.TestViewContent();
            var project = new AspNetAppProject("C#");

            project.FileName = UnitTests.TestBase.GetTempFile(".csproj");

            string file = UnitTests.TestBase.GetTempFile(extension);

            project.AddFile(file);

            ProjectDomService.Load(project);
            ProjectDom dom = ProjectDomService.GetProjectDom(project);

            dom.ForceUpdate(true);
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });

            sev.Project        = project;
            sev.ContentName    = file;
            sev.Text           = editorText;
            sev.CursorPosition = cursorPosition;
            tww.ViewContent    = sev;
            var doc = new MonoDevelop.Ide.Gui.Document(tww);

            doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser().Parse(null, sev.ContentName, parsedText);
            foreach (var e in doc.ParsedDocument.Errors)
            {
                Console.WriteLine(e);
            }

            var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension();

            Initialize(textEditorCompletion, doc);

            int triggerWordLength     = 1;
            CodeCompletionContext ctx = new CodeCompletionContext();

            ctx.TriggerOffset = sev.CursorPosition;
            int line, column;

            sev.GetLineColumnFromPosition(sev.CursorPosition, out line, out column);
            ctx.TriggerLine       = line;
            ctx.TriggerLineOffset = column - 1;

            if (isCtrlSpace)
            {
                return(textEditorCompletion.CodeCompletionCommand(ctx) as CompletionDataList);
            }
            else
            {
                return(textEditorCompletion.HandleCodeCompletion(ctx, editorText[cursorPosition - 1], ref triggerWordLength) as CompletionDataList);
            }
        }
示例#6
0
        protected override BuildResult Build(IProgressMonitor monitor, SolutionEntityItem project, ConfigurationSelector configuration)
        {
            AspNetAppProject aspProject = project as AspNetAppProject;

            //get the config object and validate
            AspNetAppProjectConfiguration config = (AspNetAppProjectConfiguration)aspProject.GetConfiguration(configuration);

            if (config == null)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString
                                          ("Project configuration is invalid. Skipping CodeBehind member generation."));
                return(base.Build(monitor, project, configuration));
            }

            if (config.DisableCodeBehindGeneration)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString
                                          ("Skipping updating of CodeBehind partial classes, because this feature is disabled."));
                return(base.Build(monitor, project, configuration));
            }

            CodeBehindWriter writer = CodeBehindWriter.CreateForProject(monitor, aspProject);

            if (!writer.SupportsPartialTypes)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString
                                          ("The code generator for {0} does not support partial classes. Skipping CodeBehind member generation.",
                                          aspProject.LanguageBinding.Language));;
                return(base.Build(monitor, project, configuration));
            }

            //get the extension used for codebehind files
            string langExt = aspProject.LanguageBinding.GetFileName("a");

            langExt = langExt.Substring(1, langExt.Length - 1);

            List <CodeBehindWarning> errors = new List <CodeBehindWarning> ();

            monitor.Log.WriteLine(GettextCatalog.GetString("Generating CodeBehind members..."));

            bool updatedParseDb = false;

            //go over all the files generating members where necessary
            foreach (ProjectFile file in aspProject.Files)
            {
                WebSubtype type = AspNetAppProject.DetermineWebSubtype(file.FilePath);
                if (type != WebSubtype.WebForm && type != WebSubtype.WebControl && type != WebSubtype.MasterPage)
                {
                    continue;
                }

                //find the designer file
                ProjectFile designerFile = aspProject.Files.GetFile(file.Name + ".designer" + langExt);
                if (designerFile == null)
                {
                    aspProject.Files.GetFile(file.Name + ".Designer" + langExt);
                }
                if (designerFile == null)
                {
                    continue;
                }

                //only regenerate the designer class if it's older than the aspx (etc) file
                if (System.IO.File.GetLastWriteTimeUtc(designerFile.FilePath)
                    > System.IO.File.GetLastWriteTimeUtc(file.FilePath))
                {
                    continue;
                }

                //need parse DB to be up to date
                if (!updatedParseDb)
                {
                    updatedParseDb = true;
                    monitor.Log.Write(GettextCatalog.GetString("Waiting for project type database to finish updating..."));
                    ProjectDom dom = ProjectDomService.GetProjectDom(aspProject);
                    dom.ForceUpdate(true);
                    monitor.Log.WriteLine(GettextCatalog.GetString(" complete."));
                }

                //parse the ASP.NET file
                var parsedDocument = ProjectDomService.Parse(aspProject, file.FilePath) as AspNetParsedDocument;
                if (parsedDocument == null)
                {
                    continue;
                }

                var ccu = CodeBehind.GenerateCodeBehind(aspProject, designerFile.FilePath, parsedDocument, errors);
                if (ccu == null)
                {
                    continue;
                }

                writer.Write(ccu, designerFile.FilePath);
            }

            writer.WriteOpenFiles();

            //write out a friendly message aout what we did
            if (writer.WrittenCount > 0)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString("{0} CodeBehind designer classes updated.", writer.WrittenCount));
            }
            else
            {
                monitor.Log.WriteLine(GettextCatalog.GetString("No changes made to CodeBehind classes."));
            }

            //and construct and return a build result
            BuildResult baseResult = base.Build(monitor, project, configuration);

            foreach (CodeBehindWarning cbw in errors)
            {
                if (cbw.FileName != null)
                {
                    baseResult.AddWarning(cbw.FileName, cbw.Line, cbw.Column, null, cbw.WarningText);
                }
                else
                {
                    baseResult.AddWarning(cbw.WarningText);
                }
            }
            return(baseResult);
        }