Example usage for org.eclipse.jdt.core ITypeRoot getModule

List of usage examples for org.eclipse.jdt.core ITypeRoot getModule

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ITypeRoot getModule.

Prototype

default IModuleDescription getModule() throws JavaModelException 

Source Link

Document

Returns the module description contained in this type root or null if there is no module in this type root.

Usage

From source file:org.springframework.tooling.jdt.ls.commons.java.JavaData.java

License:Open Source License

private ClasspathEntryData createClasspathEntryData(IMember member) {
    ClasspathEntryData data = new ClasspathEntryData();

    IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) member
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (packageFragmentRoot != null) {
        try {/*from w  w w.  ja  va2  s.co m*/
            IClasspathEntry entry = packageFragmentRoot.getResolvedClasspathEntry();
            if (entry != null) {
                List<CPE> cpes = ClasspathUtil.createCpes(packageFragmentRoot.getJavaProject(), entry);
                Assert.isTrue(cpes.size() < 2);
                if (!cpes.isEmpty()) {
                    data.setCpe(cpes.get(0));
                }
            }
        } catch (JavaModelException | MalformedURLException e) {
            logger.log(e);
        }
    }

    ITypeRoot typeRoot = member.getTypeRoot();
    try {
        if (typeRoot != null && typeRoot.getModule() != null) {
            data.setModule(typeRoot.getModule().getElementName());
        }
    } catch (JavaModelException e) {
        logger.log(e);
    }

    return data;
}