Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-04-23 06:25:41 -0400
committerStephan Herrmann2019-04-26 17:39:48 -0400
commit8620194f7c282d7f1dade77d452642d855fb1132 (patch)
treeb9187235e60b1809c712d7473cf3eaea954898f4
parenta5bb33f31600c5673590e85111231334faef5bd6 (diff)
downloadeclipse.jdt.core-8620194f7c282d7f1dade77d452642d855fb1132.tar.gz
eclipse.jdt.core-8620194f7c282d7f1dade77d452642d855fb1132.tar.xz
eclipse.jdt.core-8620194f7c282d7f1dade77d452642d855fb1132.zip
Bug 546649 - [9][model] API to get exports and opens from an
IModuleDescription Change-Id: I09fcaa4cc94e96ef6d54cff3717f6fc69c4d82e7 Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java22
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AbstractModule.java34
2 files changed, 55 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java
index ebda6d8ce8..5455e734e5 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java
@@ -54,7 +54,27 @@ public interface IModuleDescription extends IMember, IAnnotatable {
* @since 3.18
*/
String[] getUsedServiceNames() throws JavaModelException;
-
+
+ /**
+ * Get names of exported packages.
+ *
+ * @param targetModule filter the result to include only packages exported to the given module, unless {@code null}.
+ * @return a non-null array of exported package names
+ * @throws JavaModelException
+ * @since 3.18
+ */
+ String[] getExportedPackageNames(IModuleDescription targetModule) throws JavaModelException;
+
+ /**
+ * Get names of opened packages.
+ *
+ * @param targetModule filter the result to include only packages opened to the given module, unless {@code null}.
+ * @return a non-null array of opened package names
+ * @throws JavaModelException
+ * @since 3.18
+ */
+ String[] getOpenedPackageNames(IModuleDescription targetModule) throws JavaModelException;
+
/**
*
* @return true if automatic module, else false
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AbstractModule.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AbstractModule.java
index 761778fc16..b95f900110 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AbstractModule.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AbstractModule.java
@@ -15,11 +15,13 @@ package org.eclipse.jdt.internal.core;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModule.IModuleReference;
import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport;
@@ -80,6 +82,38 @@ public interface AbstractModule extends IModuleDescription {
default IModule getModuleInfo() throws JavaModelException {
return (IModule) getElementInfo();
}
+ @Override
+ default String[] getExportedPackageNames(IModuleDescription targetModule) throws JavaModelException {
+ IModule info = getModuleInfo();
+ if (info != null) {
+ List<String> result = new ArrayList<>();
+ for (IPackageExport packageExport : info.exports()) {
+ if (targetModule == null || !packageExport.isQualified()
+ || CharOperation.containsEqual(packageExport.targets(), targetModule.getElementName().toCharArray()))
+ {
+ result.add(new String(packageExport.name()));
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+ return new String[0];
+ }
+ @Override
+ default String[] getOpenedPackageNames(IModuleDescription targetModule) throws JavaModelException {
+ IModule info = getModuleInfo();
+ if (info != null) {
+ List<String> result = new ArrayList<>();
+ for (IPackageExport packageOpen : info.opens()) {
+ if (targetModule == null || !packageOpen.isQualified()
+ || CharOperation.containsEqual(packageOpen.targets(), targetModule.getElementName().toCharArray()))
+ {
+ result.add(new String(packageOpen.name()));
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+ return new String[0];
+ }
default IModuleReference[] getRequiredModules() throws JavaModelException {
return getModuleInfo().requires();
}

Back to the top