I was wondering whether there is a way to obtain a binary IType
(BinaryType) for a type that exists as source.
I would like to get a list of all declared methods of a type, including
the synthetic ones. Though the documentation of
ITypeBinding.getDeclaredMethods() just states that "Synthetic methods and
constructors may or may not be included", I noticed that they are included
for binary bindings, i.e., ITypeBindings that were obtained from a
BinaryType rather than a SourceType.
However, obtaining a binary IType for a type that is defined as source
does not seem to be so easy. I first followed the project's classpath to
find the corresponding IClassFile, from which I obtained the IType, which
indeed was a BinaryType object. However, as soon as I query the type, for
example, by calling getFlags(), I get a JavaModelException (Operation not
supported for specified element type(s):<project root>). It turns out that
this is because the package fragment root is still marked as K_SOURCE, and
not as K_BINARY.
Then I tried to modify the way how I obtained the IClassFile. I created a
new library IClasspathEntry for the output folder (libraries are K_BINARY)
and tried IJavaProject.findPackageFragmentRoots(...) for that new library
entry, in the hope it would return an IPackageFragmentRoot that is
K_BINARY. But, not surprisingly, this hack didn't work.
To make a long story short: is there any way to get a working BinaryType
object for a source type? Or, alternatively, is there a way to extract
synthetic members from the ITypeBinding of a source type?