Skip to content
This repository has been archived by the owner. It is now read-only.

Fixes #301. Fix up ConvertAutoPropertyToPropertyTest #304

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
213617c
add codescn
ceddlyburge Mar 8, 2017
80db822
Add codescene link
ceddlyburge Mar 8, 2017
f901e9d
Merge remote-tracking branch 'upstream/master'
ceddlyburge Apr 2, 2017
a21a7b3
Fixes #301. Work around Roslyn simplifier bug in ConvertAutoPropertyT…
ceddlyburge Apr 2, 2017
9dd017f
Remove duplicated files
ceddlyburge Apr 2, 2017
995fc0e
Add syntaxetenstions back in to csproj and remove duplicate
ceddlyburge Apr 2, 2017
44e0a0f
Fix up csprof to improve diff
ceddlyburge Apr 2, 2017
482d64f
fix #291 - CreateChangedEventCodeRefactoringProvider exception on aut…
siegfriedpammer Apr 7, 2017
de1c5f3
[Perf] Don't use Linq extensions when API is available.
Therzok Apr 23, 2017
c187c54
[Perf] Avoid linq and eager tolist when not needed.
Therzok Apr 23, 2017
76581a0
[Perf] Optimize LocalVariableHidesMember analyzer
Therzok Apr 23, 2017
f8fc468
[Perf] Optimize ParameterHidesMemberAnalyzer
Therzok Apr 23, 2017
7c06ed9
[Perf] Optimize ParameterOnlyAssignedAnalyzer
Therzok Apr 23, 2017
7f5e5aa
[Perf] Optimize NameOfSuggestionAnalyzer
Therzok Apr 23, 2017
e0d3d2b
[Perf] Optimize EqualsExpressionComparisonAnalyzer
Therzok Apr 26, 2017
b18d9ba
[Perf] Optimize ConvertIfStatementToSwitchStatementAnalyzer
Therzok Apr 26, 2017
b99dbc8
[Perf] Optimize RedundantIfElseBlockAnalyzer
Therzok Apr 26, 2017
93cd097
[Perf] RedundantFieldInitializerAnalyzer optimization
Therzok Apr 26, 2017
36a5c3e
[Perf] Optimize RedundantDefaultFieldInitializer
Therzok Apr 26, 2017
c9c6d4b
Bump roslyn to 2.1
Therzok Apr 27, 2017
8963678
Fix NRE in RedundantIfElseBlockAnalyzer
Therzok Apr 27, 2017
2613ca6
Fix inverted value for FalseLiteralExpression.
Therzok Apr 30, 2017
6310e9b
Fix NRE in RedundantIfElseBlockAnalyzer
Therzok May 1, 2017
1e4de48
[Perf] Optimize EnsuresNotNull
Therzok May 2, 2017
d728782
Fixed EmptyConstructorAnalyzer in case of expression bodies.
May 17, 2017
f94e74c
Fix a bug in ForControlVariableIsNeverModifiedAnalyzer.
May 19, 2017
cfd7c2c
Fix ArgumentOutOfRangeException in RedundantCommaInArrayInitializerAn…
Therzok May 31, 2017
aa1cd73
Make NRefactory6Host public so MonoDevelop can localise diagnostics
Jun 8, 2017
fb87454
Fixed change access modifier removing non access modifiers bug.
Jun 15, 2017
f4e6625
Check language version of some c#6 code refactoring providers.
Jun 15, 2017
fbc06b3
Remove diagnostics with NotYetPortedAttribute.
Therzok Aug 22, 2017
9cfbb6f
Fix build & control flow analysis
Aug 23, 2017
0f58653
Updated Microsoft.VSSDK.BuildTools package in VSIX project to latest …
Rpinski Aug 23, 2017
570161f
Bump roslyn.
Therzok Sep 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions DocGenerator.2017/DocGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,29 @@
<Reference Include="Esent.Interop, Version=1.9.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\ManagedEsent.1.9.4\lib\net40\Esent.Interop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Elfie, Version=0.10.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Elfie.0.10.6\lib\net46\Microsoft.CodeAnalysis.Elfie.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.0.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.1.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.0.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.1.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down
12 changes: 6 additions & 6 deletions DocGenerator.2017/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<packages>
<package id="ManagedEsent" version="1.9.4" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.2.0-beta2" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Common" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.CSharp" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Common" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.CSharp" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Elfie" version="0.10.6" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.VisualBasic" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.VisualBasic.Workspaces" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.VisualBasic" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.VisualBasic.Workspaces" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.Composition" version="1.0.30" targetFramework="net461" />
<package id="Microsoft.DiaSymReader.Native" version="1.5.0" targetFramework="net461" />
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Join the chat at https://gitter.im/icsharpcode/RefactoringEssentials](https://badges.gitter.im/icsharpcode/RefactoringEssentials.svg)](https://gitter.im/icsharpcode/RefactoringEssentials?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![](https://codescene.io/projects/842/status.svg) Get more details at **codescene.io**.](https://codescene.io/projects/842/jobs/latest-successful/results)

