Skip to content

Commit 1b7246f

Browse files
committed
Refactoring to use Utilities class for generic methods
1 parent f39fd47 commit 1b7246f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/PowerShellEditorServices/Services/PowerShell/Refactoring/IterativeFunctionVistor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Management.Automation.Language;
66
using Microsoft.PowerShell.EditorServices.Handlers;
7-
using System.Linq;
87

98
namespace Microsoft.PowerShell.EditorServices.Refactoring
109
{
@@ -31,7 +30,8 @@ public IterativeFunctionRename(string OldName, string NewName, int StartLineNumb
3130
this.StartColumnNumber = StartColumnNumber;
3231
this.ScriptAst = ScriptAst;
3332

34-
Ast Node = Utilities.GetAstNodeByLineAndColumn(StartLineNumber, StartColumnNumber, ScriptAst, typeof(FunctionDefinitionAst), typeof(CommandAst));
33+
Ast Node = Utilities.GetAstNodeByLineAndColumn(StartLineNumber, StartColumnNumber, ScriptAst,
34+
typeof(FunctionDefinitionAst), typeof(CommandAst));
3535

3636
if (Node != null)
3737
{
@@ -41,7 +41,7 @@ public IterativeFunctionRename(string OldName, string NewName, int StartLineNumb
4141
}
4242
if (Node is CommandAst commdef && commdef.GetCommandName().ToLower() == OldName.ToLower())
4343
{
44-
TargetFunctionAst = GetFunctionDefByCommandAst(OldName, StartLineNumber, StartColumnNumber, ScriptAst);
44+
TargetFunctionAst = Utilities.GetFunctionDefByCommandAst(OldName, StartLineNumber, StartColumnNumber, ScriptAst);
4545
if (TargetFunctionAst == null)
4646
{
4747
throw new FunctionDefinitionNotFoundException();

src/PowerShellEditorServices/Services/PowerShell/Refactoring/IterativeVariableVisitor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public IterativeVariableRename(string NewName, int StartLineNumber, int StartCol
4343
isParam = true;
4444
Ast parent = Node;
4545
// Look for a target function that the parameterAst will be within if it exists
46-
parent = Utilities.LookForParentOfType(parent,typeof(FunctionDefinitionAst));
46+
parent = Utilities.LookForParentOfType(parent, typeof(FunctionDefinitionAst));
4747
if (parent != null)
4848
{
4949
TargetFunction = (FunctionDefinitionAst)parent;
@@ -61,7 +61,7 @@ public static Ast GetVariableTopAssignment(int StartLineNumber, int StartColumnN
6161

6262
// Look up the target object
6363
Ast node = Utilities.GetAstNodeByLineAndColumn(StartLineNumber, StartColumnNumber,
64-
ScriptAst,typeof(VariableExpressionAst), typeof(CommandParameterAst), typeof(StringConstantExpressionAst));
64+
ScriptAst, typeof(VariableExpressionAst), typeof(CommandParameterAst), typeof(StringConstantExpressionAst));
6565

6666
string name = node switch
6767
{
@@ -77,7 +77,7 @@ public static Ast GetVariableTopAssignment(int StartLineNumber, int StartColumnN
7777
if (node is StringConstantExpressionAst)
7878
{
7979
Ast parent = node;
80-
parent = Utilities.LookForParentOfType(parent,typeof(AssignmentStatementAst));
80+
parent = Utilities.LookForParentOfType(parent, typeof(AssignmentStatementAst));
8181
if (parent is not null and AssignmentStatementAst assignmentStatementAst)
8282
{
8383
splatAssignment = (VariableExpressionAst)assignmentStatementAst.Left.Find(
@@ -181,7 +181,7 @@ internal static Ast GetAstParentScope(Ast node)
181181
{
182182
Ast parent = node;
183183
// Walk backwards up the tree looking for a ScriptBLock of a FunctionDefinition
184-
parent = Utilities.LookForParentOfType(parent,typeof(ScriptBlockAst),typeof(FunctionDefinitionAst));
184+
parent = Utilities.LookForParentOfType(parent, typeof(ScriptBlockAst), typeof(FunctionDefinitionAst));
185185
if (parent is ScriptBlockAst && parent.Parent != null && parent.Parent is FunctionDefinitionAst)
186186
{
187187
parent = parent.Parent;

0 commit comments

Comments
 (0)