[JSR308] ElementUtils.enclosingClass()
Niko Matsakis
niko at alum.mit.edu
Mon Feb 2 02:27:07 EST 2009
Question: when ElementUtils.enclosingClass() is invoked with a class
element E, is it intended that it always returns E? I would expect
that it would return some TypeElement E' where the definition of E is
nested inside of E', or null if E is a top-level class. Either way is
fine with me, but I don't want to code to the existing implementation
if it's not the intended semantics.
In order to implement my version of enclosingClass(), i.e., one that
always returns an enclosing class and never the element it was passed,
I believe one simply needs to change one line as shown here:
public static TypeElement enclosingClass(final Element elem) {
// XXX Change this line from: "Element result = elem;" to:
Element result = elem.getEnclosingElement();
while (result != null && !result.getKind().isClass()
&& !result.getKind().isInterface()) {
@Nullable Element encl = result.getEnclosingElement();
result = encl;
}
return (TypeElement) result;
}
Niko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/pipermail/jsr308/attachments/20090202/a155b2b5/attachment.htm
More information about the JSR308
mailing list