示例#1
0
 public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
 {
     return new NamingRule(
         info.GetSymbolSpecification(SymbolSpecificationID),
         info.GetNamingStyle(NamingStyleID),
         EnforcementLevel);
 }
        private string MethodNamesArePascalCaseOptionString()
        {
            var symbolSpecification = new SymbolSpecification(
                Guid.NewGuid(),
                "Name",
                SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Method)).ToList(),
                SpecializedCollections.EmptyList<SymbolSpecification.AccessibilityKind>(),
                SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>());

            var namingStyle = new NamingStyle();
            namingStyle.CapitalizationScheme = Capitalization.PascalCase;
            namingStyle.Name = "Name";
            namingStyle.Prefix = "";
            namingStyle.Suffix = "";
            namingStyle.WordSeparator = "";


            var namingRule = new SerializableNamingRule();
            namingRule.SymbolSpecificationID = symbolSpecification.ID;
            namingRule.NamingStyleID = namingStyle.ID;
            namingRule.EnforcementLevel = DiagnosticSeverity.Error;

            var info = new SerializableNamingStylePreferencesInfo();
            info.SymbolSpecifications.Add(symbolSpecification);
            info.NamingStyles.Add(namingStyle);
            info.NamingRules.Add(namingRule);

            return info.CreateXElement().ToString();
        }
 public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
 {
     return(new NamingRule(
                info.GetSymbolSpecification(SymbolSpecificationID),
                info.GetNamingStyle(NamingStyleID),
                EnforcementLevel));
 }
示例#4
0
 public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
 {
     return(new NamingRule(
                Title,
                Children.Select(c => c.GetRule(info)).ToImmutableArray(),
                info.GetSymbolSpecification(SymbolSpecificationID),
                info.GetNamingStyle(NamingStyleID),
                EnforcementLevel));
 }
