ExpressionContext FindExactContextForNewCompletion(ITextEditor editor, string documentToCursor,
                                                           IDocumentLine currentLine, int pos)
        {
            CSharpExpressionFinder ef = CreateExpressionFinder(editor.FileName);
            // find expression on left hand side of the assignment
            ExpressionResult lhsExpr = ef.FindExpression(documentToCursor, currentLine.Offset + pos);

            if (lhsExpr.Expression != null)
            {
                ResolveResult rr = ParserService.Resolve(lhsExpr, currentLine.LineNumber, pos, editor.FileName, editor.Document.Text);
                if (rr != null && rr.ResolvedType != null)
                {
                    ExpressionContext context;
                    IClass            c;
                    if (rr.ResolvedType.IsArrayReturnType)
                    {
                        // when creating an array, all classes deriving from the array's element type are allowed
                        IReturnType elementType = rr.ResolvedType.CastToArrayReturnType().ArrayElementType;
                        c = elementType != null?elementType.GetUnderlyingClass() : null;

                        context = ExpressionContext.TypeDerivingFrom(elementType, false);
                    }
                    else
                    {
                        // when creating a normal instance, all non-abstract classes deriving from the type
                        // are allowed
                        c       = rr.ResolvedType.GetUnderlyingClass();
                        context = ExpressionContext.TypeDerivingFrom(rr.ResolvedType, true);
                    }
                    if (c != null && context.ShowEntry(c))
                    {
                        // Try to suggest an entry (List<int> a = new => suggest List<int>).

                        string suggestedClassName = LanguageProperties.CSharp.CodeGenerator.GenerateCode(
                            CodeGenerator.ConvertType(
                                rr.ResolvedType,
                                new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.Caret.Line, editor.Caret.Column)
                                ), "");
                        if (suggestedClassName != c.Name)
                        {
                            // create a special code completion item that completes also the type arguments
                            context.SuggestedItem = new SuggestedCodeCompletionItem(c, suggestedClassName);
                        }
                        else
                        {
                            context.SuggestedItem = new CodeCompletionItem(c);
                        }
                    }
                    return(context);
                }
            }
            return(null);
        }
Exemple #2
0
 static ResolveResult ResolveExpressionAtCaret(ITextEditor textArea, ExpressionResult expressionResult)
 {
     if (expressionResult.Expression != null)
     {
         if (expressionResult.Region.IsEmpty)
         {
             expressionResult.Region = new DomRegion(textArea.Caret.Line, textArea.Caret.Column);
         }
         return(resolver.Resolve(expressionResult, ParserService.GetParseInformation(textArea.FileName), textArea.Document.Text));
     }
     return(null);
 }
Exemple #3
0
 protected override void OnPropertyChanged(ProjectPropertyChangedEventArgs e)
 {
     base.OnPropertyChanged(e);
     if (reparseReferencesSensitiveProperties.Contains(e.PropertyName))
     {
         ParserService.Reparse(this, true, false);
     }
     if (reparseCodeSensitiveProperties.Contains(e.PropertyName))
     {
         ParserService.Reparse(this, false, true);
     }
 }
