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

Commit

Permalink
Rework of reflection layer, "RoslynReflection" is now the central pla…
Browse files Browse the repository at this point in the history
…ce lazily loading types and methods. This should fix #165. Had to add workarounds in 2 analyzers to avoid exceptions, their function currently depends on reflection usage.
  • Loading branch information
Rpinski committed Jan 31, 2016
1 parent c7f3f59 commit 99bc215
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static bool TryGetDiagnostic(SyntaxNodeAnalysisContext nodeContext, out Diagnost
if (body == null)
return false;

// (Bad) workaround for usage of SignatureComparer in this analyzer, when Roslyn's Workspaces are not loaded
if (!RoslynReflection.SignatureComparer.IsAvailable())
return false;

var invocation = AnalyzeBody(body);
if (invocation == null)
return false;
Expand Down Expand Up @@ -106,8 +110,10 @@ static bool TryGetDiagnostic(SyntaxNodeAnalysisContext nodeContext, out Diagnost
{
if (otherMethod == method)
continue;
#pragma warning disable RECS9000 // Using internal Roslyn features through reflection in wrong context.
if (SignatureComparer.HaveSameSignature(otherMethod.GetParameters(), invokeMethod.Parameters))
return false;
#pragma warning restore RECS9000 // Using internal Roslyn features through reflection in wrong context.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ static bool TryGetDiagnostic(SyntaxNodeAnalysisContext nodeContext, out Diagnost
if (nodeContext.IsFromGeneratedCode())
return false;

// (Bad) workaround for usage of SpeculationAnalyzer in this analyzer, when Roslyn's Workspaces are not loaded
if (!RoslynReflection.SpeculationAnalyzer.IsAvailable())
return false;

var node = nodeContext.Node as MemberAccessExpressionSyntax;
if (node.Expression.IsKind(SyntaxKind.BaseExpression))
{
var replacementNode = node.Name.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
#pragma warning disable RECS9000 // Using internal Roslyn features through reflection in wrong context.
if (node.CanReplaceWithReducedName(replacementNode, nodeContext.SemanticModel, nodeContext.CancellationToken))
{
diagnostic = Diagnostic.Create(descriptor, node.Expression.GetLocation(), additionalLocations: new[] { node.OperatorToken.GetLocation() });
return true;
}
#pragma warning restore RECS9000 // Using internal Roslyn features through reflection in wrong context.
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions RefactoringEssentials/RefactoringEssentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@
<Compile Include="Util\GeneratedCodeRecognition.cs" />
<Compile Include="Util\HelpLink.cs" />
<Compile Include="Util\NRefactory6Host.cs" />
<Compile Include="Util\RoslynReflection.cs" />
<Compile Include="Util\SyntaxExtensions.cs" />
<Compile Include="Util\TypeExtensions.cs" />
<Compile Include="Util\CSharpUtil.cs" />
Expand Down
Loading

0 comments on commit 99bc215

Please sign in to comment.