Skip to content

Commit

Permalink
Merge branch 'UpdateV2021.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud Fakhoury authored and Mahmoud Fakhoury committed Jan 20, 2022
2 parents a71c0a3 + e63a967 commit 271ed6c
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 163 deletions.
2 changes: 1 addition & 1 deletion build/ExceptionalDevs.Exceptional.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tags>Exception XMLdoc</tags>
<licenseUrl>https://github.com/CSharpAnalyzers/ExceptionalReSharper/blob/master/LICENSE.md</licenseUrl>
<dependencies>
<dependency id="Wave" version="[211]" />
<dependency id="Wave" version="[213]" />
</dependencies>
</metadata>
<files>
Expand Down
3 changes: 1 addition & 2 deletions build/Old Build/CreatePackage.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
nuget pack ExceptionalDevs.Exceptional.nuspec -OutputDirectory ../Packages
pause
nuget pack ExceptionalDevs.Exceptional.nuspec -OutputDirectory ../Packages
4 changes: 2 additions & 2 deletions build/Old Build/ExceptionalDevs.Exceptional.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<package>
<metadata>
<id>ExceptionalDevs.Exceptional.MF</id>
<version>2021.3.0</version>
<version>2021.3.2</version>
<title>Exceptional by MF</title>
<description>Analyzes thrown and documented C# exceptions and suggests improvements.</description>
<authors>Mahmoud Fakhoury -- The source project was developed by ExceptionalDevs</authors>
<projectUrl>https://github.com/hhu-mahmoud/ExceptionalReSharper</projectUrl>
<copyright>Copyright © 2021 MF</copyright>
<copyright>Copyright © 2022 MF</copyright>
<tags>Exception XMLdoc</tags>
<licenseUrl>https://github.com/hhu-mahmoud/ExceptionalReSharper/blob/master/LICENSE.md</licenseUrl>
<dependencies>
Expand Down
Binary file modified build/Old Build/lib/ReSharper.Exceptional.dll
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions src/Exceptional.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B9A71DA-04F0-43E1-A364-8B774F5755A5}"
ProjectSection(SolutionItems) = preProject
..\build\ExceptionalDevs.Exceptional.nuspec = ..\build\ExceptionalDevs.Exceptional.nuspec
..\build\Old Build\ExceptionalDevs.Exceptional.nuspec = ..\build\Old Build\ExceptionalDevs.Exceptional.nuspec
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptional.Playground", "Exceptional.Playground\Exceptional.Playground.csproj", "{D59BE8E6-FE1E-48B9-B001-0CBAEB707B3F}"
Expand Down
15 changes: 12 additions & 3 deletions src/Exceptional/Exceptional.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
<Version>2021.3.0</Version>
</PackageReference>
<PackageReference Include="JetBrains.Lifetimes">
<Version>2021.3.4</Version>
<Version>2022.1.3</Version>
</PackageReference>
<PackageReference Include="JetBrains.RdFramework">
<Version>2021.3.4</Version>
<Version>2022.1.3</Version>
</PackageReference>
<PackageReference Include="JetBrains.ReSharper.SDK" Version="2021.3.0-eap07">
<PackageReference Include="JetBrains.ReSharper.SDK" Version="2021.3.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down Expand Up @@ -182,4 +182,13 @@
<Target Name="UpdateAssemblyInfo">
<AssemblyInfo CodeLanguage="CS" OutputFile="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs" AssemblyTitle="$(Title)" AssemblyDescription="$(Description)" AssemblyProduct="Exceptional" AssemblyCompany="$(Authors)" AssemblyCopyright="$(Copyright)" AssemblyVersion="$(Version)" ComVisible="false" Guid="3628d589-e118-4c2c-bd8e-fdef6b6ed07c" />
</Target>
<Target Name="CopyDLLs" AfterTargets="Build">
<Message Text="Executing CopyDLLs task" Importance="High" />
<Copy SourceFiles="$(TargetDir)$(AssemblyName).dll;$(TargetDir)$(AssemblyName).pdb" DestinationFolder="$(SolutionDir)\..\build\Old Build\lib\" />
<Message Text="Copied build files" Importance="High" />
</Target>
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/Exceptional/ExceptionalDaemonStageProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void AddHighlighting(IHighlighting highlighting, DocumentRange range)
}

