Bug 10730 - Auto-Fix regarding method definition: "Make it static"
Summary: Auto-Fix regarding method definition: "Make it static"
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 4.0
Hardware: PC Linux
: Normal enhancement
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-02-27 08:08 UTC by Ciprian Khlud
Modified: 2013-04-05 03:46 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ciprian Khlud 2013-02-27 08:08:25 UTC
Reference to bug #10717 comment 1


Description of Problem:
Auto-Fix should hint some fixes:

Steps to reproduce the problem:
1. Create a console application
2. Paste this code as starting point:
using System;

namespace TestConsole
{
    class MainClass
    {
         public bool AreAllNumbersPrime (List<int> items)
         {
             bool result = true;

             foreach (var item in items) {
                if (item < 4)
                     continue;
                if(item%2==0)
                 {
                     result = false;
                     break;
                 }
                for (var i = 3; i < item / 2; i += 2)
                     if (item % i == 0)
                     {
                     result = false;
                     break;
                      }
            }

                        Console.WriteLine(result?"All numers are prime":"Some
numbers are not prime");
            return result;
        }

        public static void Main (string[] args)
        {
            var items = new List<int>{2,3,5,7,11,13,17,19,23,29,37};
            var main = new MainClass ();
            main.AreAllNumbersPrime (items);

        }
    }
}
3. Set the cursor to the word: AreAllNumbersPrime; for line: public bool AreAllNumbersPrime (IList<int> items)
4. Press Alt+Enter to show quick fixes
5. Select the first option

Expected result:
Function AreAllNumbersPrime does not access This pointer either via fields call
or via method or property call.
- "Make it static": would add static in the function definition

The code refactor has to do 2 things:
- to establish the fact that a method is static
- rename in all usages instance.MethodCall(...) to ClassName.MethodCall(); //global refactor

Actual result: Nothing appears
Comment 1 Ciprian Khlud 2013-04-04 13:30:15 UTC
Add a minimalist (I found that Extract Method scans for static accesses) code action to make the code static. It will not work in all cases (like in case of public methods) but is a starting point.

https://github.com/ciplogic/NRefactory/commit/ac9732776cada14cc3ef03cc7138d463229d7215

Added pull request. (Code is done just to see that it works in some cases, and is not cleaned up, including end of lines).
Comment 2 Mike Krüger 2013-04-05 01:40:20 UTC
Btw. that thing would be much better as code issue provider and not as code action.
Comment 3 Ciprian Khlud 2013-04-05 02:50:45 UTC
You're right, I may do change it late-today, but I knew really well how to test Code-Actions so this was my starting point. Thank you for merging it.
Comment 4 Mike Krüger 2013-04-05 03:46:14 UTC
I took the opportunity to start global action support :).