List<ModuleBinding> otherRelevantModules(char[][] declaringModuleNames) { if (isUnnamed() && declaringModuleNames != null) { // unnamed module reads all named modules, // so all modules declaring the given package are relevant: return Arrays.stream(declaringModuleNames) .filter(modName -> modName != UNNAMED) .map(modName -> this.environment.getModule(modName)) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return Arrays.asList(getAllRequiredModules()); } }
@Override protected AnnotationBinding[] getAnnotationBindings() { return ((ModuleBinding) _binding).getAnnotations(); }
@Override public List<? extends ModuleElement> getTargetModules() { if(this.targets != null) { return targets; } return getTargetModules(ModuleElementImpl.this.binding.getExportRestrictions(this.binding)); }
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { if ("package-info".equals(new String(typeDeclaration.name))) { context.enter(factory.Package().getOrCreate(new String(typeDeclaration.binding.fPackage.readableName())), typeDeclaration); return true; } else { CtModule module; // skip the type declaration that are already declared if (typeDeclaration.binding == null && getFactory().getEnvironment().isIgnoreDuplicateDeclarations()) { return false; } if (typeDeclaration.binding.module != null && !typeDeclaration.binding.module.isUnnamed() && typeDeclaration.binding.module.shortReadableName() != null && typeDeclaration.binding.module.shortReadableName().length > 0) { module = factory.Module().getOrCreate(String.valueOf(typeDeclaration.binding.module.shortReadableName())); } else { module = factory.Module().getUnnamedModule(); } CtPackage pack; if (typeDeclaration.binding.fPackage.shortReadableName() != null && typeDeclaration.binding.fPackage.shortReadableName().length > 0) { pack = factory.Package().getOrCreate(new String(typeDeclaration.binding.fPackage.shortReadableName()), module); } else { pack = module.getRootPackage(); } context.enter(pack, typeDeclaration); pack.addType(helper.createType(typeDeclaration)); return true; } }
Stream<ModuleBinding> getRequiredModules(boolean transitiveOnly) { return Stream.of(transitiveOnly ? this.getRequiresTransitive() : this.getRequires()); } private void collectAllDependencies(Set<ModuleBinding> deps) {
this.directives = new ArrayList<>(); PackageBinding[] packs = this.binding.getExports(); for (PackageBinding exp : packs) { exp = getModulesPackageBinding(exp); for (ModuleBinding mBinding : this.binding.getRequiresTransitive()) { transitive.add(mBinding); ModuleBinding[] required = this.binding.getRequires(); for (ModuleBinding mBinding : required) { if (transitive.contains(mBinding)) { TypeBinding[] tBindings = this.binding.getUses(); for (TypeBinding tBinding : tBindings) { this.directives.add(new UsesDirectiveImpl(tBinding)); tBindings = this.binding.getServices(); for (TypeBinding tBinding : tBindings) { this.directives.add(new ProvidesDirectiveImpl(tBinding)); packs = this.binding.getOpens(); for (PackageBinding exp : packs) { exp = getModulesPackageBinding(exp);
private void matchPackageReferences(SearchPattern pattern, MatchLocator locator) throws CoreException { // Only process PackageReference patterns switch (pattern.kind) { case PKG_REF_PATTERN: break; case OR_PATTERN: SearchPattern[] patterns = ((OrPattern) pattern).patterns; for (int i = 0, length = patterns.length; i < length; i++) { SearchPattern p = patterns[i]; if (p.kind == PKG_REF_PATTERN) matchPackageReferences(patterns[i], locator); } // $FALL-THROUGH$ - fall through default to return default: return; } matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getExports()); matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getOpens()); matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getUses()); TypeBinding[] services = this.module.getServices(); if (services != null) { matchPackReferences(locator, (PackageReferencePattern) pattern, services); for (TypeBinding service : services) { matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getImplementations(service)); } } } private void matchPackReferences(MatchLocator locator, PackageReferencePattern packReferencePattern,
if (packageBinding == null || packageBinding == TheNotFoundPackage) { if (this.useModuleSystem) { if (this.module.isUnnamed()) { char[][] declaringModules = ((IModuleAwareNameEnvironment) this.nameEnvironment).getModulesDeclaringPackage(null, constantPoolName[0], ModuleBinding.ANY); if (declaringModules != null) { ModuleBinding declaringModule = this.root.getModule(mod); if (declaringModule != null) packageBinding = SplitPackageBinding.combine(declaringModule.getTopLevelPackage(constantPoolName[0]), packageBinding, this.module); packageBinding = this.module.getTopLevelPackage(constantPoolName[0]); if ((packageBinding = parent.getPackage0(constantPoolName[i])) == null || packageBinding == TheNotFoundPackage) { if (this.useModuleSystem) { if (this.module.isUnnamed()) { char[][] declaringModules = ((IModuleAwareNameEnvironment) this.nameEnvironment).getModulesDeclaringPackage(parent.compoundName, constantPoolName[i], ModuleBinding.ANY); if (declaringModules != null) { ModuleBinding declaringModule = this.root.getModule(mod); if (declaringModule != null) packageBinding = SplitPackageBinding.combine(declaringModule.getPackage(parent.compoundName, constantPoolName[i]), packageBinding, this.module); packageBinding = this.module.getVisiblePackage(parent, constantPoolName[i]);
mod.getExports(); mod.getRequires(); mod.getOpens(); mod.getServices();
private void matchTypeReferences(SearchPattern pattern, MatchLocator locator) throws CoreException { // Only process TypeReference patterns switch (pattern.kind) { case TYPE_REF_PATTERN: break; case OR_PATTERN: SearchPattern[] patterns = ((OrPattern) pattern).patterns; for (int i = 0, length = patterns.length; i < length; i++) { SearchPattern p = patterns[i]; if (p.kind == TYPE_REF_PATTERN) matchTypeReferences(patterns[i], locator); } // $FALL-THROUGH$ - fall through default to return default: return; } matchTypeReferences(locator, (TypeReferencePattern) pattern, this.module.getUses()); TypeBinding[] services = this.module.getServices(); if (services != null) { matchTypeReferences(locator, (TypeReferencePattern) pattern, services); for (TypeBinding service : services) { matchTypeReferences(locator, (TypeReferencePattern) pattern, this.module.getImplementations(service)); } } } private void matchTypeReferences(MatchLocator locator, TypeReferencePattern typeReferencePattern,
return pkg.enclosingModule == this; // no transitive export PackageBinding[] initializedExports = getExports(); for (int i = 0; i < initializedExports.length; i++) { PackageBinding export = initializedExports[i]; SimpleSetOfCharArray restrictions = this.exportRestrictions.get(export); if (restrictions != null) { if (client.isUnnamed()) return restrictions.includes(ALL_UNNAMED); else return restrictions.includes(client.name());
return null; else return addPackage(pkg, false); if (this.environment.useModuleSystem) { IModuleAwareNameEnvironment moduleEnv = (IModuleAwareNameEnvironment) this.environment.nameEnvironment; char[][] declaringModuleNames = moduleEnv.getModulesDeclaringPackage(parentName, name, nameForLookup()); if (declaringModuleNames != null) { if (!this.isUnnamed() && CharOperation.containsEqual(declaringModuleNames, this.moduleName)) { ModuleBinding declaringModule = this.environment.root.getModule(declaringModuleName); if (declaringModule != null && !declaringModule.isPackageLookupActive) { PackageBinding declaredPackage = declaringModule.getDeclaredPackage(parentName, name); if (declaredPackage != null) { if (!isUnnamed()) { binding = combineWithPackagesFromRequired(binding, subPkgCompoundName); else if (parent != null) binding = parent.addPackage(binding, this, false); return addPackage(binding, false);
unique.add(getModulesPackageBinding(p)); if (module.isUnnamed()) { PackageBinding def = module.environment.defaultPackage; packs = this.binding.getExports(); for (PackageBinding pBinding : packs) { unique.add(getModulesPackageBinding(pBinding)); packs = this.binding.getOpens(); for (PackageBinding pBinding : packs) { unique.add(getModulesPackageBinding(pBinding));
/** * Is this package exported from its module? * Does not consider export restrictions. */ public boolean isExported() { if (this.isExported == null) { this.enclosingModule.getExports(); // ensure resolved and completed if (this.isExported == null) this.isExported = Boolean.FALSE; } return this.isExported == Boolean.TRUE; } /**
public void analyseModuleGraph(CompilationUnitScope skope) { if (this.requires != null) { // collect transitively: Map<String, Set<ModuleBinding>> pack2mods = new HashMap<>(); for (ModuleBinding requiredModule : this.binding.getAllRequiredModules()) { for (PackageBinding exportedPackage : requiredModule.getExports()) { if (this.binding.canAccess(exportedPackage)) { String packName = String.valueOf(exportedPackage.readableName()); Set<ModuleBinding> mods = pack2mods.get(packName); if (mods == null) pack2mods.put(packName, mods = new HashSet<>()); mods.add(requiredModule); } } } // report against the causing requires directives: for (RequiresStatement requiresStat : this.requires) { ModuleBinding requiredModule = requiresStat.resolvedBinding; if (requiredModule != null) { if (requiredModule.isDeprecated()) skope.problemReporter().deprecatedModule(requiresStat.module, requiredModule); analyseOneDependency(requiresStat, requiredModule, skope, pack2mods); if (requiresStat.isTransitive()) { for (ModuleBinding secondLevelModule : requiredModule.getAllRequiredModules()) analyseOneDependency(requiresStat, secondLevelModule, skope, pack2mods); } } } } }
char[] packageName = packageBinding.readableName(); if (checkForSplit && this.environment.useModuleSystem) { if (isUnnamed()) { IModuleAwareNameEnvironment moduleEnv = (IModuleAwareNameEnvironment) this.environment.nameEnvironment; char[][] declaringModuleNames = moduleEnv.getModulesDeclaringPackage(null, packageName, ANY); ModuleBinding otherModule = this.environment.getModule(declaringModuleNames[i]); if (otherModule != null && !otherModule.isPackageLookupActive) packageBinding = SplitPackageBinding.combine(otherModule.getVisiblePackage(packageBinding.compoundName), packageBinding, this); packageBinding = combineWithPackagesFromRequired(packageBinding, packageBinding.compoundName);
@Override public TypeBinding[] getImplementations(TypeBinding binding) { if (this.implementations == null) resolveServices(); return super.getImplementations(binding); } private void resolveServices() {
@Override public PackageElement getPackageElement(ModuleElement module, CharSequence name) { ModuleBinding mBinding = ((ModuleElementImpl) module).binding; final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray()); PackageBinding p = null; if (mBinding != null) { int length = compoundName.length; if (length > 1) { char[][] parent = new char[compoundName.length - 1][]; System.arraycopy(compoundName, 0, parent, 0, length - 1); p = mBinding.getPackage(parent, compoundName[length - 1]); } else { p = mBinding.getTopLevelPackage(compoundName[0]); } } else { p = _env.getLookupEnvironment().createPackage(compoundName); } if (p == null || !p.isValidBinding()) return null; return (PackageElement) _env.getFactory().newElement(p); } }
public void deprecatedModule(ModuleReference moduleReference, ModuleBinding requiredModule) { String sinceValue = deprecatedSinceValue(() -> requiredModule.getAnnotations()); boolean isTerminally = (requiredModule.tagBits & TagBits.AnnotationTerminallyDeprecated) != 0; if (sinceValue != null) { String[] args = { String.valueOf(requiredModule.name()), sinceValue }; handle( isTerminally ? IProblem.UsingTerminallyDeprecatedSinceVersionModule : IProblem.UsingDeprecatedSinceVersionModule, args, args, moduleReference.sourceStart, moduleReference.sourceEnd); } else { String[] args = { String.valueOf(requiredModule.name()) }; handle( isTerminally ? IProblem.UsingTerminallyDeprecatedModule : IProblem.UsingDeprecatedModule, args, args, moduleReference.sourceStart, moduleReference.sourceEnd); } } String deprecatedSinceValue(Supplier<AnnotationBinding[]> annotations) {
public void analyseModuleGraph(CompilationUnitScope skope) { if (this.requires != null) { // collect transitively: Map<String, Set<ModuleBinding>> pack2mods = new HashMap<>(); for (ModuleBinding requiredModule : this.binding.getAllRequiredModules()) { for (PackageBinding exportedPackage : requiredModule.getExports()) { if (this.binding.canAccess(exportedPackage)) { String packName = String.valueOf(exportedPackage.readableName()); Set<ModuleBinding> mods = pack2mods.get(packName); if (mods == null) pack2mods.put(packName, mods = new HashSet<>()); mods.add(requiredModule); } } } // report against the causing requires directives: for (RequiresStatement requiresStat : this.requires) { ModuleBinding requiredModule = requiresStat.resolvedBinding; if (requiredModule != null) { analyseOneDependency(requiresStat, requiredModule, skope, pack2mods); if (requiresStat.isTransitive()) { for (ModuleBinding secondLevelModule : requiredModule.getAllRequiredModules()) analyseOneDependency(requiresStat, secondLevelModule, skope, pack2mods); } } } } }