Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Getting annotations from package-info.java via IType
Getting annotations from package-info.java via IType [message #1707210] Thu, 03 September 2015 02:35 Go to next message
Eclipse UserFriend
I am trying to get list of annotation defined above package-info.

IType mytype = javaProject.findType("mypackage.package-info");
mytype.getAnnotations();



package-info.java looks like this:

@XmlJavaTypeAdapters(...),
})
package mypackage;

import someimport;




getting exception (on getAnnotations()):

Java Model Exception: Java Model Status [package-info [in package-info.java [in mypackage [in src/main/java [in TEST_Proj]]]] does not exist]

Re: Getting annotations from package-info.java via IType [message #1707319 is a reply to message #1707210] Thu, 03 September 2015 12:59 Go to previous messageGo to next message
Eclipse UserFriend
package-info isn't a type, so you can't get an IType for it.

Can you get an IPackageDeclaration for mypackage? That implements IAnnotatable, just like IType.
Re: Getting annotations from package-info.java via IType [message #1707328 is a reply to message #1707319] Thu, 03 September 2015 14:45 Go to previous messageGo to next message
Eclipse UserFriend
But mytype is not null, it doesn't fail on that line.

It fails on mytype.getAnnotations();
Re: Getting annotations from package-info.java via IType [message #1707335 is a reply to message #1707328] Thu, 03 September 2015 15:41 Go to previous messageGo to next message
Eclipse UserFriend
Look at your code. Notice that the annotations that you're trying to get are actually on the package declaration. There is no package-info type.
Re: Getting annotations from package-info.java via IType [message #1707373 is a reply to message #1707328] Fri, 04 September 2015 06:13 Go to previous messageGo to next message
Eclipse UserFriend
yev xxxxx wrote on Thu, 03 September 2015 20:45
But mytype is not null, it doesn't fail on that line.


I agree that this looks fishy. While the findType() method starts by looking at names of compilation units (as spec'ed), it should not return a non-existent type. Please consider filing a bug against JDT/Core.

For your task I'd try these steps:


  1. get the IPackageFragment (assuming that no split packages are involved)
  2. get an ICompilationUnit via getCompilationUnit(String)
  3. get the IPackageDeclaration(s) via getPackageDeclarations()
  4. use its getAnnotations()


I'm aware that this looks a bit clumsy, but package-info.java is a funny animal to begin with.

HTH
Stephan
Re: Getting annotations from package-info.java via IType [message #1707507 is a reply to message #1707373] Sun, 06 September 2015 06:32 Go to previous message
Eclipse UserFriend
thanks this approach worked,

[Updated on: Sun, 06 September 2015 06:32] by Moderator

Previous Topic:Configuring HTML Editor on where to resolve css/js files
Next Topic:Birt bar chart report called with time interval
Goto Forum:
  


Current Time: Sun Jul 13 01:09:15 EDT 2025

Powered by FUDForum. Page generated in 0.04047 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top