Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasikanth Bharadwaj2016-09-23 06:08:16 +0000
committerSasikanth Bharadwaj2016-09-23 12:18:08 +0000
commit96cc7d1f2b16a1d266e02faa2b0051283ab6588c (patch)
tree05667ee4c36936e44c5420f70e0ced87f9ad95bc
parent423f36131a44d481535032bb084028d6a608977b (diff)
downloadeclipse.jdt.core-96cc7d1f2b16a1d266e02faa2b0051283ab6588c.tar.gz
eclipse.jdt.core-96cc7d1f2b16a1d266e02faa2b0051283ab6588c.tar.xz
eclipse.jdt.core-96cc7d1f2b16a1d266e02faa2b0051283ab6588c.zip
In progress - have a clear distinction between module (which represents
the module) and module declaration (which represents the module-info file. Should help in building better abstraction in the model Change-Id: I6495c0faf645ee84a657639b43e1d12a52c72bf7
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BinaryModule.java49
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJRT.java7
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java10
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java6
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java7
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java24
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/SourceModule.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java30
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModule.java35
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleAwareNameEnvironment.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleDeclaration.java49
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleEnvironment.java37
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java9
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java10
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Module.java46
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleInfo.java19
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModulePathContainer.java4
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java24
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java30
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java27
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java7
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java7
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java11
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java9
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java12
27 files changed, 322 insertions, 189 deletions
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BinaryModule.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BinaryModule.java
new file mode 100644
index 0000000000..ea89799ab0
--- /dev/null
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BinaryModule.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation and others.
+ * 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.compiler.batch;
+
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
+import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
+
+public class BinaryModule implements IModule {
+
+ public IModulePathEntry entry;
+ public IModuleDeclaration declaration;
+ public BinaryModule(IModulePathEntry entry, ClassFileReader moduleInfoClass) {
+ this.entry = entry;
+ this.declaration = moduleInfoClass.getModuleDeclaration();
+ }
+ @Override
+ public char[] name() {
+ //
+ return this.declaration.name();
+ }
+
+ @Override
+ public IModuleDeclaration getDeclaration() {
+ //
+ return this.declaration;
+ }
+
+ @Override
+ public IModuleEnvironment getLookupEnvironment() {
+ //
+ return this.entry.getLookupEnvironment();
+ }
+
+}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJRT.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJRT.java
index aff1add333..607f82fd3f 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJRT.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJRT.java
@@ -19,9 +19,9 @@ import java.util.zip.ZipFile;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
import org.eclipse.jdt.internal.compiler.env.IMultiModuleEntry;
@@ -213,15 +213,14 @@ public class ClasspathJRT extends ClasspathLocation implements IMultiModuleEntry
}
void acceptModule(ClassFileReader reader) {
if (reader != null) {
- IModule moduleDecl = reader.getModuleDeclaration();
+ IModuleDeclaration moduleDecl = reader.getModuleDeclaration();
if (moduleDecl != null) {
Set<IModule> cache = ModulesCache.get(this.file);
if (cache == null) {
ModulesCache.put(new String(moduleDecl.name()), cache = new HashSet<IModule>());
}
- cache.add(moduleDecl);
+ cache.add(new BinaryModule(this, reader));
}
- ((ModuleInfo)moduleDecl).entry = this;
}
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
index de357b22e1..923b4a72e8 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
@@ -33,7 +33,6 @@ import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
@@ -194,13 +193,8 @@ public void acceptModule(IModule mod) {
}
void acceptModule(ClassFileReader reader) {
if (reader != null) {
- IModule moduleDecl = reader.getModuleDeclaration();
- if (moduleDecl != null) {
- this.module = moduleDecl;
- ((ModuleInfo)moduleDecl).entry = this;
- }
+ this.module = new BinaryModule(this, reader);
}
-
}
void acceptModule(byte[] content) {
if (content == null)
@@ -211,7 +205,7 @@ void acceptModule(byte[] content) {
} catch (ClassFormatException e) {
e.printStackTrace();
}
- if (reader != null) {
+ if (reader != null && reader.getModuleDeclaration() != null) {
acceptModule(reader);
}
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
index 26d71b744c..e9ea3eb77f 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
@@ -34,8 +34,8 @@ import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment;
-import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport;
import org.eclipse.jdt.internal.compiler.env.IModuleContext;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IPackageExport;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.env.TypeLookup;
import org.eclipse.jdt.internal.compiler.lookup.ModuleEnvironment;
@@ -532,14 +532,14 @@ public boolean isPackage(char[][] compoundName, char[] packageName, IModuleConte
void addReads(String source, String target) {
IModule src = getModule(source.toCharArray());
if (src != null) {
- src.addReads(target.toCharArray());
+ src.getDeclaration().addReads(target.toCharArray());
}
}
void setAddonExports(Map<String, IPackageExport[]> exports) {
exports.entrySet().forEach((entry) -> {
IModule src = getModule(entry.getKey().toCharArray());
if (src != null) {
- src.addExports(entry.getValue());
+ src.getDeclaration().addExports(entry.getValue());
}
});
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
index 0ab00357b7..c254b83f94 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
@@ -89,7 +89,8 @@ import org.eclipse.jdt.internal.compiler.env.AccessRule;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.IModule;
-import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IPackageExport;
import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.CompilerStats;
@@ -3016,7 +3017,7 @@ private IModule extractModuleDesc(String fileName, Parser parser) {
} else if (fileName.toLowerCase().endsWith(IModuleLocation.MODULE_INFO_CLASS)) {
try {
ClassFileReader reader = ClassFileReader.read(fileName); // Check the absolute path?
- mod = reader.getModuleDeclaration();
+ mod = new BinaryModule(null, reader);
} catch (ClassFormatException | IOException e) {
e.printStackTrace();
throw new IllegalArgumentException(
@@ -3283,7 +3284,7 @@ protected ArrayList handleBootclasspath(ArrayList bootclasspaths, String customE
private void processAddonModuleOptions(FileSystem env) {
Map<String, IPackageExport[]> exports = new HashMap<>();
for (String option : this.addonExports) {
- IModule mod = ModuleFinder.extractAddonExport(option);
+ IModuleDeclaration mod = ModuleFinder.extractAddonExport(option);
if (mod != null) {
String modName = new String(mod.name());
IPackageExport export = mod.exports()[0];
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java
index 3b5191e33c..d13b3392d0 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java
@@ -29,10 +29,10 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.IModule;
-import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IPackageExport;
import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.util.Util;
@@ -136,7 +136,7 @@ public class ModuleFinder {
* @param option
* @return a dummy module object with package exports
*/
- protected static IModule extractAddonExport(String option) {
+ protected static IModuleDeclaration extractAddonExport(String option) {
StringTokenizer tokenizer = new StringTokenizer(option, "/"); //$NON-NLS-1$
String source = null;
String pack = null;
@@ -180,7 +180,7 @@ public class ModuleFinder {
}
}
- static class Module implements IModule {
+ static class Module implements IModuleDeclaration {
char[] name;
IPackageExport[] export;
Module(char[] name, IPackageExport export) {
@@ -218,11 +218,11 @@ public class ModuleFinder {
try {
zipFile = new ZipFile(file);
ClassFileReader reader = ClassFileReader.read(zipFile, IModuleLocation.MODULE_INFO_CLASS);
- IModule module = getModule(reader);
- if (module instanceof ModuleInfo) {
- ((ModuleInfo) module).entry = pathEntry;
+ IModuleDeclaration module = getModule(reader);
+ if (module != null) {
+ return new BinaryModule(pathEntry, reader);
}
- return module;
+ return null;
} catch (ClassFormatException | IOException e) {
e.printStackTrace();
} finally {
@@ -240,17 +240,17 @@ public class ModuleFinder {
ClassFileReader reader;
try {
reader = ClassFileReader.read(classfilePath);
- IModule module = getModule(reader);
+ IModuleDeclaration module = getModule(reader);
if (module != null) {
- ((ModuleInfo)module).entry = pathEntry;
+ return new BinaryModule(pathEntry, reader);
}
- return module;
+ return null;
} catch (ClassFormatException | IOException e) {
e.printStackTrace();
}
return null;
}
- private static IModule getModule(ClassFileReader classfile) {
+ private static IModuleDeclaration getModule(ClassFileReader classfile) {
if (classfile != null) {
return classfile.getModuleDeclaration();
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/SourceModule.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/SourceModule.java
index b7cb0dfacf..73e6cf3f96 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/SourceModule.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/SourceModule.java
@@ -13,11 +13,12 @@ import org.eclipse.jdt.internal.compiler.ast.ModuleReference;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
-public class SourceModule implements IModule {
- static class ModuleReferenceImpl implements IModule.IModuleReference {
+public class SourceModule implements IModule, IModuleDeclaration {
+ static class ModuleReferenceImpl implements IModuleDeclaration.IModuleReference {
char[] name;
boolean isPublic = false;
@Override
@@ -31,9 +32,9 @@ public class SourceModule implements IModule {
public boolean equals(Object o) {
if (this == o)
return true;
- if (!(o instanceof IModule.IModuleReference))
+ if (!(o instanceof IModuleDeclaration.IModuleReference))
return false;
- IModule.IModuleReference mod = (IModule.IModuleReference) o;
+ IModuleDeclaration.IModuleReference mod = (IModuleDeclaration.IModuleReference) o;
if (this.isPublic != mod.isPublic())
return false;
return CharOperation.equals(this.name, mod.name(), false);
@@ -43,7 +44,7 @@ public class SourceModule implements IModule {
return this.name.hashCode();
}
}
- static class PackageExport implements IModule.IPackageExport {
+ static class PackageExport implements IModuleDeclaration.IPackageExport {
char[] pack;
char[][] exportedTo;
@Override
@@ -67,7 +68,7 @@ public class SourceModule implements IModule {
return buffer.toString();
}
}
- static class Service implements IModule.IService {
+ static class Service implements IModuleDeclaration.IService {
char[] provides;
char[] with;
@Override
@@ -162,11 +163,11 @@ public class SourceModule implements IModule {
return this.name;
}
@Override
- public IModule.IModuleReference[] requires() {
+ public IModuleDeclaration.IModuleReference[] requires() {
return this.requires;
}
@Override
- public IPackageExport[] exports() {
+ public IModuleDeclaration.IPackageExport[] exports() {
return this.exports;
}
@Override
@@ -188,7 +189,7 @@ public class SourceModule implements IModule {
info.name = modName;
}
}
- public void addExports(IPackageExport[] toAdd) {
+ public void addExports(IModuleDeclaration.IPackageExport[] toAdd) {
Predicate<char[]> shouldAdd = m -> {
return Stream.of(this.exports).map(ref -> ref.pack).noneMatch(n -> CharOperation.equals(m, n));
};
@@ -217,7 +218,7 @@ public class SourceModule implements IModule {
IModule mod = (IModule) o;
if (!CharOperation.equals(this.name, mod.name()))
return false;
- return Arrays.equals(this.requires, mod.requires());
+ return Arrays.equals(this.requires, mod.getDeclaration().requires());
}
@Override
public int hashCode() {
@@ -269,4 +270,9 @@ public class SourceModule implements IModule {
}
buffer.append('\n').append('}').toString();
}
+ @Override
+ public IModuleDeclaration getDeclaration() {
+ //
+ return this;
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
index 1e461621a8..87d1d407ed 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
@@ -53,7 +53,7 @@ public class ClassFileReader extends ClassFileStruct implements IBinaryType {
private AnnotationInfo[] annotations;
private TypeAnnotationInfo[] typeAnnotations;
private FieldInfo[] fields;
- private IModule moduleDeclaration;
+ private IModuleDeclaration moduleDeclaration;
public char[] moduleName;
private int fieldsCount;
@@ -681,7 +681,7 @@ public char[] getModule() {
*
* @return the module declaration this represents
*/
-public IModule getModuleDeclaration() {
+public IModuleDeclaration getModuleDeclaration() {
return this.moduleDeclaration;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
index f9b46231bd..08d422a009 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
@@ -21,11 +21,9 @@ import java.util.function.Predicate;
import java.util.stream.Stream;
import org.eclipse.jdt.core.compiler.CharOperation;
-import org.eclipse.jdt.internal.compiler.env.IModule;
-import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
-import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
-public class ModuleInfo extends ClassFileStruct implements IModule {
+public class ModuleInfo extends ClassFileStruct implements IModuleDeclaration {
protected int requiresCount;
protected int exportsCount;
protected int usesCount;
@@ -34,8 +32,7 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
protected ModuleReferenceInfo[] requires;
protected PackageExportInfo[] exports;
char[][] uses;
- IModule.IService[] provides;
- public IModulePathEntry entry; // The entry that contributes this module to the module path
+ IModuleDeclaration.IService[] provides;
public int requiresCount() {
return this.requiresCount;
@@ -57,11 +54,11 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
this.name = name;
}
@Override
- public IModule.IModuleReference[] requires() {
+ public IModuleDeclaration.IModuleReference[] requires() {
return this.requires;
}
@Override
- public IModule.IPackageExport[] exports() {
+ public IModuleDeclaration.IPackageExport[] exports() {
return this.exports;
}
@Override
@@ -101,9 +98,6 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
ArrayList::addAll);
this.exports = merged.toArray(new PackageExportInfo[merged.size()]);
}
- public IModuleEnvironment getLookupEnvironment() {
- return this.entry.getLookupEnvironmentFor(this);
- }
/**
* @param name char[]
* @param classFileBytes byte[]
@@ -170,7 +164,7 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
}
return module;
}
- class ModuleReferenceInfo implements IModule.IModuleReference {
+ class ModuleReferenceInfo implements IModuleDeclaration.IModuleReference {
char[] refName;
boolean isPublic = false;
@Override
@@ -184,9 +178,9 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
public boolean equals(Object o) {
if (this == o)
return true;
- if (!(o instanceof IModule.IModuleReference))
+ if (!(o instanceof IModuleDeclaration.IModuleReference))
return false;
- IModule.IModuleReference mod = (IModule.IModuleReference) o;
+ IModuleDeclaration.IModuleReference mod = (IModuleDeclaration.IModuleReference) o;
if (this.isPublic != mod.isPublic())
return false;
return CharOperation.equals(this.refName, mod.name(), false);
@@ -196,7 +190,7 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
return this.refName.hashCode();
}
}
- class PackageExportInfo implements IModule.IPackageExport {
+ class PackageExportInfo implements IModuleDeclaration.IPackageExport {
char[] packageName;
char[][] exportedTo;
int exportedToCount;
@@ -226,7 +220,7 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
buffer.append(';').append('\n');
}
}
- class ServiceInfo implements IModule.IService {
+ class ServiceInfo implements IModuleDeclaration.IService {
char[] serviceName;
char[] with;
@Override
@@ -242,9 +236,9 @@ public class ModuleInfo extends ClassFileStruct implements IModule {
public boolean equals(Object o) {
if (this == o)
return true;
- if (!(o instanceof IModule))
+ if (!(o instanceof IModuleDeclaration))
return false;
- IModule mod = (IModule) o;
+ IModuleDeclaration mod = (IModuleDeclaration) o;
if (!CharOperation.equals(this.name, mod.name()))
return false;
return Arrays.equals(this.requires, mod.requires());
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModule.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModule.java
index 1e67aaaf78..156272db49 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModule.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModule.java
@@ -22,38 +22,7 @@ public interface IModule {
public char[] name();
- public IModuleReference[] requires();
-
- public IPackageExport[] exports();
-
- public char[][] uses();
-
- public IService[] provides();
-
- public interface IModuleReference {
- public char[] name();
- public boolean isPublic();
- }
-
- public interface IPackageExport {
- public char[] name();
- public char[][] exportedTo();
- }
-
- public interface IService {
- public char[] name();
- char[] with();
- }
+ public IModuleDeclaration getDeclaration();
- public default void addReads(char[] modName) {
- // do nothing, would throwing an exception be better?
- }
-
- public default void addExports(IPackageExport[] exports) {
- // do nothing, would throwing an exception be better?
- }
-
- default IModuleEnvironment getLookupEnvironment() {
- return null;
- }
+ IModuleEnvironment getLookupEnvironment();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleAwareNameEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleAwareNameEnvironment.java
index 5a9f671b40..1ad0836e92 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleAwareNameEnvironment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleAwareNameEnvironment.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2016 IBM Corporation and others.
* 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
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleDeclaration.java
new file mode 100644
index 0000000000..b2d4813eaa
--- /dev/null
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModuleDeclaration.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation and others.
+ * 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.compiler.env;
+
+public interface IModuleDeclaration {
+ public char[] name();
+ public IModuleReference[] requires();
+
+ public IPackageExport[] exports();
+
+ public char[][] uses();
+
+ public IService[] provides();
+
+ public interface IModuleReference {
+ public char[] name();
+ public boolean isPublic();
+ }
+
+ public interface IPackageExport {
+ public char[] name();
+ public char[][] exportedTo();
+ }
+
+ public interface IService {
+ public char[] name();
+ char[] with();
+ }
+
+ public default void addReads(char[] modName) {
+ // do nothing, would throwing an exception be better?
+ }
+
+ public default void addExports(IPackageExport[] exports) {
+ // do nothing, would throwing an exception be better?
+ }
+}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
index 68f84307e9..9d41aa6789 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
@@ -24,10 +24,11 @@ import java.util.stream.Stream;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
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;
import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModuleContext;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IModuleReference;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IPackageExport;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage;
@@ -88,10 +89,11 @@ public class ModuleBinding extends Binding {
}
public ModuleBinding(IModule module, LookupEnvironment environment) {
this.moduleName = module.name();
- this.requires = module.requires();
+ IModuleDeclaration decl = module.getDeclaration();
+ this.requires = decl.requires();
if (this.requires == null)
this.requires = NO_MODULE_REFS;
- this.exports = module.exports();
+ this.exports = decl.exports();
if (this.exports == null)
this.exports = NO_EXPORTS;
this.environment = environment;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleEnvironment.java
index de1be4f05b..c81b5037a5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleEnvironment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleEnvironment.java
@@ -21,6 +21,8 @@ import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModuleContext;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.util.JRTUtil;
@@ -34,31 +36,30 @@ public abstract class ModuleEnvironment implements IModuleAwareNameEnvironment {
* Given a ModuleDeclaration, creates an IModule
* TODO: This should kick-in only when source level is >= 9
*/
- public static final char[] UNNAMED = "UNNAMED".toCharArray(); //$NON-NLS-1$
+ public static final char[] UNNAMED = "".toCharArray(); //$NON-NLS-1$
public static final IModule UNNAMED_MODULE = new IModule() {
+
@Override
- public char[][] uses() {
- return null;
- }
- @Override
- public IModuleReference[] requires() {
- return null;
- }
- @Override
- public IService[] provides() {
- return null;
+ public String toString() {
+ return new String(UNNAMED);
}
+
@Override
public char[] name() {
+ //
return UNNAMED;
}
+
@Override
- public IPackageExport[] exports() {
+ public IModuleDeclaration getDeclaration() {
+ // TODO Auto-generated method stub
return null;
}
+
@Override
- public String toString() {
- return new String(UNNAMED);
+ public IModuleEnvironment getLookupEnvironment() {
+ // TODO Auto-generated method stub
+ return null;
}
};
public static IModule[] UNNAMED_MODULE_ARRAY = new IModule[]{UNNAMED_MODULE};
@@ -123,9 +124,9 @@ public abstract class ModuleEnvironment implements IModuleAwareNameEnvironment {
* @return whether or not the specified package is exported from the module to the client
*/
protected boolean isPackageExportedTo(IModule module, char[] pack, IModule client) {
- IModule.IPackageExport[] exports = module.exports();
+ IModuleDeclaration.IPackageExport[] exports = module.getDeclaration().exports();
if (exports != null && exports.length > 0) {
- for (IModule.IPackageExport iPackageExport : exports) {
+ for (IModuleDeclaration.IPackageExport iPackageExport : exports) {
if (CharOperation.equals(iPackageExport.name(), pack)) {
char[][] exportedTo = iPackageExport.exportedTo();
if (exportedTo == null || exportedTo.length == 0) {
@@ -163,9 +164,9 @@ public abstract class ModuleEnvironment implements IModuleAwareNameEnvironment {
protected void collectAllVisibleModules(IModule module, Set<IModule> targets, boolean onlyPublic) {
if (module != null) {
- IModule.IModuleReference[] requires = module.requires();
+ IModuleDeclaration.IModuleReference[] requires = module.getDeclaration().requires();
if (requires != null && requires.length > 0) {
- for (IModule.IModuleReference ref : requires) {
+ for (IModuleDeclaration.IModuleReference ref : requires) {
IModule refModule = getModule(ref.name());
if (refModule != null) {
if (!onlyPublic || ref.isPublic()) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
index 97ad67cc4a..eea9ff81c0 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
@@ -39,7 +39,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
@@ -107,11 +106,11 @@ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm,
// Make the type
IType type = getType();
info.setChildren(new IJavaElement[] {type});
- org.eclipse.jdt.internal.compiler.env.IModule moduleInfo = ((ClassFileReader)typeInfo).getModuleDeclaration();
+// org.eclipse.jdt.internal.compiler.env.IModuleDeclaration moduleInfo = ((ClassFileReader)typeInfo).getModuleDeclaration();
newElements.put(type, typeInfo);
- if (TypeDeclaration.kind(typeInfo.getModifiers()) == TypeDeclaration.MODULE_DECL) {
- ((PackageFragmentRootInfo)getPackageFragmentRoot().getElementInfo()).setModule(moduleInfo);
- }
+// if (TypeDeclaration.kind(typeInfo.getModifiers()) == TypeDeclaration.MODULE_DECL) {
+// ((PackageFragmentRootInfo)getPackageFragmentRoot().getElementInfo()).setModule(moduleInfo);
+// }
// Read children
((ClassFileInfo) info).readBinaryChildren(this, (HashMap) newElements, typeInfo);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java
index 0b70410e76..a984b35e88 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java
@@ -43,6 +43,7 @@ import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.UnaryExpression;
+import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
@@ -724,10 +725,11 @@ public void exitType(int declarationEnd) {
PackageFragmentRoot root= (PackageFragmentRoot) handle.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (root != null) {
try {
- org.eclipse.jdt.internal.core.ModuleInfo module = createModuleInfo(typeInfo, handle);
- this.unitInfo.setModule(module);
- ((PackageFragmentRootInfo)(root.getElementInfo())).setModule(module);
- module.entry = JavaModelManager.getModulePathManager().getModuleRoot(new String(module.name));
+ org.eclipse.jdt.internal.core.ModuleInfo moduleDecl = createModuleInfo(typeInfo, handle);
+ IModule module = ((PackageFragmentRootInfo)(root.getElementInfo())).getModule();
+ if (module != null) {
+ ((Module)module).declaration = moduleDecl;
+ }
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Module.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Module.java
new file mode 100644
index 0000000000..2ae23c7db5
--- /dev/null
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Module.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation and others.
+ * 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 org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
+import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
+
+public class Module implements org.eclipse.jdt.internal.compiler.env.IModule {
+
+ public IModulePathEntry entry;
+ public IModuleDeclaration declaration;
+
+ public Module(IModulePathEntry entry, IModuleDeclaration declaration) {
+ this.entry = entry;
+ this.declaration = declaration;
+ }
+ @Override
+ public char[] name() {
+ //
+ return this.declaration.name();
+ }
+ @Override
+ public IModuleDeclaration getDeclaration() {
+ //
+ return this.declaration;
+ }
+ @Override
+ public IModuleEnvironment getLookupEnvironment() {
+ //
+ return this.entry == null ? null : this.entry.getLookupEnvironment();
+ }
+
+}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleInfo.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleInfo.java
index 645d7fca3c..d18bad4533 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleInfo.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleInfo.java
@@ -19,18 +19,16 @@ import org.eclipse.jdt.internal.compiler.ast.ExportReference;
import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ModuleReference;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
-import org.eclipse.jdt.internal.compiler.env.IModule;
-import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
-import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
-public class ModuleInfo extends SourceTypeElementInfo implements IModule {
+public class ModuleInfo extends SourceTypeElementInfo implements IModuleDeclaration {
protected static final IModuleReference[] NO_REQUIRES = new IModuleReference[0];
protected static final IPackageExport[] NO_EXPORTS = new IPackageExport[0];
protected static final IService[] NO_SERVICES = new IService[0];
protected static final char[][] NO_USES = new char[0][0];
- static class ModuleReferenceImpl implements IModule.IModuleReference {
+ static class ModuleReferenceImpl implements IModuleDeclaration.IModuleReference {
char[] name;
boolean isPublic = false;
@Override
@@ -43,7 +41,7 @@ public class ModuleInfo extends SourceTypeElementInfo implements IModule {
}
}
- static class PackageExport implements IModule.IPackageExport {
+ static class PackageExport implements IModuleDeclaration.IPackageExport {
char[] pack;
char[][] exportedTo;
@Override
@@ -67,7 +65,7 @@ public class ModuleInfo extends SourceTypeElementInfo implements IModule {
return buffer.toString();
}
}
- static class Service implements IModule.IService {
+ static class Service implements IModuleDeclaration.IService {
char[] provides;
char[] with;
@Override
@@ -94,14 +92,11 @@ public class ModuleInfo extends SourceTypeElementInfo implements IModule {
PackageExport[] exports;
char[][] uses;
Service[] provides;
- public IModulePathEntry entry;
+
@Override
public char[] name() {
return this.name;
}
- public IModuleEnvironment getLookupEnvironment() {
- return this.entry.getLookupEnvironmentFor(this);
- }
public static ModuleInfo createModule(ModuleDeclaration module) {
ModuleInfo mod = new ModuleInfo();
mod.name = module.moduleName;
@@ -165,7 +160,7 @@ public class ModuleInfo extends SourceTypeElementInfo implements IModule {
}
@Override
- public IModule.IModuleReference[] requires() {
+ public IModuleDeclaration.IModuleReference[] requires() {
return this.requires;
}
@Override
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModulePathContainer.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModulePathContainer.java
index 592d8c8824..b1917ff6f5 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModulePathContainer.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModulePathContainer.java
@@ -26,7 +26,7 @@ import org.eclipse.jdt.core.JavaCore;
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.IModuleDeclaration.IModuleReference;
import org.eclipse.jdt.internal.compiler.env.IModulePathEntry;
public class ModulePathContainer implements IClasspathContainer{
@@ -45,7 +45,7 @@ public class ModulePathContainer implements IClasspathContainer{
IModule module = ((JavaProject)this.project).getModule();
if (module == null)
return new IClasspathEntry[0];
- for (IModuleReference ref : module.requires()) {
+ for (IModuleReference ref : module.getDeclaration().requires()) {
IModulePathEntry entry = manager.getModuleRoot(CharOperation.charToString(ref.name()));
JavaProject refRoot = null;
if (entry instanceof ProjectEntry) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java
index 86fc4a3475..6c5b7b21a9 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java
@@ -59,8 +59,8 @@ public class ModuleSourcePathManager {
IModule module = ((JavaProject) project).getModule();
if (module != null) {
char[] moduleName = module.name();
+ this.knownModules.put(CharOperation.charToString(name), ((Module)module).entry);
if (CharOperation.equals(name, moduleName)) {
- this.knownModules.put(CharOperation.charToString(name), new ProjectEntry((JavaProject) project));
requestor.acceptModule(module);
break;
}
@@ -78,17 +78,17 @@ public class ModuleSourcePathManager {
public IModule getModule(char[] name) {
IModulePathEntry root = getModuleRoot0(CharOperation.charToString(name));
if (root != null)
- //try {
+ try {
return root.getModule();
-// } catch (JavaModelException e1) {
-// //
-// return null;
-// }
+ } catch (Exception e1) {
+ //
+ return null;
+ }
JavaElementRequestor requestor = new JavaElementRequestor();
try {
seekModule(name, false, requestor);
} catch (JavaModelException e) {
- // TODO Auto-generated catch block
+ //
}
IModule[] modules = requestor.getModules();
return modules.length > 0 ? modules[0] : null;
@@ -99,12 +99,12 @@ public class ModuleSourcePathManager {
}
List<IModule> modules = new ArrayList<IModule>();
for (IModulePathEntry val : this.knownModules.values()) {
- //try {
+ try {
modules.add(val.getModule());
-// } catch (JavaModelException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
return modules.toArray(new IModule[modules.size()]);
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
index 71a8ab1505..97e4ae2493 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
@@ -1007,6 +1007,17 @@ public class NameLookup implements SuffixConstants {
* only exact name matches qualify when <code>false</code>
*/
public void seekPackageFragments(String name, boolean partialMatch, IJavaElementRequestor requestor, IModuleContext context) {
+ if (context == IModuleContext.UNNAMED_MODULE_CONTEXT) {
+ seekPackageFragments(name, partialMatch, requestor);
+ return;
+ }
+ String[] splittedName = Util.splitOn('.', name, 0, name.length());
+ int pkgIndex = this.packageFragments.getIndex(splittedName);
+ if (pkgIndex == -1)
+ return;
+ Object value = this.packageFragments.valueTable[pkgIndex];
+ // reuse existing String[]
+ String[] pkgName = (String[]) this.packageFragments.keyTable[pkgIndex];
context.getEnvironment().<PackageFragmentRoot>flatMap(e -> {
if (e instanceof ProjectEntry) {
JavaProject prj = ((ProjectEntry) e).project;
@@ -1031,9 +1042,22 @@ public class NameLookup implements SuffixConstants {
return Stream.of((JrtPackageFragmentRoot)e);
}
}).forEach(r -> {
- IPackageFragment pkg = r.getPackageFragment(name);
- if (pkg != null) {
- requestor.acceptPackageFragment(pkg);
+ if (value instanceof PackageFragmentRoot) {
+ if (value.equals(r)) {
+ PackageFragmentRoot root = (PackageFragmentRoot) value;
+ requestor.acceptPackageFragment(root.getPackageFragment(pkgName));
+ }
+ } else {
+ IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
+ if (roots != null) {
+ for (int i = 0, length = roots.length; i < length; i++) {
+ if (requestor.isCanceled())
+ return;
+ PackageFragmentRoot root = (PackageFragmentRoot) roots[i];
+ if (root.equals(r))
+ requestor.acceptPackageFragment(root.getPackageFragment(pkgName));
+ }
+ }
}
});
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
index 52d7cfd13d..257a1dee62 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
@@ -23,7 +23,6 @@ import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
import org.eclipse.jdt.internal.core.util.Messages;
@@ -878,23 +877,33 @@ public org.eclipse.jdt.internal.compiler.env.IModule getModule() {
for (int j = 0, length = pkgs.length; j < length; j++) {
// only look in the default package
if (pkgs[j].getElementName().length() == 0) {
- OpenableElementInfo info = null;
if (getKind() == IPackageFragmentRoot.K_SOURCE) {
ICompilationUnit unit = ((PackageFragment) pkgs[j])
.getCompilationUnit(TypeConstants.MODULE_INFO_FILE_NAME_STRING);
if (unit instanceof CompilationUnit && unit.exists()) {
- info = (CompilationUnitElementInfo) ((CompilationUnit) unit)
- .getElementInfo();
- if (info != null)
- return info.getModule();
+ IType type = unit.getType(new String(TypeConstants.MODULE_INFO_NAME));
+ ModuleInfo decl = (ModuleInfo)((SourceType)type).getElementInfo();
+ if (decl != null) {
+ JavaProject prj = (JavaProject) this.getAncestor(IJavaElement.JAVA_PROJECT);
+ module = new Module(new ProjectEntry(prj), decl);
+ rootInfo.setModule(module);
+ return module;
+ }
+// info = (CompilationUnitElementInfo) ((CompilationUnit) unit)
+// .getElementInfo();
+// if (info != null)
+// return info.getModule();
}
} else {
IClassFile classFile = ((IPackageFragment)pkgs[j]).getClassFile(TypeConstants.MODULE_INFO_CLASS_NAME_STRING);
if (classFile instanceof ClassFile && classFile.exists()) {
IType type = classFile.getType();
- IModule mod = (IModule) ((ClassFileReader)(((BinaryType)type).getElementInfo())).getModuleDeclaration();
- if (mod instanceof ModuleInfo)
- ((ModuleInfo) mod).entry = (JrtPackageFragmentRoot)this;
+ org.eclipse.jdt.internal.compiler.env.IModuleDeclaration decl = ((ClassFileReader)(((BinaryType)type).getElementInfo())).getModuleDeclaration();
+ if (decl != null) {
+ org.eclipse.jdt.internal.compiler.env.IModule mod = new Module((JrtPackageFragmentRoot)this, decl);
+ rootInfo.setModule(mod);
+ return mod;
+ }
}
}
break;
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java
index 295601e63d..8815af2eca 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java
@@ -24,7 +24,6 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
@@ -36,6 +35,7 @@ import org.eclipse.jdt.internal.compiler.env.TypeLookup;
import org.eclipse.jdt.internal.compiler.lookup.ModuleEnvironment;
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
+import org.eclipse.jdt.internal.core.Module;
import org.eclipse.jdt.internal.core.util.Util;
public class ClasspathDirectory extends ClasspathLocation implements IModuleEnvironment {
@@ -137,10 +137,7 @@ String[] directoryList(String qualifiedPackageName) {
}
void acceptModule(ClassFileReader classfile) {
if (classfile != null) {
- this.module = classfile.getModuleDeclaration();
- if (this.module instanceof ModuleInfo) {
- ((ModuleInfo)this.module).entry = this;
- }
+ this.module = new Module(this, classfile.getModuleDeclaration());
}
}
boolean doesFileExist(String fileName, String qualifiedPackageName, String qualifiedFullName) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
index bd87fd0b06..aba726771b 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
@@ -21,7 +21,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
@@ -33,6 +32,7 @@ import org.eclipse.jdt.internal.compiler.env.TypeLookup;
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
+import org.eclipse.jdt.internal.core.Module;
import org.eclipse.jdt.internal.core.util.Util;
import java.io.*;
@@ -110,10 +110,7 @@ void acceptModule(ClassFileReader classfile) {
// if ((this.module = classfile.getModuleDeclaration()) != null) {
// this.env.acceptModule(this.module, this);
// }
- this.module = classfile.getModuleDeclaration();
- if (this.module instanceof ModuleInfo) {
- ((ModuleInfo)this.module).entry = this;
- }
+ this.module = new Module(this, classfile.getModuleDeclaration());
}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java
index 168e44e5b8..0fbb63212f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java
@@ -31,8 +31,8 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo;
import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
import org.eclipse.jdt.internal.compiler.env.IModuleEnvironment;
import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
import org.eclipse.jdt.internal.compiler.env.IMultiModuleEntry;
@@ -45,6 +45,7 @@ import org.eclipse.jdt.internal.compiler.env.TypeLookup;
import org.eclipse.jdt.internal.compiler.util.JRTUtil;
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
+import org.eclipse.jdt.internal.core.Module;
public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry, IModuleEnvironment {
@@ -175,16 +176,14 @@ void acceptModule(byte[] content) {
e.printStackTrace();
}
if (reader != null) {
- IModule moduleDecl = reader.getModuleDeclaration();
+ IModuleDeclaration moduleDecl = reader.getModuleDeclaration();
if (moduleDecl != null) {
Set<IModule> cache = ModulesCache.get(this.zipFilename);
if (cache == null) {
ModulesCache.put(this.zipFilename, cache = new HashSet<IModule>());
}
- cache.add(moduleDecl);
- if (moduleDecl instanceof ModuleInfo) {
- ((ModuleInfo)moduleDecl).entry = this;
- }
+ IModule module = new Module(this, moduleDecl);
+ cache.add(module);
}
}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java
index 8a847d09d9..63e6ecf453 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java
@@ -20,8 +20,10 @@ import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.parser.Parser;
+import org.eclipse.jdt.internal.core.Module;
import org.eclipse.jdt.internal.core.ModuleInfo;
import org.eclipse.jdt.internal.core.util.Util;
@@ -80,10 +82,9 @@ public void acceptModuleInfo(ICompilationUnit cu, Parser parser) {
CompilationUnitDeclaration unit = parser.parse(cu, compilationResult);
// Request could also come in when module-info has changed or removed.
if (unit.isModuleInfo() && unit.moduleDeclaration != null) {
- IModule mod = ModuleInfo.createModule(unit.moduleDeclaration);
- if (mod != null) {
- this.module = mod;
- ((ModuleInfo)this.module).entry = this;
+ IModuleDeclaration decl = ModuleInfo.createModule(unit.moduleDeclaration);
+ if (decl != null) {
+ this.module = new Module(this, decl);
}
}
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
index a7bea87eac..411729ba35 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
@@ -29,10 +29,10 @@ import org.eclipse.jdt.internal.compiler.env.ClassSignature;
import org.eclipse.jdt.internal.compiler.env.EnumConstantSignature;
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair;
-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;
-import org.eclipse.jdt.internal.compiler.env.IModule.IService;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IModuleReference;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IPackageExport;
+import org.eclipse.jdt.internal.compiler.env.IModuleDeclaration.IService;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
@@ -641,7 +641,7 @@ public class BinaryIndexer extends AbstractIndexer implements SuffixConstants {
final String path = this.document.getPath();
ClassFileReader reader = new ClassFileReader(contents, path == null ? null : path.toCharArray());
- IModule module = reader.getModuleDeclaration();
+ IModuleDeclaration module = reader.getModuleDeclaration();
if (module != null) {
indexModule(module);
return;
@@ -839,7 +839,7 @@ public class BinaryIndexer extends AbstractIndexer implements SuffixConstants {
}
}
- private void indexModule(IModule module) {
+ private void indexModule(IModuleDeclaration module) {
addModuleDeclaration(module.name());
IModuleReference[] requiredModules = module.requires();
if (requiredModules != null) {

Back to the top