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

10 comments
Comment actions Permalink

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
Comment actions Permalink

    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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

Great, thanks for the quick fix!


0
Comment actions Permalink

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

0
Comment actions Permalink

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

Please sign in to leave a comment.