JDK-8140442 : Add getOutermostTypeElement to javax.lang.model utility class
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-10-24
  • Updated: 2022-02-09
  • Resolved: 2021-08-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18 b11Fixed
Related Reports
CSR :  
Relates :  
Sub Tasks
JDK-8281508 :  
Description
This is a useful utility used in the doclet's new api and would be beneficial to other users of javax.lang.model.

Suggested code:
    public TypeElement getOuterMostTypeElement(Element e) {
        if (e.getKind() == ElementKind.PACKAGE)
            return null;
        Element encl = e.getEnclosingElement();
        ElementKind kind = encl.getKind();
        if (kind == ElementKind.PACKAGE)
            return null;
        while (!(kind.isClass() || kind.isInterface())) {
            encl = encl.getEnclosingElement();
        }
        return (TypeElement)encl;
    }
Comments
Changeset: 57ae9fbe Author: Joe Darcy <darcy@openjdk.org> Date: 2021-08-10 16:49:49 +0000 URL: https://git.openjdk.java.net/jdk/commit/57ae9fbe779e63f9606077047137b00220c6b3a2
10-08-2021

Code in the default method implementation should also check for kinds of MODULE and OTHER as they require additional handling. Note that at time of writing "getOutMostTypeElement" is not in the set of methods in the javadoc "WorkArounds.java" class. However, javac symbols do track a corresponding outer-most class in a field.
04-08-2021