Exemple #1
0
        public static ClangTidyOptionsView GetClangTidyOptionViewFromFile()
        {
            ClangTidyOptionsView clangTidyOptionsView = new ClangTidyOptionsView();

            clangTidyOptionsView.LoadSettingsFromStorage();
            return(clangTidyOptionsView);
        }
Exemple #2
0
        private string GetTidyParameters(ClangTidyOptionsView aTidyOptions, ClangTidyPredefinedChecksOptionsView aTidyChecks, ClangTidyCustomChecksOptionsView aTidyCustomChecks)
        {
            string parameters = string.Empty;

            if (0 == string.Compare(ComboBoxConstants.kTidyFile, ClangTidyUseChecksFromConvertor.ToString(aTidyOptions.UseChecksFrom)))
            {
                parameters   = ScriptConstants.kTidyFile;
                mUseTidyFile = true;
            }
            else if (0 == string.Compare(ComboBoxConstants.kCustomChecks, ClangTidyUseChecksFromConvertor.ToString(aTidyOptions.UseChecksFrom)))
            {
                if (false == string.IsNullOrWhiteSpace(aTidyCustomChecks.TidyChecks))
                {
                    parameters = $",{aTidyCustomChecks.TidyChecks.Replace(';', ',')}";
                }
            }
            else if (0 == string.Compare(ComboBoxConstants.kPredefinedChecks, ClangTidyUseChecksFromConvertor.ToString(aTidyOptions.UseChecksFrom)))
            {
                foreach (PropertyInfo prop in aTidyChecks.GetType().GetProperties())
                {
                    object[] propAttrs          = prop.GetCustomAttributes(false);
                    object   clangCheckAttr     = propAttrs.FirstOrDefault(attr => typeof(ClangCheckAttribute) == attr.GetType());
                    object   displayNameAttrObj = propAttrs.FirstOrDefault(attr => typeof(DisplayNameAttribute) == attr.GetType());

                    if (null == clangCheckAttr || null == displayNameAttrObj)
                    {
                        continue;
                    }

                    DisplayNameAttribute displayNameAttr = (DisplayNameAttribute)displayNameAttrObj;
                    var value = prop.GetValue(aTidyChecks, null);
                    if (Boolean.TrueString != value.ToString())
                    {
                        continue;
                    }
                    parameters = $"{parameters},{displayNameAttr.DisplayName}";
                }
            }

            if (string.Empty != parameters)
            {
                parameters = string.Format("{0} ''{1}{2}''",
                                           (true == aTidyOptions.Fix ? ScriptConstants.kTidyFix : ScriptConstants.kTidy),
                                           (mUseTidyFile ? "" : "-*"),
                                           parameters);
            }

            if (null != aTidyOptions.HeaderFilter && false == string.IsNullOrWhiteSpace(aTidyOptions.HeaderFilter.HeaderFilters))
            {
                parameters = string.Format("{0} {1} ''{2}''",
                                           parameters, ScriptConstants.kHeaderFilter,
                                           true == string.IsNullOrWhiteSpace(ClangTidyHeaderFiltersConvertor.ScriptEncode(aTidyOptions.HeaderFilter.HeaderFilters)) ?
                                           aTidyOptions.HeaderFilter.HeaderFilters : ClangTidyHeaderFiltersConvertor.ScriptEncode(aTidyOptions.HeaderFilter.HeaderFilters));
            }

            return(parameters);
        }
Exemple #3
0
        public async Task ClangTidyOptionsView_NotNullAsync()
        {
            //Arrange
            await UnitTestUtility.LoadPackageAsync();

            //Act
            ClangTidyOptionsView tidySettings = SettingsProvider.TidySettings;

            //Assert
            Assert.NotNull(tidySettings);
        }
Exemple #4
0
        public ClangTidyOptionsUserControl(ClangTidyOptionsView clangTidyOptions)
        {
            InitializeComponent();

            wpfPropGrid.SelectedObject = clangTidyOptions;

            Loaded += delegate
            {
                UIElementsActivator.Activate(HwndSource.FromVisual(this) as HwndSource);
            };
        }
Exemple #5
0
 /// <summary>
 /// Instance constructor
 /// </summary>
 public GenericScriptBuilder(ClangGeneralOptionsView aGeneralOptions, ClangTidyOptionsView aTidyOptions, ClangTidyPredefinedChecksOptionsView aTidyChecks,
                             ClangTidyCustomChecksOptionsView aTidyCustomChecks, ClangFormatOptionsView aClangFormatView, string aVsEdition, string aVsVersion, bool aTidyFixFlag = false)
 {
     mGeneralOptions         = aGeneralOptions;
     mTidyOptions            = aTidyOptions;
     mTidyChecks             = aTidyChecks;
     mTidyCustomChecks       = aTidyCustomChecks;
     mClangFormatView        = aClangFormatView;
     mVsEdition              = aVsEdition;
     mVsVersion              = aVsVersion;
     mTidyFixFlag            = aTidyFixFlag;
     mUseClangTidyConfigFile = false;
 }