Exemple #4
0
        protected override ParseProjectContent CreateProjectContent()
        {
            ParseProjectContent  pc    = base.CreateProjectContent();
            ReferenceProjectItem vbRef = new ReferenceProjectItem(this, "Microsoft.VisualBasic");

            if (vbRef != null)
            {
                pc.AddReferencedContent(ParserService.GetProjectContentForReference(vbRef));
            }
            MyNamespaceBuilder.BuildNamespace(this, pc);
            return(pc);
        }
        public static void AddUsingDeclaration(ICompilationUnit cu, IDocument document, string newNamespace, bool sortExistingUsings)
        {
            if (cu == null)
            {
                throw new ArgumentNullException("cu");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (newNamespace == null)
            {
                throw new ArgumentNullException("newNamespace");
            }

            ParseInformation info = ParserService.ParseFile(cu.FileName, document.TextContent);

            if (info != null)
            {
                cu = info.MostRecentCompilationUnit;
            }

            IUsing newUsingDecl = new DefaultUsing(cu.ProjectContent);

            newUsingDecl.Usings.Add(newNamespace);

            List <IUsing> newUsings = new List <IUsing>(cu.UsingScope.Usings);

            if (sortExistingUsings)
            {
                newUsings.Sort(CompareUsings);
            }
            bool inserted = false;

            for (int i = 0; i < newUsings.Count; i++)
            {
                if (CompareUsings(newUsingDecl, newUsings[i]) <= 0)
                {
                    newUsings.Insert(i, newUsingDecl);
                    inserted = true;
                    break;
                }
            }
            if (!inserted)
            {
                newUsings.Add(newUsingDecl);
            }
            if (sortExistingUsings)
            {
                PutEmptyLineAfterLastSystemNamespace(newUsings);
            }
            cu.ProjectContent.Language.CodeGenerator.ReplaceUsings(new TextEditorDocument(document), cu.UsingScope.Usings, newUsings);
        }
        void CreateChangedEvent(object sender, EventArgs e)
        {
            MenuCommand item       = (MenuCommand)sender;
            IProperty   member     = (IProperty)item.Tag;
            ITextEditor textEditor = FindReferencesAndRenameHelper.JumpBehindDefinition(member);

            if (textEditor != null)
            {
                member.DeclaringType.ProjectContent.Language.CodeGenerator.CreateChangedEvent(member, new RefactoringDocumentAdapter(textEditor.Document));
                ParserService.ParseCurrentViewContent();
            }
        }
Exemple #7
0
        void FetchParseInformation()
        {
            ParseInformation parseInfo = ParserService.GetExistingParseInformation(this.FileName);

            if (parseInfo == null)
            {
                // if parse info is not yet available, start parsing on background
                ParserService.BeginParse(this.FileName, primaryTextEditorAdapter.Document);
                // we'll receive the result using the ParseInformationUpdated event
            }
            ParseInformationUpdated(parseInfo);
        }
Exemple #8
0
            public override void Execute()
            {
                var codeGen = TargetClass.ProjectContent.Language.CodeGenerator;
                var d       = FindReferencesAndRenameHelper.GetDocument(TargetClass);

                if (d == null)
                {
                    return;
                }
                codeGen.ImplementInterface(this.ClassToImplement, new RefactoringDocumentAdapter(d), this.IsExplicitImpl, this.TargetClass);
                ParserService.ParseCurrentViewContent();
            }
        public void SetupDataProvider(string fileName, TextArea textArea)
        {
            if (setupOnlyOnce && this.textArea != null)
            {
                return;
            }
            IDocument document = textArea.Document;

            this.fileName = fileName;
            this.document = document;
            this.textArea = textArea;
            int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;

            initialOffset = useOffset;


            IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);
            ExpressionResult  expressionResult;

            if (expressionFinder == null)
            {
                expressionResult = new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, useOffset));
            }
            else
            {
                expressionResult = expressionFinder.FindExpression(textArea.Document.TextContent, useOffset);
            }

            if (expressionResult.Expression == null)             // expression is null when cursor is in string/comment
            {
                return;
            }
            expressionResult.Expression = expressionResult.Expression.Trim();

            if (LoggingService.IsDebugEnabled)
            {
                if (expressionResult.Context == ExpressionContext.Default)
                {
                    LoggingService.DebugFormatted("ShowInsight for >>{0}<<", expressionResult.Expression);
                }
                else
                {
                    LoggingService.DebugFormatted("ShowInsight for >>{0}<<, context={1}", expressionResult.Expression, expressionResult.Context);
                }
            }

            int caretLineNumber = document.GetLineNumberForOffset(useOffset);
            int caretColumn     = useOffset - document.GetLineSegment(caretLineNumber).Offset;

            // the parser works with 1 based coordinates
            SetupDataProvider(fileName, document, expressionResult, caretLineNumber + 1, caretColumn + 1);
        }
