/// <summary> /// Export all features for documentation /// </summary> private void ExportFeaturesForDocumentation() { MessageBox.ShowInfo("latest"); var brwsr = new FolderBrowserDialog() { Description = "Choose where to save the ResharperFeatures.xml file." }; if (brwsr.ShowDialog() == DialogResult.Cancel) { return; } string saveDirectoryPath = brwsr.SelectedPath; string fileName = Path.Combine(saveDirectoryPath, "ResharperFeatures.xml"); var xDoc = new XDocument(); var xDocRoot = new XElement("Features"); // var productVersion = new ReSharperApplicationDescriptor().ProductVersion; // version = String.Format("{0}.{1}", productVersion.Major, productVersion.Minor); this.version = "9.0"; this.myTestAssemblies = new List <Assembly>(); foreach (var testAssemblyName in this.myTestAssemblyNames) { var testAssembly = Assembly.Load(testAssemblyName); this.myTestAssemblies.Add(testAssembly); } var cache = this.GetTestsForFeatures(); // Context actions int cAnumber = 0; // var contextActionTable = Shell.Instance.GetComponent<ContextActionTable>(); // foreach (var ca in contextActionTable.AllActions) // { // AddFeature(xDocRoot, ca.MergeKey.Split('.').Last(), ca.Type, // "ContextAction", version, ca.Name, ca.Description, String.Empty, cache, null); // cAnumber++; // } // Quick fixes and Inspections int qFnumber = 0; int insTypeNumber = 0; var quickFixTable = Shell.Instance.GetComponent <QuickFixTable>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { Type[] types = null; try { types = assembly.GetTypes(); } catch (Exception e) { MessageBox.ShowError("Cannot load assembly!!!!" + e.ToString()); continue; } if (types == null) { continue; } foreach (var type in types) { string name = "Unknown"; string description = "Unknown"; string lang = String.Empty; var attrs = Attribute.GetCustomAttributes(type); // Quick fixes if (typeof(IQuickFix).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { // foreach (var attr in attrs) // { // if (attr is FeatureDescAttribute) // { // var a = (FeatureDescAttribute)attr; // name = a.Title; // description = a.Description; // } // } this.AddFeature(xDocRoot, type.Name, type, "QuickFix", this.version, name, description, lang, cache, null); qFnumber++; } // Inspections if (typeof(IHighlighting).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { string id = string.Empty; string severity = string.Empty; string group = string.Empty; string solutionWide = string.Empty; string allQuickFixes = string.Empty; string configurable = string.Empty; string compoundName = string.Empty; /// TODO: Make GetHighlightingQuickFixesInfo public // var quickFixes = quickFixTable.GetHighlightingQuickFixesInfo(type); // foreach (var quickFix in quickFixes) // allQuickFixes += quickFix.QuickFixType.Name + ","; if (!string.IsNullOrEmpty(allQuickFixes)) { allQuickFixes = allQuickFixes.TrimEnd(','); } foreach (var attr in attrs) { if (attr is ConfigurableSeverityHighlightingAttribute) { var a = (ConfigurableSeverityHighlightingAttribute)attr; id = a.ConfigurableSeverityId; var inpectionInstance = HighlightingSettingsManager.Instance.GetSeverityItem(id); lang = this.GetLangsForInspection(id); if (inpectionInstance != null) { name = inpectionInstance.FullTitle; description = inpectionInstance.HTMLDescriptionBody; severity = inpectionInstance.DefaultSeverity.ToString(); solutionWide = inpectionInstance.SolutionAnalysisRequired ? "yes" : "no"; group = inpectionInstance.GroupId; compoundName = inpectionInstance.CompoundItemName; configurable = "yes"; break; } } if (attr is StaticSeverityHighlightingAttribute) { id = type.Name; var a = (StaticSeverityHighlightingAttribute)attr; name = a.ToolTipFormatString; group = a.GroupId; severity = a.Severity.ToString(); solutionWide = "no"; configurable = "no"; } } if (name != "Unknown") { var details = new XElement("Details", new XAttribute("DefaultSeverity", severity), new XAttribute("Group", group), new XAttribute("SolutionWide", solutionWide), new XAttribute("Configurable", configurable), new XAttribute("CompoundName", compoundName ?? ""), new XAttribute("QuickFixes", allQuickFixes) ); if (string.IsNullOrEmpty(name) && description == "Unknown") { name = RsDocExportFeatures.SplitCamelCase(type.Name); } if (string.IsNullOrEmpty(name)) { name = description; } this.AddFeature(xDocRoot, id, type, "Inspection", this.version, name, description, lang, cache, details); insTypeNumber++; } } } } xDocRoot.Add(new XAttribute("TotalContextActions", cAnumber), new XAttribute("TotalQuickFixes", qFnumber), new XAttribute("TotalInspections", insTypeNumber)); foreach (var ins in HighlightingSettingsManager.Instance.SeverityConfigurations) { var inspection = (from nodes in xDocRoot.Elements() let xAttribute = nodes.Attribute("Id") where xAttribute != null && xAttribute.Value == ins.Id select nodes).FirstOrDefault(); if (inspection == null) { var details = new XElement("Details", new XAttribute("DefaultSeverity", ins.DefaultSeverity), new XAttribute("Group", ins.GroupId), new XAttribute("SolutionWide", ins.SolutionAnalysisRequired ? "yes" : "no"), new XAttribute("Configurable", "yes"), new XAttribute("CompoundName", ins.CompoundItemName ?? ""), new XAttribute("QuickFixes", "") ); this.AddFeature(xDocRoot, ins.Id, ins.GetType(), "Inspection", this.version, ins.FullTitle, ins.HTMLDescriptionBody, this.GetLangsForInspection(ins.Id), null, details); } insTypeNumber++; } xDoc.Add(xDocRoot); this.SynchronizeWithStaticDesciription(xDoc); xDoc.Save(fileName); MessageBox.ShowInfo("ReSharper features exported successfully."); }
/// <summary> /// Builds a dictionary (feature type, test object) /// </summary> /// <returns></returns> private List <KeyValuePair <Type, Object> > GetTestsForFeatures() { var cache = new List <KeyValuePair <Type, Object> >(); foreach (var assembly in this.myTestAssemblies) { foreach (var testType in assembly.GetTypes()) { if (testType.IsAbstract || testType.IsInterface || testType.Name.Contains("Availability")) { continue; } var matchFound = false; var ignore = false; foreach (var attribute in testType.GetCustomAttributes(false)) { if (attribute.GetType().Name == "IgnoreAttribute") { ignore = true; } } if (ignore) { continue; } foreach (Type genericTypeArgument in testType.BaseType.GetGenericArguments()) { if (genericTypeArgument != null && !testType.ContainsGenericParameters) { cache.Add(new KeyValuePair <Type, Object>(genericTypeArgument, Activator.CreateInstance(testType))); matchFound = true; } } var methods = testType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); foreach (var methodInfo in methods) { if (methodInfo.Name == "CreateContextAction") { if (methodInfo.GetParameters().Length == 1) { var parametersArray = new object[] { null }; var testTypeInstance = Activator.CreateInstance(testType); try { object result = methodInfo.Invoke(testTypeInstance, parametersArray); cache.Add(new KeyValuePair <Type, Object>(result.GetType(), testTypeInstance)); } catch (Exception e) { MessageBox.ShowError(e.ToString()); } matchFound = true; } } } if (!matchFound && testType.Name.EndsWith("Test")) { this.myUnmatchedTests.Add(testType); } } } return(cache); }