Exemple #6
0
        public async Task ChecksFrom_ChangeValue_CompareViewToFileAsync()
        {
            await UnitTestUtility.LoadPackageAsync();

            SettingsTestUtility.ResetClangTidyOptionsView();
            ClangTidyOptionsView tidySettings = SettingsProvider.TidySettings;

            tidySettings.UseChecksFrom = ClangTidyUseChecksFrom.TidyFile;
            SettingsTestUtility.SaveTidyOptions(tidySettings);
            ClangTidyOptionsView clangTidySettingsFromFile = SettingsTestUtility.GetClangTidyOptionViewFromFile();

            Assert.Equal(tidySettings.UseChecksFrom, clangTidySettingsFromFile.UseChecksFrom);
        }
Exemple #7
0
        public async Task HeaderFilter_ChangeValue_CompareViewToFileAsync()
        {
            await UnitTestUtility.LoadPackageAsync();

            SettingsTestUtility.ResetClangTidyOptionsView();
            ClangTidyOptionsView tidySettings = SettingsProvider.TidySettings;

            tidySettings.HeaderFilter.HeaderFilters = "test";
            SettingsTestUtility.SaveTidyOptions(tidySettings);
            ClangTidyOptionsView clangTidySettingsFromFile = SettingsTestUtility.GetClangTidyOptionViewFromFile();

            Assert.Equal(tidySettings.HeaderFilter.HeaderFilters, clangTidySettingsFromFile.HeaderFilter.HeaderFilters);
        }
Exemple #8
0
        public async Task ClangTidyOnSave_ChangeValue_CompareViewToFileAsync()
        {
            await UnitTestUtility.LoadPackageAsync();

            SettingsTestUtility.ResetClangTidyOptionsView();
            ClangTidyOptionsView tidySettings = SettingsProvider.TidySettings;

            tidySettings.AutoTidyOnSave = true;
            SettingsTestUtility.SaveTidyOptions(tidySettings);
            ClangTidyOptionsView clangTidySettingsFromFile = SettingsTestUtility.GetClangTidyOptionViewFromFile();

            Assert.Equal(tidySettings.AutoTidyOnSave, clangTidySettingsFromFile.AutoTidyOnSave);
        }
Exemple #9
0
        public void ConstructParameters(ClangGeneralOptionsView aGeneralOptions, ClangTidyOptionsView aTidyOptions, ClangTidyChecksOptionsView aTidyChecks,
                                        ClangTidyCustomChecksOptionsView aTidyCustomChecks, ClangFormatOptionsView aClangFormatView, DTE2 aDTEObj, string aVsEdition, string aVsVersion)
        {
            mParameters = GetGeneralParameters(aGeneralOptions);
            mParameters = null != aTidyOptions ?
                          $"{mParameters} {GetTidyParameters(aTidyOptions, aTidyChecks, aTidyCustomChecks)}" : $"{mParameters} {ScriptConstants.kParallel}";

            if (null != aClangFormatView && null != aTidyOptions && true == aTidyOptions.Fix && true == aTidyOptions.FormatAfterTidy)
            {
                mParameters = $"{mParameters} {ScriptConstants.kClangFormatStyle} {GetClangFormatParameters(aClangFormatView)}";
            }

            mParameters = $"{mParameters} {ScriptConstants.kVsVersion} {aVsVersion} {ScriptConstants.kVsEdition} {aVsEdition}";
        }
Exemple #10
0
        public async Task CustomExecutable_ChangeValue_CompareViewToFileAsync()
        {
            await UnitTestUtility.LoadPackageAsync();

            SettingsTestUtility.ResetClangTidyOptionsView();
            ClangTidyOptionsView tidySettings = SettingsProvider.TidySettings;

            tidySettings.ClangTidyPath.Enable = true;
            tidySettings.ClangTidyPath.Value  = @"D:\Test.exe";
            SettingsTestUtility.SaveTidyOptions(tidySettings);
            ClangTidyOptionsView clangTidySettingsFromFile = SettingsTestUtility.GetClangTidyOptionViewFromFile();

            Assert.Equal(tidySettings.ClangTidyPath.Enable, clangTidySettingsFromFile.ClangTidyPath.Enable);
            Assert.Equal(tidySettings.ClangTidyPath.Value, clangTidySettingsFromFile.ClangTidyPath.Value);
        }
Exemple #11
0
 public static void SaveTidyOptions(ClangTidyOptionsView clangTidyOptionsView)
 {
     clangTidyOptionsView.SaveSettingsToStorage();
 }