Exemple #10
0
        public MenuItem Create(RefactoringMenuContext context)
        {
            if (context.ExpressionResult.Context == ExpressionContext.Attribute)
            {
                return(null);
            }
            if (!(context.ResolveResult is UnknownMethodResolveResult))
            {
                return(null);
            }
            if (context.ProjectContent == null)
            {
                return(null);
            }

            UnknownMethodResolveResult rr = context.ResolveResult as UnknownMethodResolveResult;

            MenuItem item = new MenuItem()
            {
                Header = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.ResolveExtensionMethod}"), rr.CallName),
                Icon   = ClassBrowserIconService.GotoArrow.CreateImage()
            };

            List <IClass> results = new List <IClass>();

            SearchAllExtensionMethodsWithName(results, context.ProjectContent, rr.CallName);

            foreach (IProjectContent content in context.ProjectContent.ThreadSafeGetReferencedContents())
            {
                SearchAllExtensionMethodsWithName(results, content, rr.CallName);
            }

            if (!results.Any())
            {
                return(null);
            }

            foreach (IClass c in results)
            {
                string   newNamespace = c.Namespace;
                MenuItem subItem      = new MenuItem();
                subItem.Header = "using " + newNamespace;
                subItem.Icon   = ClassBrowserIconService.Namespace.CreateImage();
                item.Items.Add(subItem);
                subItem.Click += delegate {
                    NamespaceRefactoringService.AddUsingDeclaration(context.CompilationUnit, context.Editor.Document, newNamespace, true);
                    ParserService.BeginParse(context.Editor.FileName, context.Editor.Document);
                };
            }

            return(item);
        }
Exemple #11
0
        protected IProjectContent GetProjectContent()
        {
            IProject p = FindProjectContainingFile();

            if (p != null)
            {
                return(ParserService.GetProjectContent(p) ?? ParserService.DefaultProjectContent);
            }
            else
            {
                return(ParserService.DefaultProjectContent);
            }
        }
        void UpdateIconMargin()
        {
            codeView.IconBarManager.UpdateClassMemberBookmarks(
                ParserService.ParseFile(tempFileName, new AvalonEditDocumentAdapter(codeView.Document, null)),
                null);

            // load bookmarks
            foreach (SDBookmark bookmark in BookmarkManager.GetBookmarks(this.codeView.TextEditor.FileName))
            {
                bookmark.Document = this.codeView.TextEditor.Document;
                codeView.IconBarManager.Bookmarks.Add(bookmark);
            }
        }
 static void HandleRemovedSolutionFolder(ISolutionFolder folder)
 {
     if (folder is IProject)
     {
         OpenSolution.RemoveProjectConfigurations(folder.IdGuid);
         ParserService.RemoveProjectContentForRemovedProject((IProject)folder);
     }
     if (folder is ISolutionFolderContainer)
     {
         // recurse into child folders that were also removed
         ((ISolutionFolderContainer)folder).Folders.ForEach(HandleRemovedSolutionFolder);
     }
 }
        public override void Run()
        {
            ReferenceNode node = Owner as ReferenceNode;

            if (node != null)
            {
                ReferenceProjectItem item = node.ReferenceProjectItem;
                if (item != null)
                {
                    ParserService.RefreshProjectContentForReference(item);
                }
            }
        }