[@vsrefactoring](https://twitter.com/vsrefactoring) | [vsrefactoringessentials.com](http://vsrefactoringessentials.com/)

Refactorings Essentials sports the following features:
Expand All @@ -27,4 +29,5 @@ makes them easier to maintain and contribute to.
Branch | Status 4.* (VS 2015) | Status 5.* (VS 2017)
--- | --- | ---
*master* (Development) | [![Build status](https://ci.appveyor.com/api/projects/status/5463mskexnsa0176/branch/master?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials/branch/master) | [![Build status](https://ci.appveyor.com/api/projects/status/r01wr5xdclj24y20/branch/master?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials-wgnsw/branch/master)
*release* (Latest Release) | [![Build status](https://ci.appveyor.com/api/projects/status/5463mskexnsa0176/branch/release?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials/branch/release) | [![Build status](https://ci.appveyor.com/api/projects/status/r01wr5xdclj24y20/branch/release?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials-wgnsw/branch/release)
*release* (Latest Release) | [![Build status](https://ci.appveyor.com/api/projects/status/5463mskexnsa0176/branch/release?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials/branch/release) | [![Build status](https://ci.appveyor.com/api/projects/status/r01wr5xdclj24y20/branch/release?svg=true)](https://ci.appveyor.com/project/icsharpcode/refactoringessentials-wgnsw/branch/release)
k
23 changes: 19 additions & 4 deletions RefactoringEssentials.2017/RefactoringEssentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
<Compile Include="..\RefactoringEssentials\CSharp\CodeRefactorings\Synced\ConvertAutoPropertyToPropertyCodeRefactoringProvider.cs">
<Link>CSharp\CodeRefactorings\Synced\ConvertAutoPropertyToPropertyCodeRefactoringProvider.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\CodeRefactorings\Synced\ConvertAutoPropertyToPropertyManipulater.cs">
<Link>CSharp\CodeRefactorings\Synced\ConvertAutoPropertyToPropertyManipulater.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\CodeRefactorings\Synced\ConvertCoalescingToConditionalExpressionCodeRefactoringProvider.cs">
<Link>CSharp\CodeRefactorings\Synced\ConvertCoalescingToConditionalExpressionCodeRefactoringProvider.cs</Link>
</Compile>
Expand Down Expand Up @@ -1331,6 +1334,18 @@
<Compile Include="..\RefactoringEssentials\CSharp\SyntaxExtensions.cs">
<Link>CSharp\SyntaxExtensions.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\CodeRefactoringStatementSyntax.cs">
<Link>CSharp\CodeRefactoringStatementSyntax.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\DocumentManipulator.cs">
<Link>CSharp\DocumentManipulator.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\PropertyDeclarationContext.cs">
<Link>CSharp\PropertyDeclarationContext.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\CSharp\PropertyDeclarationContextFinder.cs">
<Link>CSharp\PropertyDeclarationContextFinder.cs</Link>
</Compile>
<Compile Include="..\RefactoringEssentials\Samples\CSharp\SampleAnalyzer.cs">
<Link>Samples\CSharp\SampleAnalyzer.cs</Link>
</Compile>
Expand Down Expand Up @@ -1694,10 +1709,10 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="2.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="2.3.2" />
</ItemGroup>
<ItemGroup>
<None Update="RefactoringEssentials.Library.nuspec">
Expand Down
26 changes: 26 additions & 0 deletions RefactoringEssentials/CSharp/CodeRefactoringStatementSyntax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace RefactoringEssentials.CSharp
{
public class CodeRefactoringStatementSyntax
{
StatementSyntax StatementSyntax { get; }

public CodeRefactoringStatementSyntax(StatementSyntax statementSyntax)
{
StatementSyntax = statementSyntax;
}

public CodeRefactoringStatementSyntax WithAdditionalAnnotations(params SyntaxAnnotation[] annotations)
{
return new CodeRefactoringStatementSyntax(StatementSyntax.WithAdditionalAnnotations(annotations));
}

public BlockSyntax WrapInBlock()
{
return SyntaxFactory.Block(StatementSyntax);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static Task<Document> CreateAndInitialiseReadOnlyAutoPropertyFromConstructorPara
nodeToAdd: CreateAutoProperty(
type: context.Type,
identifier: context.PropertyName,
accessors: GetAccessor(),
accessors: GetAutoAccessor(),
accessibility: SyntaxKind.PublicKeyword));

var rootWithAssignmentAndProperty = AddStatementToConstructorBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,68 @@ static StatementSyntax CreateContractEnsuresCall(string returnType)
return SyntaxFactory.ParseStatement($"Contract.Ensures(Contract.Result<{returnType}>() != null);\r\n").WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation);
}

static bool HasReturnContract(BlockSyntax bodyStatement, string returnType)
static bool ValidateContractAccess(MemberAccessExpressionSyntax access, string method, string genericTypeName)
{
var workspace = new AdhocWorkspace();
if (access == null)
return false;

var className = access.Expression.GetRightmostName() as SimpleNameSyntax;
if (className == null || className.Identifier.ValueText != "Contract")
return false;

var ensures = access.GetRightmostName() as SimpleNameSyntax;
if (ensures == null || ensures.Identifier.ValueText != method)
return false;

if (genericTypeName!= null)
{
var generic = ensures as GenericNameSyntax;
if (generic == null || generic.Arity != 1)
return false;

var typeName = generic.TypeArgumentList.Arguments[0].GetRightmostName() as SimpleNameSyntax;
if (typeName == null || typeName.Identifier.ValueText != genericTypeName)
return false;
}
return true;
}

var rhsEnsures = $"Contract.Ensures(Contract.Result<{returnType}>() != null);";
var lhsEnsures = $"Contract.Ensures(null != Contract.Result<{returnType}>());";
static bool HasReturnContract(BlockSyntax bodyStatement, string returnType)
{
var rhsEnsures = SyntaxFactory.ParseStatement($"Contract.Ensures(Contract.Result<{returnType}>() != null);");
var lhsEnsures = SyntaxFactory.ParseStatement($"Contract.Ensures(null != Contract.Result<{returnType}>());");
foreach (var expression in bodyStatement.DescendantNodes().OfType<ExpressionStatementSyntax>())
{
var formatted = Formatter.Format(expression, workspace).ToString();
var ies = expression.Expression as InvocationExpressionSyntax;
if (ies == null)
continue;

var access = ies.Expression as MemberAccessExpressionSyntax;
if (access == null)
continue;

if (!ValidateContractAccess(access, "Ensures", null))
continue;

if (formatted == rhsEnsures || formatted == lhsEnsures)
return true;
if (ies.ArgumentList.Arguments.Count != 1)
continue;

var arg = ies.ArgumentList.Arguments[0].Expression as BinaryExpressionSyntax;
if (arg == null || !arg.OperatorToken.IsKind(SyntaxKind.ExclamationEqualsToken))
continue;

if (arg.Left.IsKind(SyntaxKind.NullLiteralExpression))
{
ies = arg.Right as InvocationExpressionSyntax;
}
else if (arg.Right.IsKind(SyntaxKind.NullLiteralExpression))
{
ies = arg.Left as InvocationExpressionSyntax;
}
access = ies?.Expression as MemberAccessExpressionSyntax;
if (!ValidateContractAccess(access, "Result", returnType))
continue;
return true;
}
return false;
}
Expand Down
Loading