Autocompletion in an Annotation
I'm working with a custom annotation that I'm looking to support, one of the values is a property path expression. I got the RefrenceProvider to work, but it looks like if I want the full auto-complete experience it looks like I have to use a MultiHostInjector, but my problem lies in the fact there is no grammar that I can find that supports a basic style property path expression ie: "object.property.name" and all the tutorials are using a full blown grammar. I just need to parse valid Java Identifiers and dots. Is there a simple way to go about this?
I have experience with Antlr but there isn't a real clear way to use it properly that isn't outdated.
Please sign in to leave a comment.
Your title and description are a bit confusing. Let me take this from it
I just need to parse valid Java Identifiers and dots. Is there a simple way to go about this?
A java identifier doesn't need to be parsed. It's enough to use a regex. What you want is to have a look at
As Patrick noted, you can parse the expression manually using regexes or something even simpler. Then, to get code completion (and also Goto Declaration) you can add references at the ranges corresponding to the identifiers. For that, you should implement a PsiReferenceContributor extension and create PsiReferenceBase objects there, with "resolve" method responsible for goto declaration and "getVariants" for completion.
@Peter and @Patrick I have implemented a reference contributor but I think I need to tokenize and parse the String literal to get auto completion to work similar to ie: Spring SpEL
Spring EL is a full-blown language with lexer, parser, highlighter, PSI, injection, etc. If you think you need this, go on. But you might not need this, and just contribute the references into a string literal (like JavaClassReferenceSet and FileReferenceSet do). It's up to you to decide.
@Peter and @Patrick, Come to figure out the order of the Reference Contributors is why it wasn't working. Since it was in an annotation, it would cause an early return. Auto-Complete with a Pop-up now works.