Exemple #15
0
        public void ParseMechanism_Streaming()
        {
            ParserService parserService = new ParserService();
            string        mechanism     = "streaming";

            var output   = parserService.ParserMechanisms(mechanism);
            var expected = new List <DistributionMechanism> {
                DistributionMechanism.streaming
            };


            Assert.AreEqual(expected, output);
        }
 public static void AddProject(ISolutionFolderNode solutionFolderNode, IProject newProject)
 {
     if (solutionFolderNode.Solution.SolutionFolders.Any(
             folder => string.Equals(folder.IdGuid, newProject.IdGuid, StringComparison.OrdinalIgnoreCase)))
     {
         LoggingService.Warn("ProjectService.AddProject: Duplicate IdGuid detected");
         newProject.IdGuid = Guid.NewGuid().ToString().ToUpperInvariant();
     }
     solutionFolderNode.Container.AddFolder(newProject);
     ParserService.CreateProjectContentForAddedProject(newProject);
     solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject });
     OnProjectAdded(new ProjectEventArgs(newProject));
 }
        public virtual void Complete(CompletionContext context)
        {
            MarkAsUsed();

            string insertedText  = this.Text;
            IClass selectedClass = GetClassOrExtensionMethodClass(this.Entity);

            if (selectedClass != null)
            {
                // Class or Extension method is being inserted
                var editor   = context.Editor;
                var document = context.Editor.Document;
                //  Resolve should return AmbiguousResolveResult or something like that when we resolve a name that exists in more imported namespaces
                //   - so that we would know that we always want to insert fully qualified name
                var nameResult = ResolveAtCurrentOffset(selectedClass.Name, context);

                bool addUsing = false;

                if (this.Entity is IClass)
                {
                    if (!IsUserTypingFullyQualifiedName(context))
                    {
                        nameResult = ResolveAtCurrentOffset(insertedText, context);
                        addUsing   = (!IsKnownName(nameResult));
                    }
                    // Special case for Attributes
                    if (insertedText.EndsWith("Attribute") && IsInAttributeContext(editor, context.StartOffset))
                    {
                        insertedText = insertedText.RemoveEnd("Attribute");
                    }
                }
                else if (this.Entity is IMethod)
                {
                    addUsing = !IsKnownName(nameResult);
                }

                InsertTextStripGenericArguments(context, insertedText, this.InsertGenericArguments);

                if (addUsing && nameResult != null && nameResult.CallingClass != null)
                {
                    var cu = nameResult.CallingClass.CompilationUnit;
                    NamespaceRefactoringService.AddUsingDeclaration(cu, document, selectedClass.Namespace, false);
                    ParserService.BeginParse(editor.FileName, document);
                }
            }
            else
            {
                // Something else than a class or Extension method is being inserted - just insert text
                InsertTextStripGenericArguments(context, insertedText, this.InsertGenericArguments);
            }
        }
