Browse Source

Fixed constructor this/base unit test.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
eb5f2577eb
  1. 4
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  2. 12
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  4. 13
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  5. 8320
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  6. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  7. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs
  8. 3
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

4
ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs

@ -57,6 +57,10 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public CSharpTokenNode ColonToken {
get { return GetChildByRole (Roles.Colon); }
}
public ConstructorInitializer Initializer { public ConstructorInitializer Initializer {
get { return GetChildByRole (InitializerRole); } get { return GetChildByRole (InitializerRole); }
set { SetChildByRole( InitializerRole, value); } set { SetChildByRole( InitializerRole, value); }

12
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -730,7 +730,17 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return wrapper.Result; return wrapper.Result;
} }
} }
if (node == null) {
var constructor = Unit.GetNodeAt<ConstructorDeclaration> (location.Line, location.Column - 3);
Console.WriteLine (constructor);
Console.WriteLine (constructor.ColonToken.IsNull);
Console.WriteLine (constructor.Initializer.IsNull);
if (constructor != null && !constructor.ColonToken.IsNull && constructor.Initializer.IsNull) {
wrapper.AddCustom ("this");
wrapper.AddCustom ("base");
return wrapper.Result;
}
}
CSharpResolver csResolver; CSharpResolver csResolver;
if (node != null) { if (node != null) {
var nodes = new List<AstNode> (); var nodes = new List<AstNode> ();

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

@ -175,7 +175,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (!IsInsideType (currentType, location)) if (!IsInsideType (currentType, location))
currentType = null; currentType = null;
} }
this.currentMember = null; this.currentMember = null;
if (this.currentType != null) { if (this.currentType != null) {
foreach (var member in currentType.Members) { foreach (var member in currentType.Members) {
@ -190,7 +189,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (!IsInsideType (currentMember, location)) if (!IsInsideType (currentMember, location))
currentMember = null; currentMember = null;
} }
var stack = GetBracketStack (GetMemberTextToCaret ().Item1); var stack = GetBracketStack (GetMemberTextToCaret ().Item1);
if (stack.Count == 0) if (stack.Count == 0)
currentMember = null; currentMember = null;

13
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -1075,14 +1075,15 @@ namespace ICSharpCode.NRefactory.CSharp
if (initializerLocation != null) if (initializerLocation != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon); newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon);
// this and base has the same length
initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword); if (initializerLocation != null && initializerLocation.Count > 1) {
if (initializerLocation != null) // this and base has the same length
initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword);
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar); initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar);
AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments); AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments);
if (initializerLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar); initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar);
newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole); newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole);
}
} }
if (c.Block != null) if (c.Block != null)

8320
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

6
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

@ -2256,6 +2256,12 @@ constructor_initializer
$$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2)); $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6)); lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
} }
| COLON error
{
Error_SyntaxError (yyToken);
$$ = new ConstructorThisInitializer (null, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($1));
}
| error | error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);

4
ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs

@ -241,7 +241,9 @@ namespace Mono.CSharp {
public char GetChar (int position) public char GetChar (int position)
{ {
return buffer[position]; if (buffer_start <= position && position < buffer.Length)
return buffer[position];
return '\0';
} }
public char[] ReadChars (int fromPosition, int toPosition) public char[] ReadChars (int fromPosition, int toPosition)

3
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -4098,14 +4098,13 @@ namespace Test
}); });
} }
[Ignore("Fixme!")]
[Test()] [Test()]
public void TestConstructorThisBase () public void TestConstructorThisBase ()
{ {
CombinedProviderTest ( CombinedProviderTest (
@"class Program @"class Program
{ {
public Program ()$ : t$ public Program () : $t$
{ {
} }
}", provider => { }", provider => {

Loading…
Cancel
Save