Injection in Java constructors and annotations for Scala
I am trying write a custom language injection rule for an SQL-like language in Scala, and having trouble in two cases:
1) if the language is being injected as a parameter of a constructor of a Java class, and
2) if it is a parameter of a Java annotation
The language grammar is implemented and injection is working correctly in Scala methods and methods/constructors in Java. But in both of my cases, the language does not get recognized, and manual injection doesn't add any rules (adds injection temporarily).
1) Imagine I have a TestMyInjection Java class with a
TestMyInjection(String query)
constructor. Here's what I am trying to do:
+ scalaLiteral().callArgument(0, psiMethod().withName("TestMyInjection").withParameters("java.lang.String").definedInClass("com.example.inject.TestMyInjection"))
I used the built in
+ scalaLiteral().callArgument(1, psiMethod().withName("BatchSqlUpdate").withParameters("javax.sql.DataSource", "java.lang.String").definedInClass("org.springframework.jdbc.object.BatchSqlUpdate"))
example as a reference.
What is the correct way to do this? Can I use other approaches?
2) Say I have a Java annotation:
public @interface Query {
java.lang.String VALUE = "value";
java.lang.String value() default "";
}
And, I am using it like this, in Scala:
trait MyRepository {
@Query("SELECT ... FROM ... SOMETHINGELSE ...")
def myMethod()
}
Again, the language does not get recognized. I tried using
+ psiMethod().withName("value").withParameters().definedInClass("com.example.Query")
as well as
+ psiAnnotation().qName(...
, but as I've noticed, the annotation does get recognized as a PsiAnnotation in Java only.
What is the correct way to inject a language in an annotation in case of Scala?
Please sign in to leave a comment.
It is not supported yet in Scala plugin:
https://youtrack.jetbrains.com/issue/SCL-14607
You may vote for the issue to get progress notification. I think we'll implement it soon.