Exemple #18
0
        /// <summary>
        /// Gets debugger tooltip information for the specified position.
        /// A descriptive text for the element or a DebuggerGridControl
        /// showing its current value (when in debugging mode) can be returned
        /// through the ToolTipInfo object.
        /// Returns <c>null</c>, if no tooltip information is available.
        /// </summary>
        internal static ToolTipInfo GetToolTipInfo(TextArea textArea, ToolTipRequestEventArgs e)
        {
            TextLocation      logicPos         = e.LogicalPosition;
            IDocument         doc              = textArea.Document;
            IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(textArea.MotherTextEditorControl.FileName);

            if (expressionFinder == null)
            {
                return(null);
            }
            LineSegment seg = doc.GetLineSegment(logicPos.Y);

            if (logicPos.X > seg.Length - 1)
            {
                return(null);
            }
            string           textContent      = doc.TextContent;
            ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, seg.Offset + logicPos.X);
            string           expression       = (expressionResult.Expression ?? "").Trim();

            if (expression.Length > 0)
            {
                // Look if it is variable
                ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y + 1, logicPos.X + 1, textArea.MotherTextEditorControl.FileName, textContent);
                bool          debuggerCanShowValue;
                string        toolTipText = GetText(result, expression, out debuggerCanShowValue);
                if (Control.ModifierKeys == Keys.Control)
                {
                    toolTipText          = "expr: " + expressionResult.ToString() + "\n" + toolTipText;
                    debuggerCanShowValue = false;
                }
                if (toolTipText != null)
                {
                    if (debuggerCanShowValue && currentDebugger != null)
                    {
                        return(new ToolTipInfo(currentDebugger.GetTooltipControl(expressionResult.Expression)));
                    }
                    return(new ToolTipInfo(toolTipText));
                }
            }
            else
            {
                                #if DEBUG
                if (Control.ModifierKeys == Keys.Control)
                {
                    return(new ToolTipInfo("no expr: " + expressionResult.ToString()));
                }
                                #endif
            }
            return(null);
        }
        public ResultService Search(string language)
        {
            StreamReader     reader;
            ParserService    ps = new ParserService();
            SanitizerService ss = new SanitizerService();
            string           queryURL = string.Format(URL, ss.SanitizeInput(language));
            string           html, numResultsStr;
            long             numResults;

            try
            {
                HttpWebRequest request = HttpWebRequest.CreateHttp(queryURL);
                request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; .NET CLR 1.0.3705;)";
                request.Timeout   = 60000;
                request.Method    = "GET";
                WebResponse response = request.GetResponse();

                using (Stream dataStream = response.GetResponseStream())
                {
                    reader        = new StreamReader(dataStream, Encoding.ASCII);
                    html          = reader.ReadToEnd();
                    numResultsStr = ps.Parse(html, RegexPattern);
                }
                reader.Close();
                response.Close();

                numResults = ss.SanitizeOutput(numResultsStr);

                if (numResults == -1)
                {
                    throw new System.InvalidCastException();
                }
                return(new ResultService {
                    EngineName = Name, Language = language, NumResults = numResults
                });
            }
            catch (WebException e)
            {
                Console.WriteLine("SearchFight | error: {0} on {1} search: \"{2}\". Please try again.", e.Status, Name, language);
                return(new ResultService {
                    EngineName = Name, Language = language, NumResults = -1
                });
            }
            catch (InvalidCastException e)
            {
                Console.WriteLine("SearchFight | error: Result could not be parsed. The term entered had 0 results or check App.config for configuration of engine {0}", Name);
                return(new ResultService {
                    EngineName = Name, Language = language, NumResults = -1
                });
            }
        }
        public static IParser GetParser(string fileName)
        {
            IParser p;

            if (presetParsersUnitTestOnly == null)
            {
                p = ParserService.GetParser(fileName);
            }
            else
            {
                presetParsersUnitTestOnly.TryGetValue(System.IO.Path.GetExtension(fileName), out p);
            }
            return(p);
        }
Exemple #21
0
        public static void InitializeWorkbench(IWorkbench workbench, IWorkbenchLayout layout)
        {
            WorkbenchSingleton.workbench = workbench;

            LanguageService.ValidateLanguage();

            DisplayBindingService.InitializeService();
            LayoutConfiguration.LoadLayoutConfiguration();
            FileService.InitializeService();
            DomHostCallback.Register();             // must be called after StatusBarService.Initialize()
            ParserService.InitializeParserService();
            TaskService.Initialize();
            Bookmarks.BookmarkManager.Initialize();
            Project.CustomToolsService.Initialize();
            Project.BuildModifiedProjectsOnlyService.Initialize();

            var messageService = Core.Services.ServiceManager.Instance.MessageService as IDialogMessageService;

            if (messageService != null)
            {
                messageService.DialogOwner = workbench.MainWin32Window;
                Debug.Assert(messageService.DialogOwner != null);
                messageService.DialogSynchronizeInvoke = workbench.SynchronizingObject;
            }

            workbench.Initialize();
            workbench.SetMemento(PropertyService.Get(workbenchMemento, new Properties()));
            workbench.WorkbenchLayout = layout;

            ApplicationStateInfoService.RegisterStateGetter(activeContentState, delegate { return(WorkbenchSingleton.Workbench.ActiveContent); });

            OnWorkbenchCreated();

            // initialize workbench-dependent services:
            Project.ProjectService.InitializeService();
            NavigationService.InitializeService();

            workbench.ActiveContentChanged += delegate {
                Debug.WriteLine("ActiveContentChanged to " + workbench.ActiveContent);
                LoggingService.Debug("ActiveContentChanged to " + workbench.ActiveContent);
            };
            workbench.ActiveViewContentChanged += delegate {
                Debug.WriteLine("ActiveViewContentChanged to " + workbench.ActiveViewContent);
                LoggingService.Debug("ActiveViewContentChanged to " + workbench.ActiveViewContent);
            };
            workbench.ActiveWorkbenchWindowChanged += delegate {
                Debug.WriteLine("ActiveWorkbenchWindowChanged to " + workbench.ActiveWorkbenchWindow);
                LoggingService.Debug("ActiveWorkbenchWindowChanged to " + workbench.ActiveWorkbenchWindow);
            };
        }
