Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2150 from Hosch250/Issue2135
Give Write Only Property a custom quick fix
- Loading branch information
Showing
6 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Linq; | ||
using Antlr4.Runtime; | ||
using Rubberduck.Parsing.Grammar; | ||
using Rubberduck.Parsing.Symbols; | ||
|
||
namespace Rubberduck.Inspections | ||
{ | ||
public class WriteOnlyPropertyQuickFix : CodeInspectionQuickFix | ||
{ | ||
private readonly Declaration _target; | ||
|
||
public WriteOnlyPropertyQuickFix(ParserRuleContext context, Declaration target) | ||
: base(context, target.QualifiedSelection, InspectionsUI.WriteOnlyPropertyQuickFix) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public override void Fix() | ||
{ | ||
var parameters = ((IDeclarationWithParameter) _target).Parameters.Cast<ParameterDeclaration>().ToList(); | ||
|
||
var signatureParams = parameters.Except(new[] {parameters.Last()}).Select(GetParamText); | ||
var propertyGet = "Public Property Get " + _target.IdentifierName + "(" + string.Join(", ", signatureParams) + | ||
") As " + parameters.Last().AsTypeName + Environment.NewLine + "End Property"; | ||
|
||
var module = _target.QualifiedName.QualifiedModuleName.Component.CodeModule; | ||
module.InsertLines(_target.Selection.StartLine, propertyGet); | ||
} | ||
|
||
private string GetParamText(ParameterDeclaration param) | ||
{ | ||
return (((VBAParser.ArgContext)param.Context).BYVAL() == null ? "ByRef " : "ByVal ") + param.IdentifierName + " As " + param.AsTypeName; | ||
} | ||
} | ||
} |
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