Structural Search to match method call with generic parameter

◇◆丶佛笑我妖孽 提交于 2020-01-14 02:10:34

问题


Let's say that I have a class class Foo : Base and I want to perform a certain method call with signature

public void someStuf(Iterable<? extends Base> param)

For the search template I just take as starting point the pre-existing one

$Instance$.$MethodCall$($Parameter$)

Is it possible to match a parameter of any kind Iterable of a specific Base subclass (Foo in this example)??

List<Foo> fooList = new ArrayList<>();
fooList.add(new Foo("A"));
List<Bar> barList = new ArrayList<>();
barList.add(new Bar(1));

someStuff(fooList); // find this!
someStuff(barList); // don't find this one
someStuff(Collections.singletonList(new Foo("B"))); // also match this one

I've tried several combinations without any luck, is it even possible to do?


回答1:


This is currently not possible without resorting to hack. The trick is use a script constraint:

search template

$Instance$.$MethodCall$($Parameter$)

variables

$Instance$ min/max count: 0,1
$MethodCall text/regexp: someStuff
$Parameter$ script text: __context__.type.parameters[0].presentableText.contains("Foo"), expression type: List

I have submitted a bug report.



来源:https://stackoverflow.com/questions/45882590/structural-search-to-match-method-call-with-generic-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!