How to retrieve value of variable argument at runtime in visitMethodInvocation method.

51 views
Skip to first unread message

Madhuri Rane

unread,
May 29, 2018, 4:47:50 AM5/29/18
to SonarQube
I have test file as below:-
class SampleClass {
private String strCommand;
public void formStrCommand()
{
strCommand = "type trace mql on;trigger on;type trace mql on;"
}
int runCommand(Context context) {
str = MqlUtil.mqlCommand(context, strCommand, true);
}
}

I have custom rule with below overridden method:-

public void visitMethodInvocation(MethodInvocationTree tree) {
if (tree.methodSelect().is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) tree.methodSelect();
String expr = memberSelect.expression().toString();
String idnfier = memberSelect.identifier().name();

Arguments args = (Arguments) tree.arguments();
// If the args[1] is LiteralTree I am good to get value of args[1]
// But if it is a variable / identifier, how can the value inside it be retrieved?
// In below example, how can I retrieve value of 'strCommand' in visitMethodInvocation() method ?
}
}

How can I retrieve value of variable argument at runtime in visitMethodInvocation method ?

Andrei Epure

unread,
Jun 8, 2018, 12:05:57 PM6/8/18
to SonarQube
Hi Madhuri,

You cannot, as our products do static analysis.

Thanks,
Andrei
Reply all
Reply to author
Forward
0 new messages