Skip to content

Commit

Permalink
added method to verify if the method in a method call belongs to a QA…
Browse files Browse the repository at this point in the history
…ctionTable subclass (#33)
  • Loading branch information
PedroDebevere authored Sep 13, 2024
1 parent 64d3571 commit a51ea39
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Common/Classes/CallingMethodClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@ private CallingMethodClass(InvocationExpressionSyntax node) : base(node)
public List<Argument> Arguments { get; }

/// <summary>
/// Returns the Fully Qualified Name of the Parent. Or null in case it couldn't be resolved.
/// Returns the Fully Qualified Name of the Parent. Or null in case it could not be resolved.
/// </summary>
/// <param name="semanticModel">The semantic model.</param>
public string GetFullyQualifiedNameOfParent(SemanticModel semanticModel)
{
return RoslynHelper.GetFullyQualifiedName(semanticModel, SyntaxNode.Expression);
}

/// <summary>
/// Returns the type symbol of the parent.
/// </summary>
/// <param name="semanticModel">The semantic model.</param>
/// <returns>The type symbol of the parent or <see langword="null"/> in case it could not be resolved.</returns>
public ITypeSymbol GetTypeSymbol(SemanticModel semanticModel)
{
return RoslynHelper.GetTypeSymbol(semanticModel, SyntaxNode.Expression);
}

/// <summary>
/// Returns a value indicating whether the parent is of the specified type.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions Common/RoslynHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,5 +928,29 @@ public static string GetFullyQualifiedName(SemanticModel semanticModel, Expressi
ITypeSymbol symbol = semanticModel.GetTypeInfo(expression).Type;
return symbol?.ToDisplayString(symbolDisplayFormat);
}

/// <summary>
/// Gets the type symbol of the specified expression.
/// </summary>
/// <param name="semanticModel">The semantic model.</param>
/// <param name="expression">The expression.</param>
/// <returns>The type symbol.</returns>
public static ITypeSymbol GetTypeSymbol(SemanticModel semanticModel, ExpressionSyntax expression)
{
if (expression is MemberAccessExpressionSyntax maes)
{
ITypeSymbol argSymbol = semanticModel.GetTypeInfo(maes.Expression).Type;
return argSymbol;
}

if (expression is InvocationExpressionSyntax ies)
{
ITypeSymbol argSymbol = semanticModel.GetTypeInfo(ies.Expression).Type;
return argSymbol;
}

ITypeSymbol symbol = semanticModel.GetTypeInfo(expression).Type;
return symbol;
}
}
}
18 changes: 18 additions & 0 deletions Protocol/QActionAnalysisHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ public static bool IsSLProtocol(this CallingMethodClass callingMethod, SemanticM
String.Equals(fqn, "Skyline.DataMiner.Scripting.SLProtocolExt");
}

/// <summary>
/// Determines whether the calling method is a method of a QActionTable subclass.
/// </summary>
/// <param name="callingMethod">The calling method.</param>
/// <param name="semanticModel">The semantic model.</param>
/// <returns><c>true</c> if the calling method is a method of a QActionTable subclass; otherwise, <c>false</c>.</returns>
public static bool IsProtocolExtTable(this CallingMethodClass callingMethod, SemanticModel semanticModel)
{
var typeSymbol = callingMethod.GetTypeSymbol(semanticModel);

if (typeSymbol?.BaseType != null && typeSymbol.BaseType.IsType && typeSymbol.BaseType.ToString().Equals("Skyline.DataMiner.Scripting.QActionTable", StringComparison.Ordinal))
{
return true;
}

return false;
}

/// <summary>
/// Checks if the parameter/argument of a method is the SLProtocol or SLProtocolExt interface.
/// </summary>
Expand Down

0 comments on commit a51ea39

Please sign in to comment.