diff options
author | Stephan Herrmann | 2017-08-26 19:31:56 +0000 |
---|---|---|
committer | Stephan Herrmann | 2017-08-26 19:35:30 +0000 |
commit | 10dd02010dd61fe266fb956c77e9e4e93f61367c (patch) | |
tree | 9a476cb932f83546aced25b96a4841f70bf2e7fa | |
parent | 500fc51536fa5a97b7201c6d8d466e834a26ccc0 (diff) | |
download | eclipse.jdt.core-10dd02010dd61fe266fb956c77e9e4e93f61367c.tar.gz eclipse.jdt.core-10dd02010dd61fe266fb956c77e9e4e93f61367c.tar.xz eclipse.jdt.core-10dd02010dd61fe266fb956c77e9e4e93f61367c.zip |
- support multiple add-eports per classpath attribute
Change-Id: Ie33ce52fc2a073005e9d4e284dd43a753bc59d43
3 files changed, 73 insertions, 18 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index 4aa7f6f3ae..f9d670fa0c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -4597,6 +4597,56 @@ public class ModuleBuilderTests extends ModifyingResourceTests { deleteProject("com.greetings"); } } + public void testAddExports2() throws CoreException { + if (!isJRE9) return; + try { + String[] sources = new String[] { + "src/module-info.java", + "module morg.astro {\n" + +// " exports org.astro to com.greetings;\n" + // this export will be added via add-exports +// " exports org.eclipse to com.greetings;\n" + // this export will be added via add-exports + "}", + "src/org/astro/World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public String name();\n" + + "}", + "src/org/eclipse/Planet.java", + "package org.eclipse;\n" + + "public class Planet {}\n" + }; + IJavaProject p1 = setupModuleProject("morg.astro", sources); + IClasspathAttribute modAttr = new ClasspathAttribute("module", "true"); + IClasspathAttribute addExports = new ClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, + "morg.astro/org.astro=com.greetings:morg.astro/org.eclipse=com.greetings"); + IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, + new IClasspathAttribute[] {modAttr, addExports}, + false/*not exported*/); + String[] src = new String[] { + "src/module-info.java", + "module com.greetings {\n" + + " requires morg.astro;\n" + + " exports com.greetings;\n" + + "}", + "src/com/greetings/MyWorld.java", + "package com.greetings;\n" + + "import org.astro.World;\n" + + "public class MyWorld implements World {\n" + + " org.eclipse.Planet planet;\n" + + " public String name() {\n" + + " return \" My World!!\";\n" + + " }\n" + + "}" + }; + IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep }); + p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "", markers); + } finally { + deleteProject("morg.astro"); + deleteProject("com.greetings"); + } + } public void testAddReads() throws CoreException, IOException { if (!isJRE9) return; try { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java index 5d78a433d6..aa8f7d3a6e 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java @@ -601,6 +601,8 @@ public interface IJavaProject extends IParent, IJavaElement, IOpenable { * valid Java module descriptor. * * @return the <code>IModule</code> this project represents. + * @exception JavaModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource * @since 3.13 BETA_JAVA9 */ IModuleDescription getModuleDescription() throws JavaModelException; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleUpdater.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleUpdater.java index 4275879625..900a8498d4 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleUpdater.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleUpdater.java @@ -45,27 +45,30 @@ public class ModuleUpdater { public void computeModuleUpdates(IClasspathEntry entry) { for (IClasspathAttribute attribute : entry.getExtraAttributes()) { String attributeName = attribute.getName(); + String values = attribute.getValue(); // the attributes considered here may have multiple values separated by ':' if (attributeName.equals(IClasspathAttribute.ADD_EXPORTS)) { - String value = attribute.getValue(); // format: <source-module>/<package>=<target-module>(,<target-module>)* - int slash = value.indexOf('/'); - int equals = value.indexOf('='); - if (slash != -1 && equals != -1) { - String modName = value.substring(0, slash); - char[] packName = value.substring(slash+1, equals).toCharArray(); - char[][] targets = CharOperation.splitOn(',', value.substring(equals+1).toCharArray()); - addModuleUpdate(modName, m -> m.addExports(packName, targets), UpdateKind.PACKAGE); - } else { - Util.log(IStatus.WARNING, "Invalid argument to add-exports: "+value); //$NON-NLS-1$ + for (String value : values.split(":")) { // format: <source-module>/<package>=<target-module>(,<target-module>)* //$NON-NLS-1$ + int slash = value.indexOf('/'); + int equals = value.indexOf('='); + if (slash != -1 && equals != -1) { + String modName = value.substring(0, slash); + char[] packName = value.substring(slash+1, equals).toCharArray(); + char[][] targets = CharOperation.splitOn(',', value.substring(equals+1).toCharArray()); + addModuleUpdate(modName, m -> m.addExports(packName, targets), UpdateKind.PACKAGE); + } else { + Util.log(IStatus.WARNING, "Invalid argument to add-exports: "+value); //$NON-NLS-1$ + } } } else if (attributeName.equals(IClasspathAttribute.ADD_READS)) { - String value = attribute.getValue(); // format: <source-module>=<target-module> - int equals = value.indexOf('='); - if (equals != -1) { - String srcMod = value.substring(0, equals); - char[] targetMod = value.substring(equals+1).toCharArray(); - addModuleUpdate(srcMod, m -> m.addReads(targetMod), UpdateKind.MODULE); - } else { - Util.log(IStatus.WARNING, "Invalid argument to add-reads: "+value); //$NON-NLS-1$ + for (String value : values.split(":")) { // format: <source-module>=<target-module> //$NON-NLS-1$ + int equals = value.indexOf('='); + if (equals != -1) { + String srcMod = value.substring(0, equals); + char[] targetMod = value.substring(equals+1).toCharArray(); + addModuleUpdate(srcMod, m -> m.addReads(targetMod), UpdateKind.MODULE); + } else { + Util.log(IStatus.WARNING, "Invalid argument to add-reads: "+value); //$NON-NLS-1$ + } } } } |