https://kotlinlang.org logo
#intellij
Title
# intellij
s

sreich

07/08/2022, 12:45 PM
I have a search template of
$Before$.$MethodCall$($Parameter$)
, problem is..it matches on
<http://log.info|log.info> { }
as well as
<http://log.info|log.info> ()
, how can i get it to not match on lambda? I set complete match but it still doesn't listen to me, i want it to take the parentheses as is
r

Roukanken

07/08/2022, 2:18 PM
remember that's it is a structural search, and therefore it searches based on structure of the syntax tree. Eg, from AST view,
<http://log.info|log.info> { }
is same as
<http://log.info|log.info>({ })
- and
{ }
gets matched to your
$Parameter$
how to solve it hmmm... I guess only way is to limit what can get matched as parameter. Limiting its type should help you I guess?
s

sreich

07/08/2022, 2:23 PM
@Roukanken so, that's the part that confuses me..if you look at the builtin kotlin ones, you get
{ $Parameter$ }
, this matches
<http://log.info|log.info> {}
only
but it seems like if you surround it with other stuff, maybe...it doesn't seem to work the same
if the AST thing you mention were true, it should have matched on my braces, in my original test case, as it does for the builtin example
r

Roukanken

07/08/2022, 2:28 PM
remember that
func { }
is just a syntax sugar for
func( { } )
they have the exact same meaning which means ASTs look something like this: •
func { }
AST is: ◦ call a method (taken from whatever is
func
) and give it as parameters: ▪︎ lambda function •
func({ })
AST is same ↑ •
func { $parameter$ }
is: ◦ call a method (taken from whatever is
func
) and give it as parameters: ▪︎ lambda function • of which content is "return `$parameter$`"
s

sreich

07/08/2022, 2:31 PM
yeah i get that part, but i'm saying that it is matching on
{}
which matches
log.debug {}
, and not
log.debug()
. so it definitely treats it differently
r

Roukanken

07/08/2022, 3:09 PM
okay, I took out the big guns, and surprisingly there is a difference between 1st and 2nd This should be the tree JB is operating on
s

sreich

07/08/2022, 3:25 PM
hm interesting. thank you. shall i raise a youtrack issue?
r

Roukanken

07/08/2022, 3:27 PM
I'm reasonably sure this is an intended behaviour (as it would make more sense) but yeah, this basically stops you from matching what you want also fun is that
<http://log.info|log.info> { $x$ }
matches only the first one but
<http://log.info|log.info>({ $x$ })
matches both
s

sreich

07/08/2022, 5:23 PM
haha right?
it's hilarious becuase it's matching everything i don't want. i just want to match parentheses 😂
@Roukanken btw how do you view the AST like that? also, nice color scheme
r

Roukanken

07/08/2022, 6:15 PM
It's a plugin (PSI viewer I think?) mostly meant for coding plugins to manipulate code. It shows internal tree of code
s

sreich

07/08/2022, 6:16 PM
okay, cool
r

Roukanken

07/08/2022, 6:20 PM
(and theme is Palenight, from Material UI)
👍 1