methodcall ========== .. include:: /ref/targets/autogen/descriptions/methodcall.txt .. contents:: Configuration options --------------------- type ~~~~ Checks the type which the method is called on. In case of a static method call .. code-block:: yaml search: methodcall: type: MyClass .. code-block:: java :emphasize-lines: 3 public void example() { MyClass m = new MyClass(); m.someMethod(); } .. code-block:: java :emphasize-lines: 2 public void example() { MyClass.someStaticMethod(); } .. seealso:: The examples above use shorthands, see :doc:`type` target for more advanced configurations name ~~~~ Matches the name of the method. .. code-block:: yaml search: methodcall: name: someMethod .. code-block:: java :emphasize-lines: 3 public void example() { MyClass m = new MyClass(); m.someMethod(); } .. code-block:: java :emphasize-lines: 2 public void example() { MyStaticClass.someMethod(); } .. seealso:: The examples above use shorthands, see :doc:`string` target for more advanced configurations declaration ~~~~~~~~~~~ The place where the method is defined will be resolved and matched against a :doc:`method` target. .. code-block:: yaml search: methodcall: declaration: annotation: type: "SomeAnnotation" .. code-block:: java :emphasize-lines: 6 @SomeAnnotation public void action() { } public void doSomething() { this.action(); } returnType ~~~~~~~~~~ Checks the return type of a method. .. code-block:: yaml search: methodcall: returnType: String .. code-block:: java :emphasize-lines: 5 public String action() { } public void doSomething() { String test = this.action(); } .. code-block:: java :emphasize-lines: 5 public String action() { } public void doSomething() { Object test = this.action(); } Note that we don't check the type of the variable that the result value is assigned to. Instead we check the actual return type of the method call. .. seealso:: The examples above use shorthands, see :doc:`type` target for more advanced configurations args ~~~~ Checks the arguments of the method call. This option is configured as a list of :doc:`argument` targets. There is a possibility to specific match a certain argument (based on the position) or to choose the ``any`` match. .. code-block:: yaml search: methodcall: args: 1: value: "1" 2: value: "2" .. code-block:: java :emphasize-lines: 5 public void action(int a, int b) { } public void doSomething() { this.action(1, 2); } argCount ~~~~~~~~ Checks the number of arguments .. code-block:: yaml search: methodcall: argCount: 2 .. code-block:: java :emphasize-lines: 5 public void action(int a, int b) { } public void doSomething() { this.action(1, 2); } .. seealso:: The examples above use shorthands, see :doc:`integer` target for more advanced configurations on ~~ Looks at the declaration of the instance that this object has been called on. This option can be used to search for instances where method chaining or builder patterns are used. .. code-block:: yaml search: methodcall: name: equals on: methodcall name: toLower .. code-block:: java :emphasize-lines: 2 public bool matches(String input) { return input.toLower().equals("sensei"); } As seen in the example, the ``on`` allows the user to specify another target. See :doc:`/ref/targets` for all available options. The examples also indicate a common case for this type of configuration, where we want to search for consecutive method calls that can be replaced by a single, more robust one. In this example, we could replace this into a single method call ``equalsIgnoreCase``. .. include:: /ref/targets/partials/objectcreator.txt