/// <exception cref="OperationCanceledException">The process has been cancelled. </exception>
/// <exception cref="Exception">A delegate callback throws an exception.</exception>
public override void Execute(Action<DaemonStageResult> commiter)
{
var file = ServiceLocator.Process.SourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance) as ICSharpFile;
Expand Down
172 changes: 73 additions & 99 deletions src/Exceptional/ExceptionalRecursiveElementProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ExceptionalRecursiveElementProcessor : IRecursiveElementProcessor
{
#region member vars

private readonly CSharpDaemonStageProcessBase _daemonProcess;
private readonly List<IDocCommentBlock> _eventComments = new List<IDocCommentBlock>();

private IProcessContext _currentContext;
Expand All @@ -26,7 +25,6 @@ public class ExceptionalRecursiveElementProcessor : IRecursiveElementProcessor

public ExceptionalRecursiveElementProcessor(CSharpDaemonStageProcessBase daemonProcess)
{
_daemonProcess = daemonProcess;
_currentContext = new NullProcessContext();
}

Expand All @@ -41,112 +39,88 @@ public bool InteriorShouldBeProcessed(ITreeNode element)

public void ProcessAfterInterior(ITreeNode element)
{
if (element is IMethodDeclaration)
{
_currentContext.RunAnalyzers();
}
else if (element is IEventDeclaration)
{
_currentContext.RunAnalyzers();
}
else if (element is IAccessorOwnerDeclaration)
{
_currentContext.RunAnalyzers();
}
else if (element is IAccessorDeclaration)
{
//_currentContext.RunAnalyzers(_daemonProcess, _settings); // Already analyzed by accessor owner
_currentContext.LeaveAccessor();
}
else if (element is IConstructorDeclaration)
{
_currentContext.RunAnalyzers();
}
else if (element is ITryStatement)
{
_currentContext.LeaveTryBlock();
}
else if (element is ICatchClause)
{
_currentContext.LeaveCatchClause();
switch (element)
{
case IMethodDeclaration _:
case IEventDeclaration _:
case IAccessorOwnerDeclaration _:
_currentContext.RunAnalyzers();
break;
case IAccessorDeclaration _:
//_currentContext.RunAnalyzers(_daemonProcess, _settings); // Already analyzed by accessor owner
_currentContext.LeaveAccessor();
break;
case IConstructorDeclaration _:
_currentContext.RunAnalyzers();
break;
case ITryStatement _:
_currentContext.LeaveTryBlock();
break;
case ICatchClause _:
_currentContext.LeaveCatchClause();
break;
}
}

public void ProcessBeforeInterior(ITreeNode element)
{
if (element is IThrowStatement)
{
_currentContext.Process(element as IThrowStatement);
}
else if (element is ICatchVariableDeclaration)
{
_currentContext.Process(element as ICatchVariableDeclaration);
}
else if (element is IReferenceExpression)
{
_currentContext.Process(element as IReferenceExpression);
}
else if (element is IObjectCreationExpression)
{
_currentContext.Process(element as IObjectCreationExpression);
}
if (element is IMethodDeclaration)
{
var methodDeclaration = element as IMethodDeclaration;
_currentContext = new MethodProcessContext();
_currentContext.StartProcess(new MethodDeclarationModel(methodDeclaration));
}
else if (element is IConstructorDeclaration)
{
var constructorDeclaration = element as IConstructorDeclaration;
_currentContext = new ConstructorProcessContext();
_currentContext.StartProcess(new ConstructorDeclarationModel(constructorDeclaration));
}
else if (element is IEventDeclaration)
{
var eventDeclaration = element as IEventDeclaration;
_currentContext = new EventProcessContext();
_currentContext.StartProcess(new EventDeclarationModel(eventDeclaration));
foreach (var doc in _eventComments)
switch (element)
{
case IThrowStatement statement:
_currentContext.Process(statement);
break;
case ICatchVariableDeclaration declaration:
_currentContext.Process(declaration);
break;
case IReferenceExpression expression:
_currentContext.Process(expression);
break;
case IObjectCreationExpression creationExpression:
_currentContext.Process(creationExpression);
break;
case IMethodDeclaration methodDeclaration:
_currentContext = new MethodProcessContext();
_currentContext.StartProcess(new MethodDeclarationModel(methodDeclaration));
break;
case IConstructorDeclaration constructorDeclaration:
_currentContext = new ConstructorProcessContext();
_currentContext.StartProcess(new ConstructorDeclarationModel(constructorDeclaration));
break;
case IEventDeclaration eventDeclaration:
{
_currentContext.Process(doc);
_currentContext = new EventProcessContext();
_currentContext.StartProcess(new EventDeclarationModel(eventDeclaration));
foreach (var doc in _eventComments)
{
_currentContext.Process(doc);
}
_eventComments.Clear();
break;
}
_eventComments.Clear();
}
else if (element is IAccessorOwnerDeclaration)
{
var accessorOwnerDeclaration = element as IAccessorOwnerDeclaration;
_currentContext = new AccessorOwnerProcessContext();
_currentContext.StartProcess(new AccessorOwnerDeclarationModel(accessorOwnerDeclaration));
}
else if (element is IAccessorDeclaration)
{
_currentContext.EnterAccessor(element as IAccessorDeclaration);
}
else if (element is IDocCommentBlock)
{
if (_currentContext.Model == null || _currentContext.Model.Node == element.Parent)
{
_currentContext.Process(element as IDocCommentBlock);
}
else
{
_eventComments.Add((IDocCommentBlock)element);
case IAccessorOwnerDeclaration accessorOwnerDeclaration:
_currentContext = new AccessorOwnerProcessContext();
_currentContext.StartProcess(new AccessorOwnerDeclarationModel(accessorOwnerDeclaration));
break;
case IAccessorDeclaration declaration:
_currentContext.EnterAccessor(declaration);
break;
case IDocCommentBlock block when _currentContext.Model == null || _currentContext.Model.Node == block.Parent:
_currentContext.Process(block);
break;
case IDocCommentBlock block:
_eventComments.Add(block);
// HACK: Event documentation blocks are processed before event declaration,
// other documentation blocks are processed after the associated element declaration
}
}
else if (element is IThrowExpression)
{
_currentContext.Process(element as IThrowExpression);
}
else if (element is ITryStatement)
{
_currentContext.EnterTryBlock(element as ITryStatement);
}
else if (element is ICatchClause)
{
_currentContext.EnterCatchClause(element as ICatchClause);
break;
case IThrowExpression expression:
_currentContext.Process(expression);
break;
case ITryStatement tryStatement:
_currentContext.EnterTryBlock(tryStatement);
break;
case ICatchClause clause:
_currentContext.EnterCatchClause(clause);
break;
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/Exceptional/Models/CatchClauseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public void AddCatchVariable(string variableName)
var exceptionType = (IUserDeclaredTypeUsage)specificNode.ExceptionTypeUsage;
var exceptionTypeName = exceptionType.TypeName.NameIdentifier.Name;
var tempTry = GetElementFactory().CreateStatement("try {} catch($0 $1) {}", exceptionTypeName, variableName) as ITryStatement;
var tempCatch = tempTry?.Catches[0] as ISpecificCatchClause;
if (tempCatch == null)
if (!(tempTry?.Catches[0] is ISpecificCatchClause tempCatch))
{
return;
}
Expand All @@ -90,11 +89,7 @@ public bool Catches(IDeclaredType exception)
{
return false;
}
if (Node.ExceptionType == null)
{
return false;
}
return exception.IsSubtypeOf(Node.ExceptionType);
return Node?.ExceptionType != null && exception.IsSubtypeOf(Node.ExceptionType);
}

/// <summary>Checks whether the block catches the given exception. </summary>
Expand Down
19 changes: 10 additions & 9 deletions src/Exceptional/Models/ConstructorDeclarationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public ConstructorDeclarationModel(IConstructorDeclaration constructorDeclaratio
}
else
{
if (constructorDeclaration.DeclaredElement?.IsDefault == true)
if (constructorDeclaration.DeclaredElement?.IsDefault != true)
{
var containingType = constructorDeclaration.DeclaredElement.GetContainingType();
var baseClass = containingType?.GetSuperTypes().FirstOrDefault(t => !t.IsInterfaceType());
var baseClassTypeElement = baseClass?.GetTypeElement();
var defaultBaseConstructor = baseClassTypeElement?.Constructors.FirstOrDefault(c => c.IsDefault);
if (defaultBaseConstructor != null)
{
ThrownExceptions.Add(new ConstructorInitializerModel(this, defaultBaseConstructor, this));
}
return;
}
var containingType = constructorDeclaration.DeclaredElement.GetContainingType();
var baseClass = containingType?.GetSuperTypes().FirstOrDefault(t => !t.IsInterfaceType());
var baseClassTypeElement = baseClass?.GetTypeElement();
var defaultBaseConstructor = baseClassTypeElement?.Constructors.FirstOrDefault(c => c.IsDefault);
if (defaultBaseConstructor != null)
{
ThrownExceptions.Add(new ConstructorInitializerModel(this, defaultBaseConstructor, this));
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/Exceptional/Models/ThrownExceptionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ public bool IsExceptionOrSubtype(ExceptionDocCommentModel exceptionDocumentation
private void CheckAccessorOverride(IExceptionsOriginModel exceptionsOrigin, IDeclaredType exceptionType)
{
var doc = GetXmlDocId(exceptionsOrigin.Node);
if (doc != null)
if (doc == null)
{
var fullMethodName = Regex.Replace(doc.Substring(2), "(`[0-9]+)|(\\(.*?\\))", ""); // TODO: merge with other
var overrides = ServiceLocator.Settings.GetExceptionAccessorOverrides();
var ov = overrides.SingleOrDefault(o => o.FullMethodName == fullMethodName && o.GetExceptionType().Equals(exceptionType));
if (ov != null)
{
ExceptionAccessor = ov.ExceptionAccessor;
}
return;
}
var fullMethodName = Regex.Replace(doc.Substring(2), "(`[0-9]+)|(\\(.*?\\))", ""); // TODO: merge with other
var overrides = ServiceLocator.Settings.GetExceptionAccessorOverrides();
var ov = overrides.SingleOrDefault(o => o.FullMethodName == fullMethodName && o.GetExceptionType().Equals(exceptionType));
if (ov != null)
{
ExceptionAccessor = ov.ExceptionAccessor;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Exceptional/Models/ThrownExceptionsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static IEnumerable<ThrownExceptionModel> Read(
}
foreach (var declaration in declarations)
{
var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwner;
if (docCommentBlockOwnerNode == null)
if (!(declaration is IDocCommentBlockOwner docCommentBlockOwnerNode))
{
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptional/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
[assembly: System.Reflection.AssemblyDescription("Analyzes thrown and documented C# exceptions and suggests improvements.")]
[assembly: System.Reflection.AssemblyProduct("Exceptional")]
[assembly: System.Reflection.AssemblyCompany("Mahmoud Fakhoury -- The source project was developed by ExceptionalDevs")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © 2021 MF")]
[assembly: System.Reflection.AssemblyVersion("2021.3.0")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © 2022 MF")]
[assembly: System.Reflection.AssemblyVersion("2021.3.2")]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Runtime.InteropServices.Guid("3628d589-e118-4c2c-bd8e-fdef6b6ed07c")]

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptional/Settings/ExceptionAccessorOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public IDeclaredType GetExceptionType()
}
catch (Exception ex)
{
Logger.LogException(string.Format("[Exceptional] Error loading excluded method exception '{0}'", ExceptionType), ex);
Logger.LogException($"[Exceptional] Error loading excluded method exception '{ExceptionType}'", ex);
}
finally
{
Expand Down
Loading

0 comments on commit 271ed6c

Please sign in to comment.