@NotNull
 private Set<PsiPackage> getContext() {
   if (myIndex == 0) return myReferenceSet.getInitialContext();
   Set<PsiPackage> psiPackages = new HashSet<>();
   for (ResolveResult resolveResult : myReferenceSet.getReference(myIndex - 1).doMultiResolve()) {
     PsiElement psiElement = resolveResult.getElement();
     if (psiElement instanceof PsiPackage) {
       psiPackages.add((PsiPackage) psiElement);
     }
   }
   return psiPackages;
 }
 @NotNull
 protected ResolveResult[] doMultiResolve() {
   final Collection<PsiPackage> packages = new HashSet<>();
   for (PsiPackage parentPackage : getContext()) {
     packages.addAll(myReferenceSet.resolvePackageName(parentPackage, getValue()));
   }
   return PsiElementResolveResult.createResults(packages);
 }
  @Override
  @NotNull
  public Object[] getVariants() {
    Set<PsiPackage> subPackages = new HashSet<>();
    for (PsiPackage psiPackage : getContext()) {
      subPackages.addAll(
          Arrays.asList(psiPackage.getSubPackages(myReferenceSet.getResolveScope())));
    }

    return subPackages.toArray();
  }
 public PsiPackageReference(
     final PackageReferenceSet set, final TextRange range, final int index) {
   super(set.getElement(), range, set.isSoft());
   myReferenceSet = set;
   myIndex = index;
 }