Browse Source

Fixed SD2-571: Folding classes hides the declaration line

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1346 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
db253755b8
  1. 1
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs
  2. 6
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/CompilationUnit.cs
  3. 16
      src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs
  4. 1932
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  5. 17
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  6. 1969
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  7. 11
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  8. 2
      src/Libraries/NRefactory/Project/Src/Parser/gen.bat
  9. 16
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs
  10. 7
      src/Main/Base/Project/Src/Dom/IClass.cs
  11. 3
      src/Main/Base/Project/Src/Dom/IMember.cs
  12. 10
      src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs
  13. 26
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  14. 8
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/ParserFoldingStrategy.cs

1
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs

@ -55,6 +55,7 @@ namespace NRefactoryASTGenerator.AST @@ -55,6 +55,7 @@ namespace NRefactoryASTGenerator.AST
ClassType type;
List<TypeReference> baseTypes;
List<TemplateDefinition> templates;
Point bodyStartLocation;
public TypeDeclaration(Modifier modifier, List<AttributeSection> attributes) : base(modifier, attributes) {}
}

6
src/Libraries/NRefactory/Project/Src/Parser/AST/General/CompilationUnit.cs

@ -34,6 +34,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -34,6 +34,12 @@ namespace ICSharpCode.NRefactory.Parser.AST
blockStack.Pop();
}
public INode CurrentBock {
get {
return blockStack.Count > 0 ? (INode)blockStack.Peek() : null;
}
}
public override void AddChild(INode childNode)
{
if (childNode != null) {

16
src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs

@ -3806,6 +3806,8 @@ namespace ICSharpCode.NRefactory.Parser.AST { @@ -3806,6 +3806,8 @@ namespace ICSharpCode.NRefactory.Parser.AST {
List<TemplateDefinition> templates;
Point bodyStartLocation;
public string Name {
get {
return name;
@ -3842,12 +3844,22 @@ namespace ICSharpCode.NRefactory.Parser.AST { @@ -3842,12 +3844,22 @@ namespace ICSharpCode.NRefactory.Parser.AST {
}
}
public Point BodyStartLocation {
get {
return bodyStartLocation;
}
set {
bodyStartLocation = value;
}
}
public TypeDeclaration(Modifier modifier, List<AttributeSection> attributes) :
base(attributes) {
Modifier = modifier;
name = "";
baseTypes = new List<TypeReference>();
templates = new List<TemplateDefinition>();
bodyStartLocation = new Point(-1, -1);
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -3855,8 +3867,8 @@ namespace ICSharpCode.NRefactory.Parser.AST { @@ -3855,8 +3867,8 @@ namespace ICSharpCode.NRefactory.Parser.AST {
}
public override string ToString() {
return string.Format("[TypeDeclaration Name={0} Type={1} BaseTypes={2} Templates={3} Attributes={4} Mod" +
"ifier={5}]", Name, Type, GetCollectionString(BaseTypes), GetCollectionString(Templates), GetCollectionString(Attributes), Modifier);
return string.Format("[TypeDeclaration Name={0} Type={1} BaseTypes={2} Templates={3} BodyStartLocation=" +
"{4} Attributes={5} Modifier={6}]", Name, Type, GetCollectionString(BaseTypes), GetCollectionString(Templates), BodyStartLocation, GetCollectionString(Attributes), Modifier);
}
}

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

File diff suppressed because it is too large Load Diff

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

@ -840,6 +840,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes> @@ -840,6 +840,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes>
/* .NET 2.0 */
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
(. newType.BodyStartLocation = t.EndLocation; .)
ClassBody
[ ";" ] (. newType.EndLocation = t.Location;
compilationUnit.BlockEnd();
@ -863,6 +864,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes> @@ -863,6 +864,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes>
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
(. newType.BodyStartLocation = t.EndLocation; .)
StructBody
[ ";" ] (. newType.EndLocation = t.Location;
compilationUnit.BlockEnd();
@ -885,6 +887,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes> @@ -885,6 +887,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes>
/* .NET 2.0 */
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
(. newType.BodyStartLocation = t.EndLocation; .)
InterfaceBody
[ ";" ] (. newType.EndLocation = t.Location;
compilationUnit.BlockEnd();
@ -899,6 +902,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes> @@ -899,6 +902,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes>
ident (. newType.Name = t.val; .)
[ ":" IntegralType<out name> (. newType.BaseTypes.Add(new TypeReference(name)); .)
]
(. newType.BodyStartLocation = t.EndLocation; .)
EnumBody
[ ";" ] (. newType.EndLocation = t.Location;
compilationUnit.BlockEnd();
@ -974,7 +978,7 @@ StructInterfaces<out List<TypeReference> names> @@ -974,7 +978,7 @@ StructInterfaces<out List<TypeReference> names>
StructBody
(. AttributeSection section; .)
=
"{"
"{"
{ (.List<AttributeSection> attributes = new List<AttributeSection>();
Modifiers m = new Modifiers();
.)
@ -996,12 +1000,17 @@ InterfaceBase<out List<TypeReference> names> @@ -996,12 +1000,17 @@ InterfaceBase<out List<TypeReference> names>
.
InterfaceBody
= "{" { InterfaceMemberDecl } "}" .
= "{"
{ InterfaceMemberDecl }
"}"
.
EnumBody (. FieldDeclaration f; .)
=
"{" [ EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
{ IF (NotFinalComma()) "," EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
"{"
[ EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
{ IF (NotFinalComma()) ","
EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
}
[","] ] "}"
.

1969
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

11
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -662,6 +662,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -662,6 +662,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
ClassBody<newType>
@ -679,6 +680,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -679,6 +680,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
.)
Identifier (. newType.Name = t.val; .)
EOL
(. newType.BodyStartLocation = t.Location; .)
ModuleBody<newType>
(.
compilationUnit.BlockEnd();
@ -694,7 +696,9 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -694,7 +696,9 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EOL { TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
EOL
(. newType.BodyStartLocation = t.Location; .)
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
StructureBody<newType>
(.
compilationUnit.BlockEnd();
@ -713,6 +717,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -713,6 +717,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .)
[ "As" NonArrayTypeName<out typeRef, false> (. newType.BaseTypes.Add(typeRef); .) ]
EOL
(. newType.BodyStartLocation = t.Location; .)
EnumBody<newType>
(.
compilationUnit.BlockEnd();
@ -729,7 +734,9 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -729,7 +734,9 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EndOfStmt { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
{ InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
InterfaceBody<newType>
(.
compilationUnit.BlockEnd();

2
src/Libraries/NRefactory/Project/Src/Parser/gen.bat

@ -35,3 +35,5 @@ del VBNET.ATG @@ -35,3 +35,5 @@ del VBNET.ATG
:exit
pause
cd ..
cd ..\..\..
%windir%\microsoft.net\framework\v2.0.50727\msbuild

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

@ -32,7 +32,19 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -32,7 +32,19 @@ namespace ICSharpCode.NRefactory.Tests.AST
}
[Test]
public void CSharpSimplePartitialClassTypeDeclarationTest()
public void CSharpSimpleClassRegionTest()
{
const string program = "class MyClass\n{\n}\n";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual(1, td.StartLocation.Y, "StartLocation.Y");
Assert.AreEqual(1, td.StartLocation.X, "StartLocation.X");
Assert.AreEqual(1, td.BodyStartLocation.Y, "BodyStartLocation.Y");
Assert.AreEqual(14, td.BodyStartLocation.X, "BodyStartLocation.X");
Assert.AreEqual(3, td.EndLocation.Y, "EndLocation.Y");
}
[Test]
public void CSharpSimplePartialClassTypeDeclarationTest()
{
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class MyClass { }");
Assert.IsNotNull(td);
@ -184,6 +196,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -184,6 +196,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type);
Assert.AreEqual(1, td.StartLocation.Y, "start line");
Assert.AreEqual(1, td.BodyStartLocation.Y, "bodystart line");
Assert.AreEqual(16, td.BodyStartLocation.X, "bodystart col");
Assert.AreEqual(2, td.EndLocation.Y, "end line");
}

7
src/Main/Base/Project/Src/Dom/IClass.cs

@ -55,10 +55,17 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -55,10 +55,17 @@ namespace ICSharpCode.SharpDevelop.Dom
get;
}
/// <summary>
/// Region of the whole class including the body.
/// </summary>
DomRegion Region {
get;
}
DomRegion BodyRegion {
get;
}
List<IReturnType> BaseTypes {
get;
}

3
src/Main/Base/Project/Src/Dom/IMember.cs

@ -16,6 +16,9 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -16,6 +16,9 @@ namespace ICSharpCode.SharpDevelop.Dom
get;
}
/// <summary>
/// Declaration region of the member (without body!)
/// </summary>
DomRegion Region {
get;
}

10
src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs

@ -20,6 +20,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -20,6 +20,7 @@ namespace ICSharpCode.SharpDevelop.Dom
{
ClassType classType;
DomRegion region;
DomRegion bodyRegion;
ICompilationUnit compilationUnit;
@ -172,6 +173,15 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -172,6 +173,15 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
public DomRegion BodyRegion {
get {
return bodyRegion;
}
set {
bodyRegion = value;
}
}
public override string DotNetName {
get {
if (typeParameters == null || typeParameters.Count == 0) {

26
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -74,8 +74,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -74,8 +74,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
string GetDocumentation(int line)
string GetDocumentation(int line, IList<AST.AttributeSection> attributes)
{
foreach (AST.AttributeSection att in attributes) {
if (att.StartLocation.Y > 0 && att.StartLocation.Y < line)
line = att.StartLocation.Y;
}
List<string> lines = new List<string>();
int length = 0;
while (line > 0) {
@ -141,7 +145,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -141,7 +145,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object Visit(AST.CompilationUnit compilationUnit, object data)
{
//TODO: usings, Comments
if (compilationUnit == null) {
return null;
}
@ -276,9 +279,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -276,9 +279,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object Visit(AST.TypeDeclaration typeDeclaration, object data)
{
DomRegion region = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertModifier(typeDeclaration.Modifier, ModifierEnum.Internal), region, GetCurrentClass());
c.BodyRegion = bodyRegion;
ConvertAttributes(typeDeclaration, c);
c.Documentation = GetDocumentation(region.BeginLine);
c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);
if (currentClass.Count > 0) {
DefaultClass cur = GetCurrentClass();
@ -365,7 +371,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -365,7 +371,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{
DomRegion region = GetRegion(delegateDeclaration.StartLocation, delegateDeclaration.EndLocation);
DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ConvertModifier(delegateDeclaration.Modifier, ModifierEnum.Internal), region, GetCurrentClass());
c.Documentation = GetDocumentation(region.BeginLine);
c.Documentation = GetDocumentation(region.BeginLine, delegateDeclaration.Attributes);
ConvertAttributes(delegateDeclaration, c);
CreateDelegate(c, delegateDeclaration.Name, delegateDeclaration.ReturnType,
delegateDeclaration.Templates, delegateDeclaration.Parameters);
@ -426,7 +432,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -426,7 +432,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DefaultClass c = GetCurrentClass();
DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
method.Documentation = GetDocumentation(region.BeginLine);
method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes);
ConvertTemplates(methodDeclaration.Templates, method);
method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method);
ConvertAttributes(methodDeclaration, method);
@ -466,7 +472,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -466,7 +472,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DefaultClass c = GetCurrentClass();
Constructor constructor = new Constructor(ConvertModifier(constructorDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
constructor.Documentation = GetDocumentation(region.BeginLine);
constructor.Documentation = GetDocumentation(region.BeginLine, constructorDeclaration.Attributes);
ConvertAttributes(constructorDeclaration, constructor);
if (constructorDeclaration.Parameters != null) {
foreach (AST.ParameterDeclarationExpression par in constructorDeclaration.Parameters) {
@ -495,7 +501,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -495,7 +501,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{
DomRegion region = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation);
DefaultClass c = GetCurrentClass();
string doku = GetDocumentation(region.BeginLine);
string doku = GetDocumentation(region.BeginLine, fieldDeclaration.Attributes);
if (currentClass.Count > 0) {
for (int i = 0; i < fieldDeclaration.Fields.Count; ++i) {
AST.VariableDeclaration field = (AST.VariableDeclaration)fieldDeclaration.Fields[i];
@ -535,7 +541,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -535,7 +541,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation);
property.CanSet = true;
}
property.Documentation = GetDocumentation(region.BeginLine);
property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes);
ConvertAttributes(propertyDeclaration, property);
c.Properties.Add(property);
return null;
@ -565,7 +571,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -565,7 +571,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
ConvertAttributes(eventDeclaration, e);
c.Events.Add(e);
if (e != null) {
e.Documentation = GetDocumentation(region.BeginLine);
e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes);
} else {
LoggingService.Warn("NRefactoryASTConvertVisitor: " + eventDeclaration + " has no events!");
}
@ -578,7 +584,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -578,7 +584,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart, indexerDeclaration.BodyEnd);
DefaultProperty i = new DefaultProperty("Indexer", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
i.IsIndexer = true;
i.Documentation = GetDocumentation(region.BeginLine);
i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes);
ConvertAttributes(indexerDeclaration, i);
if (indexerDeclaration.Parameters != null) {
foreach (AST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) {

8
src/Main/Base/Project/Src/TextEditor/Gui/Editor/ParserFoldingStrategy.cs

@ -22,9 +22,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -22,9 +22,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
if (c.ClassType == ClassType.Delegate) {
return;
}
if (c.Region.BeginLine < c.Region.EndLine) {
FoldMarker newFoldMarker = new FoldMarker(document, c.Region.BeginLine - 1, c.Region.BeginColumn - 1,
c.Region.EndLine - 1, c.Region.EndColumn, FoldType.TypeBody);
DomRegion cRegion = c.BodyRegion;
if (cRegion.IsEmpty) cRegion = c.Region;
if (cRegion.BeginLine < cRegion.EndLine) {
FoldMarker newFoldMarker = new FoldMarker(document, cRegion.BeginLine - 1, cRegion.BeginColumn - 1,
cRegion.EndLine - 1, cRegion.EndColumn, FoldType.TypeBody);
if (newFoldMarker.Length > 0) {
foldMarkers.Add(newFoldMarker);
}

Loading…
Cancel
Save