示例#5
0
 public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
 {
     return new NamingRule(
         Title,
         Children.Select(c => c.GetRule(info)).ToImmutableArray(),
         info.GetSymbolSpecification(SymbolSpecificationID),
         info.GetNamingStyle(NamingStyleID),
         EnforcementLevel);
 }
 internal NamingStylesOptionPageControlViewModel(SerializableNamingStylePreferencesInfo info, string languageName, ImmutableArray<string> categories, INotificationService notificationService)
 {
     this._languageName = languageName;
     this.categories = categories;
     this.notificationService = notificationService;
     this.SymbolSpecificationList = new ObservableCollection<SymbolSpecificationViewModel>(info.SymbolSpecifications.Select(s => new SymbolSpecificationViewModel(languageName, categories, s, notificationService)));
     this.NamingStyleList = new ObservableCollection<NamingStyleViewModel>(info.NamingStyles.Select(s => new NamingStyleViewModel(s, this.notificationService)));
     this.rootNamingRule = CreateRoot(info);
 }
        internal static SerializableNamingStylePreferencesInfo FromXElement(XElement namingPreferencesInfoElement)
        {
            var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo();

            namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications)));
            namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles)));
            namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules)));

            return(namingPreferencesInfo);
        }
        internal static SerializableNamingStylePreferencesInfo FromXElement(XElement namingPreferencesInfoElement)
        {
            var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo();

            var serializationVersion = int.Parse(namingPreferencesInfoElement.Attribute("SerializationVersion").Value);

            if (serializationVersion != s_serializationVersion)
            {
                namingPreferencesInfoElement = XElement.Parse(SimplificationOptions.NamingPreferences.DefaultValue);
            }

            namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications)));
            namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles)));
            namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules)));

            return(namingPreferencesInfo);
        }
        private void CompilationStartAction(CompilationStartAnalysisContext context)
        {
            var workspace    = (context.Options as WorkspaceAnalyzerOptions)?.Workspace;
            var optionSet    = (context.Options as WorkspaceAnalyzerOptions)?.Workspace.Options;
            var currentValue = optionSet.GetOption(SimplificationOptions.NamingPreferences, context.Compilation.Language);

            if (!string.IsNullOrEmpty(currentValue))
            {
                // Deserializing the naming preference info on every CompilationStart is expensive.
                // Instead, the diagnostic engine should listen for option changes and have the
                // ability to create the new SerializableNamingStylePreferencesInfo when it detects
                // any change. The overall system would then only deserialize & allocate when
                // actually necessary.
                var viewModel       = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(currentValue));
                var preferencesInfo = viewModel.GetPreferencesInfo();
                context.RegisterSymbolAction(
                    symbolContext => SymbolAction(symbolContext, preferencesInfo),
                    _symbolKinds);
            }
        }
        public NamingStyleOptionPageViewModel(SerializableNamingStylePreferencesInfo info)
        {
            var viewModels = new List<NamingRuleViewModel>();
            foreach (var namingRule in info.NamingRules)
            {
                var viewModel = new NamingRuleViewModel();

                viewModel.NamingStyles = new ObservableCollection<NamingStyle>(info.NamingStyles);
                viewModel.Specifications = new ObservableCollection<SymbolSpecification>(info.SymbolSpecifications);
                viewModel.NotificationPreferences = new List<EnforcementLevel>(_notifications);

                viewModel.SelectedSpecification = viewModel.Specifications.Single(s => s.ID == namingRule.SymbolSpecificationID);
                viewModel.SelectedStyle= viewModel.NamingStyles.Single(s => s.ID == namingRule.NamingStyleID);
                viewModel.SelectedNotificationPreference = viewModel.NotificationPreferences.Single(n => n.Name == new EnforcementLevel(namingRule.EnforcementLevel).Name);
                
                viewModels.Add(viewModel);
            }

            CodeStyleItems = new ObservableCollection<NamingRuleViewModel>(viewModels);
            Specifications = new ObservableCollection<SymbolSpecification>(info.SymbolSpecifications);
            NamingStyles = new ObservableCollection<NamingStyle>(info.NamingStyles);

            SetMoveArrowStatuses();
        }
        internal static SerializableNamingStylePreferencesInfo FromXElement(XElement namingPreferencesInfoElement)
        {
            var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo();

            var serializationVersion = int.Parse(namingPreferencesInfoElement.Attribute("SerializationVersion").Value);
            if (serializationVersion != s_serializationVersion)
            {
                namingPreferencesInfoElement = XElement.Parse(SimplificationOptions.NamingPreferences.DefaultValue);
            }

            namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications)));
            namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles)));
            namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules)));

            return namingPreferencesInfo;
        }
        internal static SerializableNamingStylePreferencesInfo FromXElement(XElement namingPreferencesInfoElement)
        {
            var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo();

            namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications)));
            namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles)));
            namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules)));

            return namingPreferencesInfo;
        }
        internal override void SaveSettings()
        {
            var info = new SerializableNamingStylePreferencesInfo();

            foreach (var item in _viewModel.CodeStyleItems)
            {
                if (!item.IsComplete())
                {
                    continue;
                }

                var rule = new SerializableNamingRule()
                {
                    EnforcementLevel = item.SelectedNotificationPreference.Notification.Value,
                    NamingStyleID = item.SelectedStyle.ID,
                    SymbolSpecificationID = item.SelectedSpecification.ID
                };

                info.NamingRules.Add(rule);
            }

            foreach (var item in _viewModel.Specifications)
            {
                info.SymbolSpecifications.Add(item);
            }

            foreach (var item in _viewModel.NamingStyles)
            {
                info.NamingStyles.Add(item);
            }

            var oldOptions = OptionService.GetOptions();
            var newOptions = oldOptions.WithChangedOption(SimplificationOptions.NamingPreferences, _languageName, info.CreateXElement().ToString());
            OptionService.SetOptions(newOptions);
            OptionLogger.Log(oldOptions, newOptions);
        }
 public SerializableNamingStylePreferencesInfo GetInfo()
 {
     // TODO!
     var info = new SerializableNamingStylePreferencesInfo();
     info.SymbolSpecifications = SymbolSpecificationList.Select(s => s.GetSymbolSpecification()).ToList();
     info.NamingStyles = NamingStyleList.Select(s => s.GetNamingStyle()).ToList();
     info.NamingRules = CreateNamingRuleTree();
     return info;
 }
 private NamingRuleTreeItemViewModel CreateRoot(SerializableNamingStylePreferencesInfo info)
 {
     var root = new NamingRuleTreeItemViewModel("Naming Rules:");
     CreateRootHelper(root, info.NamingRules);
     return root;
 }
        internal override void LoadSettings()
        {
            base.LoadSettings();

            var namingPreferencesXml = this.OptionService.GetOption(SimplificationOptions.NamingPreferences, _languageName);

            SerializableNamingStylePreferencesInfo preferencesInfo;
            if (string.IsNullOrEmpty(namingPreferencesXml))
            {
                preferencesInfo = new SerializableNamingStylePreferencesInfo();
            }
            else
            {
                preferencesInfo = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(namingPreferencesXml));
            }

            _viewModel = new NamingStylesOptionPageControlViewModel(preferencesInfo, _languageName, _categories, _notificationService);
            this.DataContext = _viewModel;

            this.RootTreeView.ItemsPath = nameof(NamingRuleTreeItemViewModel.Children);
            this.RootTreeView.IsExpandablePath = nameof(NamingRuleTreeItemViewModel.HasChildren);
            this.RootTreeView.FilterParentEvaluator = GetParent;
            this.RootTreeView.RootItemsSource = new ObservableCollection<NamingRuleTreeItemViewModel>() { _viewModel.rootNamingRule };
        }