private static void addModuleReferences(PsiElement moduleRef, PsiFile originalFile, CompletionResultSet result) {
    PsiElement statement = moduleRef.getParent();
    boolean requires;
    if ((requires = statement instanceof PsiRequiresStatement) || statement instanceof PsiPackageAccessibilityStatement) {
      PsiElement parent = statement.getParent();
      if (parent != null) {
        Project project = moduleRef.getProject();
        Set<String> filter = new HashSet<>();
        filter.add(((PsiJavaModule)parent).getName());

        JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
        GlobalSearchScope scope = ProjectScope.getAllScope(project);
        for (String name : index.getAllKeys(project)) {
          if (!index.getModules(name, project, scope).isEmpty() && filter.add(name)) {
            LookupElement lookup = LookupElementBuilder.create(name).withIcon(AllIcons.Nodes.JavaModule);
            if (requires) lookup = TailTypeDecorator.withTail(lookup, TailTypes.semicolonType());
            result.addElement(lookup);
          }
        }

        if (requires) {
          Module module = ModuleUtilCore.findModuleForFile(originalFile);
          if (module != null) {
            scope = ProjectScope.getAllScope(project);
            Set<String> shadowedNames = new HashSet<>();
            for (String name : JavaSourceModuleNameIndex.getAllKeys(project)) {
              Collection<VirtualFile> manifests = JavaSourceModuleNameIndex.getFilesByKey(name, scope);
              if (!manifests.isEmpty()) {
                shadowedNames.add(name);
                for (VirtualFile manifest : manifests) {
                  VirtualFile jarRoot = manifest.getParent().getParent();
                  if (jarRoot.getFileSystem() instanceof JarFileSystem) {
                    shadowedNames.add(LightJavaModule.moduleName(jarRoot.getNameWithoutExtension()));
                  }
                }
                addAutoModuleReference(name, parent, filter, result);
              }
            }
            VirtualFile[] roots = ModuleRootManager.getInstance(module).orderEntries().withoutSdk().librariesOnly().getClassesRoots();
            scope = GlobalSearchScope.filesScope(project, Arrays.asList(roots));
            for (String name : JavaAutoModuleNameIndex.getAllKeys(project)) {
              if (shadowedNames.contains(name)) {
                continue;
              }
              if (!JavaAutoModuleNameIndex.getFilesByKey(name, scope).isEmpty()) {
                addAutoModuleReference(name, parent, filter, result);
              }
            }
          }
        }
      }
    }
  }
private static void addModuleReferences(PsiElement moduleRef, PsiFile originalFile, CompletionResultSet result)