Property auto completion for Orika mapper
Hi,
I'd like to write a small plugin to enable property auto completion for the Orika Mapping Framework.
A mapping usually looks like this:
mapperFactory.classMap(PersonSource.class, PersonDestination.class)
.field("firstName", "givenName")
.field("lastName", "sirName")
.byDefault()
.register();
`classMap(Class<A> a, Class<B>b)` returns a ClassMapBuilder<A, B> then mapping for fields is defined by invoking the field, fieldAtoB, or fieldBtoA methods. Nested fields can be accessed via '.' eg, field("address.street", "street")
What I'd like to to is to enable auto completion support for the properties of the classes. Since the ClassMapBuilder has the generic type information it should be possible to access that.
In a later stage I'd also like to add support for the advanced "in-line property syntax" https://orika-mapper.github.io/orika-docs/advanced-mappings.html
In-line property syntax:
«name» :{ «getter» | «setter» [ | type= «type» ] }
«name» :{ «getter» [ | type= «type» ] }
«name» :{| «setter» [ | type= «type» ] }
I'm looking for pointers on where to start, first and foremost it should work for Java, but if it easily done then Groovy and Kotlin support would be nice too. I think that it should work like the Regex Language injection works, that automatically is applied for Pattern.compile("regex").
I've found Custom Language Support Tutorial but I'm not sure if that is really the right way, since I don't really want to create a new language with file-types and so on.
Please sign in to leave a comment.
The best solution for that seems to be to add a reference to such string literals, make its "resolve" navigate to the field/property declaration and make its "getVariants" return all possible values. For a similar example, you can look at how Java reflection references are implemented: https://github.com/JetBrains/intellij-community/blob/77ad294a3dd445878c8d1f4bed63fb8873739c93/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/JavaReflectionReferenceContributor.java