Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageElement .toString() #3

Open
regbo opened this issue Aug 15, 2022 · 2 comments
Open

PackageElement .toString() #3

regbo opened this issue Aug 15, 2022 · 2 comments

Comments

@regbo
Copy link

regbo commented Aug 15, 2022

I don't know if it's my maven setup, windows, or my JVM, but this block of code leads to errors:

 private String _getPackage(Element pElement)
    {
      Element element = pElement;
      while (element != null)
      {
        if (element.getKind() == ElementKind.PACKAGE)
          return element.toString();
        Element enclosingElement = element.getEnclosingElement();
        if (ENCLOSING_TYPES.contains(enclosingElement.getKind()))
          element = enclosingElement;
        else
        {
          processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Element type not supported", pElement);
          break;
        }
      }
      return "";
    }

In my setup, the element.toString returns "package com.x.y.z" when it sould be "com.x.y.z"

I remedied this with:

private String _getPackage(Element pElement)
    {
      Element element = pElement;
      while (element != null)
      {
        if (element.getKind() == ElementKind.PACKAGE)
          return ((javax.lang.model.element.PackageElement)element).getQualifiedName().toString();
        Element enclosingElement = element.getEnclosingElement();
        if (ENCLOSING_TYPES.contains(enclosingElement.getKind()))
          element = enclosingElement;
        else
        {
          processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Element type not supported", pElement);
          break;
        }
      }
      return "";
    }
@jboesl
Copy link
Member

jboesl commented Aug 16, 2022

Thanks for the report. I'll look into it.

jboesl added a commit that referenced this issue Aug 16, 2022
@jboesl
Copy link
Member

jboesl commented Aug 16, 2022

Fix is pushed. Please test it and then I'll release it on maven.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants