Пример #1
0
		void TestCreateMethod (string input, string outputString, bool returnWholeFile)
		{
			var generator = new CSharpCodeGeneratorNode ();
			MonoDevelop.Projects.CodeGeneration.CodeGenerator.AddGenerator (generator);
			var refactoring = new CreateMethodCodeGenerator ();
			RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (input);
			Assert.IsTrue (refactoring.IsValid (options));
			if (returnWholeFile) {
				refactoring.SetInsertionPoint (CodeGenerationService.GetInsertionPoints (options.Document, refactoring.DeclaringType).First ());
			} else {
				DocumentLocation loc = new DocumentLocation (1, 1);
				refactoring.SetInsertionPoint (new InsertionPoint (loc, NewLineInsertion.Eol, NewLineInsertion.Eol));
			}
			List<Change> changes = refactoring.PerformChanges (options, null);
//			changes.ForEach (c => Console.WriteLine (c));
			// get just the generated method.
			string output = ExtractMethodTests.GetOutput (options, changes);
			if (returnWholeFile) {
				Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
				return;
			}
			output = output.Substring (0, output.IndexOf ('}') + 1).Trim ();
			// crop 1 level of indent
			Document doc = new Document (output);
			foreach (LineSegment line in doc.Lines) {
				if (doc.GetCharAt (line.Offset) == '\t')
					((IBuffer)doc).Remove (line.Offset, 1);
			}
			output = doc.Text;
			
			Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
			MonoDevelop.Projects.CodeGeneration.CodeGenerator.RemoveGenerator (generator);
		}
Пример #2
0
        protected override void Run(RefactoringOptions options)
        {
            CreateMethodCodeGenerator createMethodCodeGenerator = new CreateMethodCodeGenerator();

            if (createMethodCodeGenerator.IsValid(options))
            {
                createMethodCodeGenerator.Run(options);
            }
        }
Пример #3
0
		protected override void Run (RefactoringOptions options)
		{
			CreateMethodCodeGenerator createMethodCodeGenerator = new CreateMethodCodeGenerator ();
			if (createMethodCodeGenerator.IsValid (options))
				createMethodCodeGenerator.Run (options);
		}