Writing a new custom Java Rule to find a method invocation

I am trying to implement some custom rules using java, and I’m having trouble to implement a rule which require me to gather all the invocation of a certain method say Methodone(). I am also need to find the object name which invokes this method. Please help me

Hello,

There is a lot of missing info here… If you want to get some help, you’ll need to help us helping you.

  • What language are you targeting?
  • What did you try already?
  • If it’s Java, did you follow the tutorial?
  • Can you provide the code of your rule? (or equivalent if it can not be shared publicly)
  • Can you provide the test code you are targeting with your rule? (again, anonymized if needed)

Regards,
Michael

Sorry for writing such a vague question. Full details here

Targeting language is Java

I am trying to find whether a method is invoked or not
Targeting code:

int testlab = labOps.createlab(args..);

I need to find whether createlab(args..) method is invoked or not.

My test code

public List<Tree.Kind> nodesToVisit() {
		    // Register to the kind of nodes you want to be called upon visit.
		    return ImmutableList.of(
		    		    		Tree.Kind.METHOD_INVOCATION);
		    		
		  }

		  @Override
		  public void visitNode(Tree tree) {

                  if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
		    	
		      MethodInvocationTree mit = (MethodInvocationTree) tree;
	              String mname = mit.symbol().name();
                      System.out.println("Invoked Method  "+ mname );
                      }
                }

The above code is not returning the method name createlab(args..).
I also need to find the variable name “testlab” which is invoking this method and also the list of arguments passed to that method

I followed the tutorial and based on that I have written the above code.

1 Like

What is this line returning ?

the code above returning null