public void Should_insert_stub_method_override() { var buffer = @" public class WeirdString : String { $ }"; var location = TestHelpers.GetLineAndColumnFromDollar(buffer); buffer = buffer.Replace("$",""); var request = new RunOverrideTargetRequest { Buffer = buffer, FileName = "myfile.cs", Line = location.Line, Column = location.Column }; var solution = new FakeSolutionBuilder().AddFile(buffer, "myfile.cs").Build(); var parser = new BufferParser(solution); var handler = new OverrideHandler (parser, new OmniSharpConfiguration ()); request.OverrideTargetName = "public virtual string ToString ();"; var response = handler.RunOverrideTarget (request); string expected = @" public class WeirdString : String { public override string ToString() { throw new System.NotImplementedException(); } }"; string result = response.Buffer.Replace ("\r\n", "\n"); result.ShouldEqual(expected); }
/// <summary> /// Takes an editing context. Inserts an override /// declaration of the chosen member in the context. Returns /// the new context. /// </summary> /// <remarks> /// The text editor cursor stays in the same line and column /// it originally was. /// </remarks> public RunOverrideTargetResponse RunOverrideTarget (RunOverrideTargetRequest request) { var overrideContext = new OverrideContext(request, _parser); var refactoringContext = OmniSharpRefactoringContext.GetContext (overrideContext.BufferParser, request); var memberToOverride = overrideContext.GetOverridableMembers() .First(ot => { var memberSignature = GetOverrideTargetsResponse.GetOverrideTargetName (ot, overrideContext.CompletionContext.ResolveContext); return(memberSignature == request.OverrideTargetName); }); var builder = new TypeSystemAstBuilder (new CSharpResolver (overrideContext.CompletionContext.ResolveContext)) // Will generate a "throw new // NotImplementedException();" statement in the // bodies { GenerateBody = true }; var newEditorContents = runOverrideTargetWorker (request , refactoringContext , overrideContext.CompletionContext.ParsedContent , script: new OmniSharpScript(refactoringContext, _config) , memberDeclaration: builder.ConvertEntity(memberToOverride)); return(new RunOverrideTargetResponse (fileName: request.FileName , buffer: newEditorContents.Text , line: request.Line , column: request.Column)); }
/// <summary> /// Takes an editing context. Inserts an override /// declaration of the chosen member in the context. Returns /// the new context. /// </summary> /// <remarks> /// The text editor cursor stays in the same line and column /// it originally was. /// </remarks> public RunOverrideTargetResponse RunOverrideTarget (RunOverrideTargetRequest request) { var overrideContext = new OverrideContext(request, _parser); var refactoringContext = OmniSharpRefactoringContext.GetContext (overrideContext.BufferParser, request); var memberToOverride = overrideContext.GetOverridableMembers() .First(ot => { var memberSignature = GetOverrideTargetsResponse.GetOverrideTargetName (ot, overrideContext.CompletionContext.ResolveContext); return memberSignature == request.OverrideTargetName;}); var builder = new TypeSystemAstBuilder (new CSharpResolver (overrideContext.CompletionContext.ResolveContext)) // Will generate a "throw new // NotImplementedException();" statement in the // bodies {GenerateBody = true}; var newEditorContents = runOverrideTargetWorker ( request , refactoringContext , overrideContext.CompletionContext.ParsedContent , script: new OmniSharpScript(refactoringContext, _config) , memberDeclaration: builder.ConvertEntity(memberToOverride)); return new RunOverrideTargetResponse ( fileName : request.FileName , buffer : newEditorContents.Text , line : request.Line , column : request.Column); }