Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 08c04e545d08897d91c8716c8e9849014bfd8cbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2016 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * This is an implementation of an early-draft specification developed under the Java
 * Community Process (JCP) and is made available for testing and evaluation purposes
 * only. The code is not compatible with any specification of the JCP.
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.core;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;

public class ModulePathContainer implements IClasspathContainer{

	private IJavaProject project;

	public ModulePathContainer(IJavaProject project) {
		this.project = project;
	}
	@Override
	public IClasspathEntry[] getClasspathEntries() {
		//
		List<IClasspathEntry> entries = new ArrayList<>();
		ModuleSourcePathManager manager = JavaModelManager.getModulePathManager();
		try {
			AbstractModule module = (AbstractModule) ((JavaProject)this.project).getModuleDescription();
			if (module == null)
				return new IClasspathEntry[0];
			for (org.eclipse.jdt.internal.compiler.env.IModule.IModuleReference ref : module.getRequiredModules()) {
				IModulePathEntry entry = manager.getModuleRoot(new String(ref.name()));
				JavaProject refRoot = null;
				if (entry instanceof ProjectEntry) {
					refRoot = ((ProjectEntry) entry).project;
				}
				if (refRoot == null)
					continue;
				IPath path = refRoot.getPath();
				IClasspathAttribute moduleAttribute = new ClasspathAttribute(IClasspathAttribute.MODULE, "true"); //$NON-NLS-1$
				entries.add(JavaCore.newProjectEntry(path, ClasspathEntry.NO_ACCESS_RULES,
						false,
						new IClasspathAttribute[] {moduleAttribute}, ref.isTransitive()));
			}
		} catch (JavaModelException e) {
			// ignore
		}
		return entries.toArray(new IClasspathEntry[entries.size()]);
	}

	@Override
	public String getDescription() {
		// 
		return "Module path"; //$NON-NLS-1$
	}

	@Override
	public int getKind() {
		// 
		return K_APPLICATION;
	}

	@Override
	public IPath getPath() {
		// 
		return new Path(JavaCore.MODULE_PATH_CONTAINER_ID);
	}

}

Back to the top