From d8de6b39270f3d06009849dc29a74162f89c0970 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 5 May 2010 17:15:43 +0000 Subject: [PATCH] Fixed NullReferenceException in CodeCompletionItem.Complete. Simplify some code. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5761 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Controls/CallTreeNodeViewModel.cs | 35 +++++++++---------- .../Src/Visitors/ToVBNetConvertVisitor.cs | 4 --- .../CodeCompletionItemProvider.cs | 29 +++------------ .../ProjectContent/DefaultProjectContent.cs | 7 ++-- 4 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs b/src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs index c721801579..ed5f7e1581 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs +++ b/src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs @@ -223,42 +223,41 @@ namespace ICSharpCode.Profiler.Controls public virtual string FullyQualifiedClassName { get { - if (string.IsNullOrEmpty(this.node.Name)) + string nodeName = this.node.Name; + if (string.IsNullOrEmpty(nodeName)) return null; - if (!this.node.Name.Contains(".")) + if (!nodeName.Contains(".")) return null; - int index = this.node.Name.LastIndexOf('.'); - if (this.node.Name[index - 1] == '.') + int index = nodeName.LastIndexOf('.'); + if (nodeName[index - 1] == '.') index--; - return this.node.Name.Substring(0, index); + return nodeName.Substring(0, index); } } public virtual string MethodName { get { - if (string.IsNullOrEmpty(this.node.Name)) + string nodeName = this.node.Name; + if (string.IsNullOrEmpty(nodeName)) return null; - if (!this.node.Name.Contains(".")) + if (!nodeName.Contains(".")) return null; - int index = this.node.Name.LastIndexOf('.'); - if (this.node.Name[index - 1] == '.') + int index = nodeName.LastIndexOf('.'); + if (nodeName[index - 1] == '.') index--; - return this.node.Name.Substring(index + 1); + return nodeName.Substring(index + 1); } } public virtual string ShortName { get { - if (string.IsNullOrEmpty(this.node.Name)) - return null; - if (!this.node.Name.Contains(".")) - return Name; - int index = FullyQualifiedClassName.LastIndexOf('.'); - if (FullyQualifiedClassName[index - 1] == '.') - index--; - return FullyQualifiedClassName.Substring(index + 1) + "." + MethodName; + string className = this.FullyQualifiedClassName; + if (className == null) + return this.Name; + int index = className.LastIndexOf('.'); + return className.Substring(index + 1) + "." + MethodName; } } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs index d241eaa66d..026fe50c11 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs @@ -309,10 +309,6 @@ namespace ICSharpCode.NRefactory.Visitors { if (!IsClassType(ClassType.Interface) && (propertyDeclaration.Modifier & Modifiers.Visibility) == 0) propertyDeclaration.Modifier |= Modifiers.Private; - - if (propertyDeclaration.IsIndexer) - propertyDeclaration.Modifier |= Modifiers.Default; - base.VisitPropertyDeclaration(propertyDeclaration, data); ToVBNetRenameConflictingVariablesVisitor.RenameConflicting(propertyDeclaration); diff --git a/src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs b/src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs index fb473f9d74..5108610f1c 100644 --- a/src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs +++ b/src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs @@ -267,9 +267,8 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion var fullNameResult = ParserService.Resolve(new ExpressionResult(selectedClass.FullyQualifiedName), position.Line, position.Column, editor.FileName, document.Text); bool addUsing = false; - var cu = nameResult.CallingClass.CompilationUnit; - if (IsKnown(nameResult)) { - if (IsEqualClass(nameResult, selectedClass)) { + if (nameResult != null && nameResult.IsValid) { + if (nameResult.IsReferenceTo(selectedClass)) { // Selected name is known in the current context - do nothing } else { // Selected name is known in the current context but resolves to something else than the user wants to insert @@ -286,8 +285,9 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion context.Editor.Document.Replace(context.StartOffset, context.Length, insertedText); context.EndOffset = context.StartOffset + insertedText.Length; - if (addUsing) { - NamespaceRefactoringService.AddUsingDeclaration(cu, document, selectedClass.Namespace, true); + if (addUsing && nameResult != null && nameResult.CallingClass != null) { + var cu = nameResult.CallingClass.CompilationUnit; + NamespaceRefactoringService.AddUsingDeclaration(cu, document, selectedClass.Namespace, false); ParserService.BeginParse(context.Editor.FileName, context.Editor.Document); } } else { @@ -297,25 +297,6 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion } } - /// - /// Returns false if is or something similar. - /// - bool IsKnown(ResolveResult result) - { - return !(result is UnknownIdentifierResolveResult || result is UnknownConstructorCallResolveResult); - } - - /// - /// Returns true if both parameters refer to the same class. - /// - bool IsEqualClass(ResolveResult nameResult, IClass selectedClass) - { - var classResult = nameResult as TypeResolveResult; - if (classResult == null) - return false; - return classResult.ResolvedClass.FullyQualifiedName == selectedClass.FullyQualifiedName; - } - #region Description string description; bool descriptionCreated; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs index 1f9b8938c7..691862fff5 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs @@ -267,6 +267,8 @@ namespace ICSharpCode.SharpDevelop.Dom /// /// Container class that is used when multiple classes with different type parameter /// count have the same class name. + /// + /// The GenericClassContainer is only used internally to hold the class list, it is never returned by any public API. /// private sealed class GenericClassContainer : DefaultClass { @@ -332,11 +334,6 @@ namespace ICSharpCode.SharpDevelop.Dom } } - static bool IsEqualFileName(string fileName1, string fileName2) - { - return ICSharpCode.Core.FileUtility.IsEqualFileName(fileName1, fileName2); - } - protected void AddClassToNamespaceListInternal(IClass addClass) { // Freeze the class when adding it to the project content