Browse Source

Fixed possible null reference exception.

newNRvisualizers
mike 14 years ago
parent
commit
54b3baee81
  1. 42
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

42
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -415,9 +415,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
wrapper.Append (';'); wrapper.Append (';');
} }
protected CompilationUnit ParseStub(string continuation, bool appendSemicolon = true, string afterContinuation = null) protected CompilationUnit ParseStub (string continuation, bool appendSemicolon = true, string afterContinuation = null)
{ {
var mt = GetMemberTextToCaret(); var mt = GetMemberTextToCaret ();
if (mt == null) { if (mt == null) {
return null; return null;
} }
@ -429,33 +429,35 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var wrapper = new StringBuilder (); var wrapper = new StringBuilder ();
bool wrapInClass = memberLocation != new TextLocation (1, 1); bool wrapInClass = memberLocation != new TextLocation (1, 1);
if (wrapInClass) { if (wrapInClass) {
var nodeAtLocation = Unit.GetNodeAt(memberLocation, n => n is TypeDeclaration || n is NamespaceDeclaration); var nodeAtLocation = Unit.GetNodeAt (memberLocation, n => n is TypeDeclaration || n is NamespaceDeclaration);
foreach (var n in nodeAtLocation.AncestorsAndSelf) { if (nodeAtLocation != null) {
if (memberLocation == n.StartLocation) { foreach (var n in nodeAtLocation.AncestorsAndSelf) {
continue; if (memberLocation == n.StartLocation) {
} continue;
if (n is TypeDeclaration) { }
var t = (TypeDeclaration)n; if (n is TypeDeclaration) {
switch (t.ClassType) { var t = (TypeDeclaration)n;
switch (t.ClassType) {
case ClassType.Class: case ClassType.Class:
wrapper.Append("class"); wrapper.Append ("class");
break; break;
case ClassType.Struct: case ClassType.Struct:
wrapper.Append("struct"); wrapper.Append ("struct");
break; break;
case ClassType.Interface: case ClassType.Interface:
wrapper.Append("interface"); wrapper.Append ("interface");
break; break;
case ClassType.Enum: case ClassType.Enum:
wrapper.Append("enum"); wrapper.Append ("enum");
break; break;
}
wrapper.Append (" " + t.Name + " {");
wrapper.AppendLine ();
closingBrackets++;
generatedLines++;
} else {
Console.WriteLine (n);
} }
wrapper.Append(" " + t.Name + " {");
wrapper.AppendLine();
closingBrackets++;
generatedLines++;
} else {
Console.WriteLine(n);
} }
} }
} }

Loading…
Cancel
Save