-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix async method default return statements - fixes #478
- Loading branch information
1 parent
745007a
commit 1a7e389
Showing
8 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
using System.Linq; | ||
using ICSharpCode.CodeConverter.Util; | ||
using Microsoft.CodeAnalysis; | ||
using VBasic = Microsoft.CodeAnalysis.VisualBasic; | ||
using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax; | ||
|
||
namespace ICSharpCode.CodeConverter.CSharp | ||
{ | ||
internal static class VbMethodSyntaxExtensions | ||
{ | ||
public static bool AllowsImplicitReturn(this Microsoft.CodeAnalysis.VisualBasic.Syntax.MethodBlockBaseSyntax node) | ||
/// <summary> | ||
/// Use in conjunction with <see cref="IMethodSymbolExtensions.ReturnsVoidOrAsyncTask(IMethodSymbol)" /> | ||
/// </summary> | ||
public static bool MustReturn(this VBSyntax.MethodBlockBaseSyntax node) | ||
{ | ||
return !IsIterator(node) && node.IsKind(Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.FunctionBlock, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.GetAccessorBlock); | ||
return !IsIterator(node) && node.IsKind(VBasic.SyntaxKind.FunctionBlock, VBasic.SyntaxKind.GetAccessorBlock) | ||
&& !node.IsIterator(); | ||
} | ||
|
||
public static bool IsIterator(this Microsoft.CodeAnalysis.VisualBasic.Syntax.MethodBlockBaseSyntax node) | ||
public static bool IsIterator(this VBSyntax.MethodBlockBaseSyntax node) | ||
{ | ||
var modifiableNode = node.IsKind(Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.GetAccessorBlock) ? node.GetAncestor<Microsoft.CodeAnalysis.VisualBasic.Syntax.PropertyBlockSyntax>().PropertyStatement : node.BlockStatement; | ||
return HasIteratorModifier(modifiableNode); | ||
return GetMethodBlock(node).HasModifier(VBasic.SyntaxKind.IteratorKeyword); | ||
} | ||
|
||
private static bool HasIteratorModifier(this Microsoft.CodeAnalysis.VisualBasic.Syntax.MethodBaseSyntax d) | ||
public static bool HasModifier(this VBSyntax.MethodBaseSyntax d, VBasic.SyntaxKind modifierKind) | ||
{ | ||
return d.Modifiers.Any(m => SyntaxTokenExtensions.IsKind(m, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.IteratorKeyword)); | ||
return d.Modifiers.Any(m => SyntaxTokenExtensions.IsKind(m, modifierKind)); | ||
} | ||
|
||
private static VBSyntax.MethodBaseSyntax GetMethodBlock(VBSyntax.MethodBlockBaseSyntax node) | ||
{ | ||
return node.IsKind(VBasic.SyntaxKind.GetAccessorBlock) ? node.GetAncestor<VBSyntax.PropertyBlockSyntax>().PropertyStatement : node.BlockStatement; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters