Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Basic implementation cleanup #24

Merged
merged 4 commits into from
Nov 19, 2014
Merged
Changes from all commits
Commits
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
19 changes: 6 additions & 13 deletions src/NullParameterCheckRefactoring.VB/CodeRefactoringProvider.vb
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,22 @@ Friend Class NullCheck_CodeRefactoringCodeRefactoringProvider
parameterStmt As ParameterSyntax,
method As MethodBlockSyntax,
cancellationToken As CancellationToken) As Task(Of Document)
Dim _null_ = SyntaxFactory.NothingLiteralExpression(SyntaxFactory.Token(SyntaxKind.NothingKeyword))
Dim _IsExpr_ = SyntaxFactory.IsExpression(
SyntaxFactory.IdentifierName(parameterStmt.Identifier.Identifier.Text),
_null_).WithAdditionalAnnotations(Formatting.Formatter.Annotation)
SyntaxFactory.NothingLiteralExpression(SyntaxFactory.Token(SyntaxKind.NothingKeyword)))
' Note: If I can find the nameof feature in VB.net, then I'll change this line to reflect that
Dim _paramname_ = SyntaxFactory.StringLiteralExpression(
SyntaxFactory.StringLiteralToken("""" & parameterStmt.Identifier.Identifier.Text & """",
parameterStmt.Identifier.Identifier.Text))
Dim st = SyntaxFactory.ObjectCreationExpression(Nothing,
SyntaxFactory.ParseTypeName(GetType(ArgumentNullException).FullName),
SyntaxFactory.ArgumentList().AddArguments(
SyntaxFactory.SimpleArgument(_paramname_)
),
Nothing)
SyntaxFactory.Literal(parameterStmt.Identifier.Identifier.Text))
Dim st = SyntaxFactory.ObjectCreationExpression(
SyntaxFactory.ParseTypeName(GetType(ArgumentNullException).FullName)).WithArgumentList(
SyntaxFactory.ArgumentList().AddArguments(SyntaxFactory.SimpleArgument(_paramname_)))

Dim throwExpr = SyntaxFactory.ThrowStatement(st)

Dim if_ = SyntaxFactory.SingleLineIfStatement(
SyntaxFactory.Token(SyntaxKind.IfKeyword),
_IsExpr_,
SyntaxFactory.Token(SyntaxKind.ThenKeyword),
New SyntaxList(Of StatementSyntax)().Add(throwExpr),
Nothing).WithAdditionalAnnotations(Formatting.Formatter.Annotation)
Nothing).WithAdditionalAnnotations(Formatting.Formatter.Annotation, Simplification.Simplifier.Annotation)

Dim newStatements = method.Statements.Insert(0, if_)
Dim newBlock = method.WithStatements(newStatements)
Expand Down