Bug 10729 - Auto-Fix regarding control flow: "Remove redundant paranthesis" in lambdas
Summary: Auto-Fix regarding control flow: "Remove redundant paranthesis" in lambdas
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 4.0
Hardware: PC Linux
: Normal enhancement
Target Milestone: 4.2.3 (from master)
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-02-27 08:02 UTC by Ciprian Khlud
Modified: 2014-02-06 02:37 UTC (History)
2 users (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:02:09 UTC
Reference to bug #10717 comment 1

Add an Auto-Fix that simplify blocks of code:
Any lambda with one parameter
$(i) => { ... }
can be simplified to: 
i => {...}
Note: it works just for 1 parameter method
Comment 1 Ciprian Khlud 2013-04-05 18:47:21 UTC
I've made a visitor for lambda expression with parenthesis and it seems that the parser removes paranthesis, so there is basically no way to detect where the extra parenthesis are:

an unit test like this:
{
var input = @"
class TestClass
    {
        delegate void EventT<T>(T data);
        public void T() {
            EventT<int> a=null;
            a+= (i) => { };
        }
    }";
			var output =@"
class TestClass
    {
        delegate void EventT<T>(T data);
        public void T() {
            EventT<int> a=null;
            a+= i => { };
        }
    }";
Test<RedundantLambdaParenthesesIssue> (input, 1, output);
}

And a visitor as minimalist as this one:


public override void VisitLambdaExpression (LambdaExpression expression)
{
  base.VisitLambdaExpression(expression);

  if(expression.Parameters.Count!=1)
    return;
  AddIssue (expression.StartLocation, expression.EndLocation, 
    ctx.TranslateString ("Remove redundant parentheses"),
    script => { script.Replace (expression, expression.Clone ()); } );
}

would do the job.
Comment 2 Mike Krüger 2013-09-16 05:20:34 UTC
tis one got implemented.
Comment 3 narayanp 2014-02-06 02:16:21 UTC
Could you please provide me some steps so that I can check this implemented feature?
Comment 4 Mike Krüger 2014-02-06 02:37:23 UTC
just take the input/output example from above