public void RewriteAllModules()
 {
     foreach (var module in _moduleStates.Where(s => ProjectsProvider.Component(s.Key) != null))
     {
         module.Value.ModuleRewriter.Rewrite();
     }
 }
Example #2
0
        protected override void OnExecute(object parameter)
        {
            if (!(parameter is CodeExplorerComponentViewModel node) ||
                node.Declaration == null ||
                node.Declaration.QualifiedName.QualifiedModuleName.ComponentType == ComponentType.Document)
            {
                return;
            }

            var qualifiedModuleName = node.Declaration.QualifiedName.QualifiedModuleName;
            var message             = string.Format(CodeExplorerUI.ExportBeforeRemove_Prompt, node.Name);

            switch (MessageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes))
            {
            case ConfirmationOutcome.Yes:
                if (!PromptFileNameAndExport(qualifiedModuleName))
                {
                    return;
                }
                break;

            case ConfirmationOutcome.No:
                break;

            case ConfirmationOutcome.Cancel:
                return;
            }

            // No file export or file successfully exported--now remove it
            var components = ProjectsProvider.ComponentsCollection(qualifiedModuleName.ProjectId);

            try
            {
                components?.Remove(ProjectsProvider.Component(qualifiedModuleName));
            }
            catch (Exception ex)
            {
                MessageBox.NotifyWarn(ex.Message, string.Format(CodeExplorerUI.RemoveError_Caption, qualifiedModuleName.ComponentName));
            }
        }
        private ParserState OverallParserStateFromModuleStates()
        {
            if (_moduleStates.IsEmpty)
            {
                return(ParserState.Ready);
            }

            var moduleStates = new List <ParserState>();

            foreach (var moduleState in _moduleStates)
            {
                if (string.IsNullOrEmpty(moduleState.Key.ComponentName) || ProjectsProvider.Component(moduleState.Key) == null || !moduleState.Key.IsParsable)
                {
                    continue;
                }

                moduleStates.Add(moduleState.Value.State);
            }

            if (moduleStates.Count == 0)
            {
                return(ParserState.Ready);
            }

            var state = moduleStates[0];

            foreach (var moduleState in moduleStates)
            {
                if (moduleState != moduleStates[0])
                {
                    state = default;
                    break;
                }
            }

            if (state != default)
            {
                // if all modules are in the same state, we have our result.
                return(state);
            }

            var stateCounts = new int[States.Count];

            foreach (var moduleState in moduleStates)
            {
                stateCounts[(int)moduleState]++;
            }

            // error state takes precedence over every other state
            if (stateCounts[(int)ParserState.UnexpectedError] > 0)
            {
                return(ParserState.UnexpectedError);
            }
            if (stateCounts[(int)ParserState.Error] > 0)
            {
                return(ParserState.Error);
            }
            if (stateCounts[(int)ParserState.ResolverError] > 0)
            {
                return(ParserState.ResolverError);
            }

            //The lowest state wins.
            var result = ParserState.None;

            foreach (var item in moduleStates)
            {
                if (item < result)
                {
                    result = item;
                }
            }

            if (result == ParserState.Ready)
            {
                for (var i = 0; i < stateCounts.Length; i++)
                {
                    if (i == (int)ParserState.Ready || i == (int)ParserState.None)
                    {
                        continue;
                    }

                    if (stateCounts[i] != 0)
                    {
                        result = (ParserState)i;
                    }
                }
            }

#if DEBUG
            if (state == ParserState.Ready)
            {
                for (var i = 0; i < stateCounts.Length; i++)
                {
                    if (i == (int)ParserState.Ready || i == (int)ParserState.None)
                    {
                        continue;
                    }

                    if (stateCounts[i] != 0)
                    {
                        Debug.Assert(false, "State is ready, but component has non-ready/non-none state");
                    }
                }
            }
#endif

            return(result);
        }
        private int GetModuleContentHash(QualifiedModuleName module)
        {
            var component = ProjectsProvider.Component(module);

            return(QualifiedModuleName.GetModuleContentHash(component));
        }
 public void AddTokenStream(QualifiedModuleName module, ITokenStream stream)
 {
     _moduleStates[module].SetTokenStream(ProjectsProvider.Component(module).CodeModule, stream);
     _moduleStates[module].SetModuleContentHashCode(GetModuleContentHash(module));
 }