Browse Source

NRefactory: Fixed incorrect end column in C# type declarations.

Fixes forum-9578: IndexOutOfRangeException in 'Implement Interface' refactoring.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4455 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
6ace8895af
  1. 10
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 10
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  3. 2
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs
  4. 1
      src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs
  5. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CSharpCodeGenerator.cs

10
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -765,7 +765,7 @@ templates);
} }
#line 390 "cs.ATG" #line 390 "cs.ATG"
newType.EndLocation = t.Location; newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
} else if (StartOf(9)) { } else if (StartOf(9)) {
@ -814,7 +814,7 @@ templates);
} }
#line 414 "cs.ATG" #line 414 "cs.ATG"
newType.EndLocation = t.Location; newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
} else if (la.kind == 83) { } else if (la.kind == 83) {
@ -859,7 +859,7 @@ templates);
} }
#line 437 "cs.ATG" #line 437 "cs.ATG"
newType.EndLocation = t.Location; newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
} else if (la.kind == 68) { } else if (la.kind == 68) {
@ -894,7 +894,7 @@ out name);
} }
#line 452 "cs.ATG" #line 452 "cs.ATG"
newType.EndLocation = t.Location; newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
} else { } else {
@ -947,7 +947,7 @@ templates);
Expect(11); Expect(11);
#line 474 "cs.ATG" #line 474 "cs.ATG"
delegateDeclr.EndLocation = t.Location; delegateDeclr.EndLocation = t.EndLocation;
compilationUnit.AddChild(delegateDeclr); compilationUnit.AddChild(delegateDeclr);
} }

10
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -387,7 +387,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
"{" "{"
ClassBody ClassBody
"}" "}"
[ ";" ] (. newType.EndLocation = t.Location; [ ";" ] (. newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
.) .)
| /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .) | /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .)
@ -411,7 +411,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
(. newType.BodyStartLocation = t.EndLocation; .) (. newType.BodyStartLocation = t.EndLocation; .)
StructBody StructBody
[ ";" ] (. newType.EndLocation = t.Location; [ ";" ] (. newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
.) .)
| /*--- interface declaration: */ | /*--- interface declaration: */
@ -434,7 +434,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
(. newType.BodyStartLocation = t.EndLocation; .) (. newType.BodyStartLocation = t.EndLocation; .)
InterfaceBody InterfaceBody
[ ";" ] (. newType.EndLocation = t.Location; [ ";" ] (. newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
.) .)
| /*--- enumeration declaration: */ | /*--- enumeration declaration: */
@ -449,7 +449,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
] ]
(. newType.BodyStartLocation = t.EndLocation; .) (. newType.BodyStartLocation = t.EndLocation; .)
EnumBody EnumBody
[ ";" ] (. newType.EndLocation = t.Location; [ ";" ] (. newType.EndLocation = t.EndLocation;
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
.) .)
| /*--- delegate declaration: */ | /*--- delegate declaration: */
@ -471,7 +471,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
/* .NET 2.0 */ /* .NET 2.0 */
{ TypeParameterConstraintsClause<templates> } { TypeParameterConstraintsClause<templates> }
";" (. delegateDeclr.EndLocation = t.Location; ";" (. delegateDeclr.EndLocation = t.EndLocation;
compilationUnit.AddChild(delegateDeclr); compilationUnit.AddChild(delegateDeclr);
.) .)
) )

2
src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(1, td.BodyStartLocation.Line, "BodyStartLocation.Y"); Assert.AreEqual(1, td.BodyStartLocation.Line, "BodyStartLocation.Y");
Assert.AreEqual(14, td.BodyStartLocation.Column, "BodyStartLocation.X"); Assert.AreEqual(14, td.BodyStartLocation.Column, "BodyStartLocation.X");
Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y"); Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(2, td.EndLocation.Column, "EndLocation.Y");
} }
[Test] [Test]
@ -194,6 +195,7 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line"); Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line");
Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col"); Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col");
Assert.AreEqual(2, td.EndLocation.Line, "end line"); Assert.AreEqual(2, td.EndLocation.Line, "end line");
Assert.AreEqual(10, td.EndLocation.Column, "end col");
} }
[Test] [Test]

1
src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

@ -70,7 +70,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y"); Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X"); Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X");
// endLocation.X is currently 20. It should be 18, but that error is not critical // endLocation.X is currently 20. It should be 18, but that error is not critical
//Assert.AreEqual(18, md.EndLocation.X, "EndLocation.X"); //Assert.AreEqual(18, md.EndLocation.X, "EndLocation.X");
} }

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CSharpCodeGenerator.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
string endLineText = endLine.Text; string endLineText = endLine.Text;
int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}' int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}'
int pos = originalPos; int pos = originalPos;
if (pos >= endLineText.Length || endLineText[pos] != '}') { if (pos < 0 || pos >= endLineText.Length || endLineText[pos] != '}') {
LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')" LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')"
+ " endLineText=" + endLineText + ", pos=" + pos); + " endLineText=" + endLineText + ", pos=" + pos);
} else { } else {

Loading…
Cancel
Save