Browse Source

Prevent infinite recursion when running "Find Derived Classes" on a class in an inheritance cycle.

Fixed "Find Derived Classes" on generic class when there was a non-generic class with the same name.
FontSelectionPanel, OutputWindowOptionsPanel: fixed NullReferenceException when closing the options dialog before the font list was loaded.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2986 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
1546cab7d0
  1. 6
      src/Main/Base/Project/Src/Gui/Components/FontSelectionPanel.cs
  2. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/OutputWindowOptionsPanel.cs
  3. 31
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs
  4. 4
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs
  5. 5
      src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs

6
src/Main/Base/Project/Src/Gui/Components/FontSelectionPanel.cs

@ -24,7 +24,11 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
public string CurrentFontString { public string CurrentFontString {
get { get {
return CurrentFont.ToString(); Font font = CurrentFont;
if (font != null)
return font.ToString();
else
return null;
} }
set { set {
CurrentFont = FontSelectionPanel.ParseFont(value); CurrentFont = FontSelectionPanel.ParseFont(value);

4
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/OutputWindowOptionsPanel.cs

@ -40,7 +40,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{ {
Properties properties = (Properties)PropertyService.Get(OutputWindowsProperty, new Properties()); Properties properties = (Properties)PropertyService.Get(OutputWindowsProperty, new Properties());
properties.Set("WordWrap", ((CheckBox)ControlDictionary["wordWrapCheckBox"]).Checked); properties.Set("WordWrap", ((CheckBox)ControlDictionary["wordWrapCheckBox"]).Checked);
properties.Set("DefaultFont", fontSelectionPanel.CurrentFontString); string currentFontString = fontSelectionPanel.CurrentFontString;
if (currentFontString != null)
properties.Set("DefaultFont", currentFontString);
PropertyService.Set(OutputWindowsProperty, properties); PropertyService.Set(OutputWindowsProperty, properties);
return true; return true;

31
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Linq;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
@ -27,11 +28,19 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <param name="baseClass">The base class.</param> /// <param name="baseClass">The base class.</param>
/// <param name="projectContents">The project contents in which derived classes should be searched.</param> /// <param name="projectContents">The project contents in which derived classes should be searched.</param>
/// <param name="directDerivationOnly">If true, gets only the classes that derive directly from <paramref name="baseClass"/>.</param> /// <param name="directDerivationOnly">If true, gets only the classes that derive directly from <paramref name="baseClass"/>.</param>
public static List<IClass> FindDerivedClasses(IClass baseClass, IEnumerable<IProjectContent> projectContents, bool directDerivationOnly) public static IEnumerable<IClass> FindDerivedClasses(IClass baseClass, IEnumerable<IProjectContent> projectContents, bool directDerivationOnly)
{
HashSet<IClass> resultList = new HashSet<IClass>();
FindDerivedClasses(resultList, baseClass, projectContents, directDerivationOnly);
return resultList.OrderBy(c => c.FullyQualifiedName);
}
static void FindDerivedClasses(HashSet<IClass> resultList, IClass baseClass, IEnumerable<IProjectContent> projectContents, bool directDerivationOnly)
{ {
baseClass = baseClass.GetCompoundClass(); baseClass = baseClass.GetCompoundClass();
string baseClassName = baseClass.Name; string baseClassName = baseClass.Name;
string baseClassFullName = baseClass.FullyQualifiedName; string baseClassFullName = baseClass.FullyQualifiedName;
LoggingService.Debug("FindDerivedClasses for " + baseClassFullName);
List<IClass> list = new List<IClass>(); List<IClass> list = new List<IClass>();
foreach (IProjectContent pc in projectContents) { foreach (IProjectContent pc in projectContents) {
if (pc != baseClass.ProjectContent && !pc.ReferencedContents.Contains(baseClass.ProjectContent)) { if (pc != baseClass.ProjectContent && !pc.ReferencedContents.Contains(baseClass.ProjectContent)) {
@ -41,17 +50,15 @@ namespace ICSharpCode.SharpDevelop.Refactoring
} }
AddDerivedClasses(pc, baseClass, baseClassName, baseClassFullName, pc.Classes, list); AddDerivedClasses(pc, baseClass, baseClassName, baseClassFullName, pc.Classes, list);
} }
if (!directDerivationOnly) { if (directDerivationOnly) {
List<IClass> additional = new List<IClass>(); resultList.AddRange(list);
} else {
foreach (IClass c in list) { foreach (IClass c in list) {
additional.AddRange(FindDerivedClasses(c, projectContents, directDerivationOnly)); if (resultList.Add(c)) {
} FindDerivedClasses(resultList, c, projectContents, directDerivationOnly);
foreach (IClass c in additional) { }
if (!list.Contains(c))
list.Add(c);
} }
} }
return list;
} }
static void AddDerivedClasses(IProjectContent pc, IClass baseClass, string baseClassName, string baseClassFullName, static void AddDerivedClasses(IProjectContent pc, IClass baseClass, string baseClassName, string baseClassFullName,
@ -65,7 +72,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (pc.Language.NameComparer.Equals(baseTypeName, baseClassName) || if (pc.Language.NameComparer.Equals(baseTypeName, baseClassName) ||
pc.Language.NameComparer.Equals(baseTypeName, baseClassFullName)) { pc.Language.NameComparer.Equals(baseTypeName, baseClassFullName)) {
IReturnType possibleBaseClass = c.GetBaseType(i); IReturnType possibleBaseClass = c.GetBaseType(i);
if (possibleBaseClass.FullyQualifiedName == baseClass.FullyQualifiedName) { if (possibleBaseClass.FullyQualifiedName == baseClass.FullyQualifiedName
&& possibleBaseClass.TypeArgumentCount == baseClass.TypeParameters.Count)
{
resultList.Add(c); resultList.Add(c);
} }
} }
@ -425,5 +434,3 @@ namespace ICSharpCode.SharpDevelop.Refactoring
#endregion #endregion
} }
} }

4
src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

@ -344,14 +344,14 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{ {
MenuCommand item = (MenuCommand)sender; MenuCommand item = (MenuCommand)sender;
IClass c = (IClass)item.Tag; IClass c = (IClass)item.Tag;
List<IClass> derivedClasses = RefactoringService.FindDerivedClasses(c, ParserService.AllProjectContents, false); IEnumerable<IClass> derivedClasses = RefactoringService.FindDerivedClasses(c, ParserService.AllProjectContents, false);
List<SearchResultMatch> results = new List<SearchResultMatch>(); List<SearchResultMatch> results = new List<SearchResultMatch>();
foreach (IClass derivedClass in derivedClasses) { foreach (IClass derivedClass in derivedClasses) {
if (derivedClass.CompilationUnit == null) continue; if (derivedClass.CompilationUnit == null) continue;
if (derivedClass.CompilationUnit.FileName == null) continue; if (derivedClass.CompilationUnit.FileName == null) continue;
SearchResultMatch res = new SimpleSearchResultMatch(derivedClass.FullyQualifiedName, new TextLocation(derivedClass.Region.BeginColumn - 1, derivedClass.Region.BeginLine - 1)); SearchResultMatch res = new SimpleSearchResultMatch(ClassNode.GetText(derivedClass), new TextLocation(derivedClass.Region.BeginColumn - 1, derivedClass.Region.BeginLine - 1));
res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(derivedClass.CompilationUnit.FileName); res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(derivedClass.CompilationUnit.FileName);
results.Add(res); results.Add(res);
} }

5
src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
@ -176,14 +177,14 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{ {
MenuCommand item = (MenuCommand)sender; MenuCommand item = (MenuCommand)sender;
IMember member = (IMember)item.Tag; IMember member = (IMember)item.Tag;
List<IClass> derivedClasses = RefactoringService.FindDerivedClasses(member.DeclaringType, ParserService.AllProjectContents, false); IEnumerable<IClass> derivedClasses = RefactoringService.FindDerivedClasses(member.DeclaringType, ParserService.AllProjectContents, false);
List<SearchResultMatch> results = new List<SearchResultMatch>(); List<SearchResultMatch> results = new List<SearchResultMatch>();
foreach (IClass derivedClass in derivedClasses) { foreach (IClass derivedClass in derivedClasses) {
if (derivedClass.CompilationUnit == null) continue; if (derivedClass.CompilationUnit == null) continue;
if (derivedClass.CompilationUnit.FileName == null) continue; if (derivedClass.CompilationUnit.FileName == null) continue;
IMember m = MemberLookupHelper.FindSimilarMember(derivedClass, member); IMember m = MemberLookupHelper.FindSimilarMember(derivedClass, member);
if (m != null && !m.Region.IsEmpty) { if (m != null && !m.Region.IsEmpty) {
SearchResultMatch res = new SimpleSearchResultMatch(m.FullyQualifiedName, new TextLocation(m.Region.BeginColumn - 1, m.Region.BeginLine - 1)); SearchResultMatch res = new SimpleSearchResultMatch(MemberNode.GetText(m), new TextLocation(m.Region.BeginColumn - 1, m.Region.BeginLine - 1));
res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(derivedClass.CompilationUnit.FileName); res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(derivedClass.CompilationUnit.FileName);
results.Add(res); results.Add(res);
} }

Loading…
Cancel
Save