Exemple #22
0
        static IClass GetCurrentClass(ITextEditor editor)
        {
            var caret            = editor.Caret;
            NRefactoryResolver r = new NRefactoryResolver(LanguageProperties.VBNet);

            if (r.Initialize(ParserService.GetParseInformation(editor.FileName), caret.Line, caret.Column))
            {
                return(r.CallingClass);
            }
            else
            {
                return(null);
            }
        }
        public void ParseFileTest_DefineWithValueTest_Newline()
        {
            ParserService     target = new ParserService();
            string            file   = "test.asm";
            string            lines  = "#define Label1 10\r\n #define Label2 20";
            ParserInformation actual;

            actual = target.ParseFile(file, lines);
            Assert.AreEqual(2, actual.DefinesList.Count);
            Assert.AreEqual("Label1", actual.DefinesList.ElementAt(0).Name);
            Assert.AreEqual("Label2", actual.DefinesList.ElementAt(1).Name);
            Assert.AreEqual("10", actual.DefinesList.ElementAt(0).Contents);
            Assert.AreEqual("20", actual.DefinesList.ElementAt(1).Contents);
        }
Exemple #24
0
        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            ParseInformation parseInfo = ParserService.GetParseInformation(fileName);

            if (parseInfo == null)
            {
                return(null);
            }
            IClass c = parseInfo.MostRecentCompilationUnit.GetInnermostClass(textArea.Caret.Line, textArea.Caret.Column);

            if (c == null)
            {
                return(null);
            }
            List <ICompletionData> result = new List <ICompletionData>();

            foreach (IMethod m in c.DefaultReturnType.GetMethods())
            {
                if (m.IsPublic || m.IsProtected)
                {
                    if (m.IsAbstract || m.IsVirtual || m.IsOverride)
                    {
                        if (!m.IsSealed && !m.IsConst)
                        {
                            if (m.DeclaringType.FullyQualifiedName != c.FullyQualifiedName)
                            {
                                result.Add(new OverrideCompletionData(m));
                            }
                        }
                    }
                }
            }
            foreach (IProperty m in c.DefaultReturnType.GetProperties())
            {
                if (m.IsPublic || m.IsProtected)
                {
                    if (m.IsAbstract || m.IsVirtual || m.IsOverride)
                    {
                        if (!m.IsSealed && !m.IsConst)
                        {
                            if (m.DeclaringType.FullyQualifiedName != c.FullyQualifiedName)
                            {
                                result.Add(new OverrideCompletionData(m));
                            }
                        }
                    }
                }
            }
            return(result.ToArray());
        }
