Registering JAM w/ annotation for PsiPackageStatement in package-info.java

Does it work at all? If yes, would someone share their might ElementPattern for SemRegistrar? :-) Thanks

0

Nobody has needed this until now. I believe that the JAM should hang on
a PsiPackage object. As for the pattern, you can create it yourself.

0

    JamParentPackage.META_P.register(registrar, PsiJavaPatterns.psiElement(PsiPackage.class));


where META_P is as follows in com.intellij.struts2.model.jam.convention.JamParentPackage

  public static final JamMemberMeta<PsiPackage, JamParentPackage> META_P = new JamMemberMeta<PsiPackage, JamParentPackage>(
    null, JamParentPackage.class).addAnnotation(PARENT_PACKAGE_META);


does not work.. I tried a couple of other possibilities via PsiPackageStatement, but no success.. any hints?

0

Spent 2 minutes on the following and it looks like everything works just fine:


// jam class
public class MappedPackageImpl implements JamElement {
  private final PsiPackage myPsiPackage;

  public MappedPackageImpl(final PsiPackage psiPackage) {
    myPsiPackage = psiPackage;
  }
}


// meta declaration
public static final JamMemberMeta<PsiPackage, MappedPackageImpl> PACKAGE_META =
    new JamMemberMeta<PsiPackage,MappedPackageImpl>(null, MappedPackageImpl.class);


// part of Jam contributor:
PACKAGE_META.register(registrar, psiElement(PsiPackage.class));

// Now this call returns the Jam element for the package.
PACKAGE_META.getJamElement(JavaPsiFacade.getInstance(project).findPackage("com"))

0

Gregory,

thanks for your feedback.

Indeed, binding and finding the JamReference works (verified for my example).

I was unclear about what does not work: trying to bind the JamSimpleReferenceConverter to the annotation in the context of package-info.java. It does work on PsiClass level, but it seems like ReferenceProvider is not registered at all/not properly for package-info.java context (I only get PsiProperty completion). Could you verify this behaviour?

Thanks,

Yan

0

Another question: using JamSimpleReferenceConverter should enable "backwards" find usages from XML to reference in Package-parameter? It seems this doesn't work for me (seecom.intellij.struts2.model.jam.convention.JamParentPackage#STRUTS_PACKAGE_JAM_CONVERTER). Do I have to provide anything else?

Thanks,

Yann

0

Indeed, there's problem with JAM package support. I've just committed a fix that should enable JamConverters.

Important: JamPackageMeta should be used instead of JamMemberMeta.

0

Great, thanks for the quick fix!


0

may I suggest to add "target"-parameter in UOE-message from com.intellij.jam.JamSimpleReferenceConverter#createLookupElementFor

0

For anyone else struggling with references to DOM-elements from JAM: let your DomElement extend com.intellij.javaee.model.xml.impl.BaseImpl where all the nasty magic happens

0

请先登录再写评论。