How to implement code completion for annotation's array parameter?
I have implemented code completion for annotation's string parameter with following code:
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(
registrar.registerReferenceProvider(
PsiJavaPatterns.literalExpression().annotationParam("org.unitils.dbunit.annotation.DataSet", "value"), new URIReferenceProvider(), PsiReferenceRegistrar.HIGHER_PRIORITY);
}
The above code code can work for @DataSet("xxx.xml"), but I can not work for array type. No completion for @ DataSet({"xxx.xml"}), Any idea?
code for @DataSet
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Inherited
public @interface DataSet {
/**
* The file name of the data set. If left empty, the default filename will
* be used: first 'classname'.'testMethodname'.xml will be tried, if that file does not exist,
* 'classname'.xml is tried. If that file also does not exist, an exception is thrown.
*
* @return the fileName, empty for default
*/
String[] value() default {};
}
Please sign in to leave a comment.
Got it please igore it.
registrar.registerReferenceProvider(PsiJavaPatterns.literalExpression().insideAnnotationParam(
PlatformPatterns.string().with(new PatternCondition<String>("DataSet") {
public boolean accepts(@NotNull final String annotationFQN, final ProcessingContext context) {
return annotationFQN.equals("org.unitils.dbunit.annotation.DataSet");
}
}), "value"), new URIReferenceProvider());