Exemple #25
0
        public void ParseMechanism_Both()
        {
            ParserService parserService = new ParserService();
            string        mechanism     = " digital download, streaming ";

            var output   = parserService.ParserMechanisms(mechanism);
            var expected = new List <DistributionMechanism> {
                DistributionMechanism.digitaldownload, DistributionMechanism.streaming
            };


            Assert.AreEqual(expected.First(), output.First());
            Assert.AreEqual(expected.Last(), output.Last());
        }
        public void ParseFileTest_EquateTest_Slash()
        {
            ParserService     target = new ParserService();
            string            file   = "test.asm";
            string            lines  = "Label1 .equ 10\\Label2 .equ 6";
            ParserInformation actual;

            actual = target.ParseFile(file, lines);
            Assert.AreEqual(2, actual.DefinesList.Count);
            Assert.AreEqual("Label1", actual.DefinesList.ElementAt(0).Name);
            Assert.AreEqual("Label2", actual.DefinesList.ElementAt(1).Name);
            Assert.AreEqual("10", actual.DefinesList.ElementAt(0).Contents);
            Assert.AreEqual("6", actual.DefinesList.ElementAt(1).Contents);
        }
        /// <summary>
        /// Gets the next member after the specified caret position.
        /// </summary>
        static object GetMemberAfter(ITextEditor editor, int caretLine)
        {
            string fileName    = editor.FileName;
            object nextElement = null;

            if (fileName != null && fileName.Length > 0)
            {
                ParseInformation parseInfo = ParserService.ParseFile(fileName, editor.Document);
                if (parseInfo != null)
                {
                    ICompilationUnit currentCompilationUnit = parseInfo.CompilationUnit;
                    if (currentCompilationUnit != null)
                    {
                        IClass currentClass    = currentCompilationUnit.GetInnermostClass(caretLine, 0);
                        int    nextElementLine = int.MaxValue;
                        if (currentClass == null)
                        {
                            foreach (IClass c in currentCompilationUnit.Classes)
                            {
                                if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine)
                                {
                                    nextElementLine = c.Region.BeginLine;
                                    nextElement     = c;
                                }
                            }
                        }
                        else
                        {
                            foreach (IClass c in currentClass.InnerClasses)
                            {
                                if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine)
                                {
                                    nextElementLine = c.Region.BeginLine;
                                    nextElement     = c;
                                }
                            }
                            foreach (IMember m in currentClass.AllMembers)
                            {
                                if (m.Region.BeginLine < nextElementLine && m.Region.BeginLine > caretLine)
                                {
                                    nextElementLine = m.Region.BeginLine;
                                    nextElement     = m;
                                }
                            }
                        }
                    }
                }
            }
            return(nextElement);
        }
        public void ParseFileTest_MacroWithArgsTest_ExtraComma()
        {
            ParserService     target = new ParserService();
            string            file   = "test.asm";
            string            lines  = "#macro TestMacro(arg1, arg2, )\r\n\tld hl,1\r\n#endmacro";
            ParserInformation actual;

            actual = target.ParseFile(file, lines);
            Assert.AreEqual(1, actual.MacrosList.Count);
            Assert.AreEqual("TestMacro", actual.MacrosList.ElementAt(0).Name);
            Assert.AreEqual(2, actual.MacrosList.ElementAt(0).Arguments.Count);
            Assert.AreEqual("arg1", actual.MacrosList.ElementAt(0).Arguments[0]);
            Assert.AreEqual("arg2", actual.MacrosList.ElementAt(0).Arguments[1]);
        }
        public void ParseFileTest_EquateTest_MissingValue_Newline()
        {
            ParserService     target = new ParserService();
            string            file   = "test.asm";
            string            lines  = "Label1 .equ \r\nLabel2 .equ ";
            ParserInformation actual;

            actual = target.ParseFile(file, lines);
            Assert.AreEqual(2, actual.DefinesList.Count);
            Assert.AreEqual("Label1", actual.DefinesList.ElementAt(0).Name);
            Assert.AreEqual("Label2", actual.DefinesList.ElementAt(1).Name);
            Assert.IsTrue(string.IsNullOrEmpty(actual.DefinesList.ElementAt(0).Contents));
            Assert.IsTrue(string.IsNullOrEmpty(actual.DefinesList.ElementAt(1).Contents));
        }
        void Register(string prog)
        {
            DefaultProjectContent pc = new DefaultProjectContent();

            lastPC = pc;
            HostCallback.GetCurrentProjectContent = delegate { return(pc); };
            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference("System.Windows.Forms", typeof(System.Windows.Forms.Form).Module.FullyQualifiedName));
            pc.ReferencedContents.Add(booLangPC);
            ICompilationUnit cu = new BooParser().Parse(pc, fileName, new StringTextBuffer(prog));

            ParserService.RegisterParseInformation(fileName, cu);
            cu.Classes.ForEach(pc.AddClassToNamespaceList);
        }
 public AbstractSyntaxTreeTagger(ParserService parserService)
 {
     this.parserService = parserService;
 }