intellij-postfix-templates icon indicating copy to clipboard operation
intellij-postfix-templates copied to clipboard

Allow templates on types in Scala

Open crater2150 opened this issue 6 years ago • 2 comments

I'd like to create templates that work on types instead of expressions. E.g. I tried:

.seqT : wrap type in Seq[ ]
    ANY → Seq[$expr$]

to achieve something like def foo(x: Bar.seq) -> def foo(x: Seq[Bar]) but the .seqT template is not available in this context.

crater2150 avatar Mar 14 '18 10:03 crater2150

Correct. Types/classes are currently not supported as MATCHING_TYPE.

I have to look into it to see what I can do.

xylo avatar Mar 14 '18 12:03 xylo

OK, this is unfortunately not easy to implement, because one has to replace the AncestorSelector in https://github.com/xylo/intellij-postfix-templates/blob/0f5a054b3652b7ab8baa46796bd293f3762fb4d9/src/de/endrullis/idea/postfixtemplates/languages/scala/CustomScalaStringPostfixTemplate.java#L75 with one that does not filter out the CodeReferenceElement. Unfortunately, AncestorSelector is not written in Java, so I cannot just adapt the code to make it work. Instead one has to convert the whole class to Java and adapt it or adapt the Scala file and somehow manage to import it into the plugin. Both solutions are very cumbersome and takes probably days of work. So I give up here. Sorry. But I keep the ticket open in case that someone else is willing to implement this feature.

xylo avatar Mar 15 '18 20:03 xylo