Example usage for org.eclipse.jdt.core IJavaProject getModuleDescription

List of usage examples for org.eclipse.jdt.core IJavaProject getModuleDescription

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getModuleDescription.

Prototype

IModuleDescription getModuleDescription() throws JavaModelException;

Source Link

Document

Returns the IModuleDescription this project represents or null if the Java project doesn't represent any named module.

Usage

From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java

License:Open Source License

/**
 * Sets <code>module</code flag to <code>true</code> to classpath dependencies declared in module-info.java
 * // ww  w.j  a  v a 2  s.co  m
 * @param facade a Maven facade project
 * @param classpath a classpath descriptor
 * @param monitor a progress monitor
 */
public static void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath,
        IProgressMonitor monitor) throws CoreException {
    IJavaProject javaProject = JavaCore.create(facade.getProject());
    if (javaProject == null || !javaProject.exists()) {
        return;
    }
    IModuleDescription moduleDescription = javaProject.getModuleDescription();
    if (!(moduleDescription instanceof AbstractModule)) {
        return;
    }
    AbstractModule module = (AbstractModule) moduleDescription;
    Set<String> requiredModules = Stream.of(module.getRequiredModules()).map(m -> new String(m.name()))
            .collect(Collectors.toSet());
    for (IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
        String moduleName = getModuleName(entry, monitor);
        if (requiredModules.contains(moduleName)) {
            entry.setClasspathAttribute(IClasspathAttribute.MODULE, Boolean.TRUE.toString());
        }
    }
}

From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java

License:Open Source License

private static String getModuleNameFromProject(IPath projectPath, IProgressMonitor monitor) {
    IJavaProject project = getJavaProject(projectPath);
    String module = null;/*from www  .ja  v a2  s.  c o m*/
    if (project != null) {
        try {
            if (project.getModuleDescription() == null) {
                String buildName = null;
                IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry()
                        .getProject(project.getProject());
                if (facade != null) {
                    MavenProject mavenProject = facade.getMavenProject(monitor);
                    if (mavenProject != null) {
                        buildName = mavenProject.getBuild().getFinalName();
                    }
                }
                if (buildName == null || buildName.isEmpty()) {
                    buildName = project.getElementName();
                }
                module = new String(AutomaticModuleNaming.determineAutomaticModuleName(buildName, false, null));
            } else {
                module = project.getModuleDescription().getElementName();
            }
        } catch (CoreException ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    return module;
}