Browse Source

Fixed NullReferenceException in CodeCompletionItem.Complete.

Simplify some code.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5761 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
d8de6b3927
  1. 35
      src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  3. 29
      src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs
  4. 7
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

35
src/AddIns/Misc/Profiler/Frontend/Controls/CallTreeNodeViewModel.cs

@ -223,42 +223,41 @@ namespace ICSharpCode.Profiler.Controls @@ -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;
}
}

4
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -309,10 +309,6 @@ namespace ICSharpCode.NRefactory.Visitors @@ -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);

29
src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs

@ -267,9 +267,8 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -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 @@ -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 @@ -297,25 +297,6 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
}
}
/// <summary>
/// Returns false if <paramref name="result" /> is <see cref="UnknownIdentifierResolveResult" /> or something similar.
/// </summary>
bool IsKnown(ResolveResult result)
{
return !(result is UnknownIdentifierResolveResult || result is UnknownConstructorCallResolveResult);
}
/// <summary>
/// Returns true if both parameters refer to the same class.
/// </summary>
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;

7
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -267,6 +267,8 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -267,6 +267,8 @@ namespace ICSharpCode.SharpDevelop.Dom
/// <summary>
/// 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.
/// </summary>
private sealed class GenericClassContainer : DefaultClass
{
@ -332,11 +334,6 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -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

Loading…
Cancel
Save