public void indexStub(GrFileStub stub, IndexSink sink) {
   String name = stub.getName().toString();
   if (stub.isScript() && name != null) {
     sink.occurrence(GrScriptClassNameIndex.KEY, name);
     final String pName = stub.getPackageName().toString();
     final String fqn = pName == null || pName.length() == 0 ? name : pName + "." + name;
     sink.occurrence(GrFullScriptNameIndex.KEY, fqn.hashCode());
   }
 }
  @Override
  public void indexClass(PsiJetClassStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
      sink.occurrence(JetIndexKeys.SHORT_NAME_KEY, name);
    }

    String fqn = stub.getQualifiedName();
    if (fqn != null) {
      sink.occurrence(JetIndexKeys.FQN_KEY, fqn);
    }
  }
  @Override
  public void indexFile(PsiJetFileStub stub, IndexSink sink) {
    String packageName = stub.getPackageName();
    FqName fqName = new FqName(packageName == null ? "" : packageName);

    sink.occurrence(JetPackageDeclarationIndex.getInstance().getKey(), fqName.getFqName());

    while (true) {
      sink.occurrence(JetAllPackagesIndex.getInstance().getKey(), fqName.getFqName());
      if (fqName.isRoot()) {
        return;
      }
      fqName = fqName.parent();
    }
  }
  @Override
  public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
    String propertyName = stub.getName();
    if (propertyName != null) {
      if (stub.isTopLevel()) {
        FqName topFQName = stub.getTopFQName();
        if (topFQName != null) {
          sink.occurrence(
              JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.getFqName());
        }
      }

      sink.occurrence(JetShortPropertiesNameIndex.getInstance().getKey(), propertyName);
    }
  }
 @Override
 public void indexFunction(PsiJetFunctionStub stub, IndexSink sink) {
   String name = stub.getName();
   if (name != null) {
     if (stub.isTopLevel()) {
       // Collection only top level functions as only they are expected in completion without
       // explicit import
       if (!stub.isExtension()) {
         sink.occurrence(JetIndexKeys.TOP_LEVEL_FUNCTION_SHORT_NAME_KEY, name);
         // sink.occurrence(JetIndexKeys.TOP_LEVEL_FUNCTION_FQNAME_KEY, name);
       } else {
         sink.occurrence(JetIndexKeys.EXTENSION_FUNCTION_SHORT_NAME_KEY, name);
         // sink.occurrence(JetIndexKeys.EXTENSION_FUNCTION_FQNAME_KEY, name);
       }
     }
   }
 }
 @Override
 public void indexStub(@NotNull GrReferenceListStub stub, @NotNull IndexSink sink) {
   for (String name : stub.getBaseClasses()) {
     if (name != null) {
       sink.occurrence(GrDirectInheritorsIndex.KEY, PsiNameHelper.getShortClassName(name));
     }
   }
 }
  @Override
  public void indexObject(PsiJetObjectStub stub, IndexSink sink) {
    String name = stub.getName();
    assert name != null;

    sink.occurrence(JetShortClassNameIndex.getInstance().getKey(), name);

    if (stub.isTopLevel()) {
      sink.occurrence(JetTopLevelShortObjectNameIndex.getInstance().getKey(), name);
    }

    FqName fqName = stub.getFQName();
    if (fqName != null) {
      sink.occurrence(JetFullClassNameIndex.getInstance().getKey(), fqName.getFqName());
    }

    recordClassOrObjectByPackage(stub, sink);
  }
  @Override
  public void indexClass(PsiJetClassStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
      sink.occurrence(JetShortClassNameIndex.getInstance().getKey(), name);
    }

    String fqn = stub.getQualifiedName();
    if (fqn != null) {
      sink.occurrence(JetFullClassNameIndex.getInstance().getKey(), fqn);
    }

    for (String superName : stub.getSuperNames()) {
      sink.occurrence(JetSuperClassIndex.getInstance().getKey(), superName);
    }

    recordClassOrObjectByPackage(stub, sink);
  }
  @Override
  public void indexStub(@NotNull GrFileStub stub, @NotNull IndexSink sink) {
    String name = stub.getName().toString();
    if (stub.isScript() && name != null) {
      sink.occurrence(GrScriptClassNameIndex.KEY, name);
      final String pName = GrStubUtils.getPackageName(stub);
      final String fqn = StringUtil.isEmpty(pName) ? name : pName + "." + name;
      sink.occurrence(GrFullScriptNameIndex.KEY, fqn.hashCode());
    }

    for (String anno : stub.getAnnotations()) {
      sink.occurrence(GrAnnotatedMemberIndex.KEY, anno);
    }

    Integer fileId = stub.getUserData(IndexingDataKeys.VIRTUAL_FILE_ID);
    if (fileId == null) return;
    IndexTree.Unit unit = GrStubIndexer.translate(fileId, stub);
    sink.occurrence(JavaStubIndexKeys.UNITS, unit);
  }
 private static void recordClassOrObjectByPackage(
     StubElement<? extends JetClassOrObject> stub, IndexSink sink) {
   StubElement parentStub = stub.getParentStub();
   if (parentStub instanceof PsiJetFileStub) {
     PsiJetFileStub jetFileStub = (PsiJetFileStub) parentStub;
     String packageName = jetFileStub.getPackageName();
     if (packageName != null) {
       sink.occurrence(JetClassByPackageIndex.getInstance().getKey(), packageName);
     }
   }
 }
  @Override
  public void indexFunction(PsiJetFunctionStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
      if (stub.isTopLevel()) {
        // Collection only top level functions as only they are expected in completion without
        // explicit import
        if (!stub.isExtension()) {
          sink.occurrence(JetShortFunctionNameIndex.getInstance().getKey(), name);
        } else {
          sink.occurrence(JetExtensionFunctionNameIndex.getInstance().getKey(), name);
        }

        FqName topFQName = stub.getTopFQName();
        if (topFQName != null) {
          sink.occurrence(
              JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.getFqName());
        }
      }

      sink.occurrence(JetAllShortFunctionNameIndex.getInstance().getKey(), name);
    }
  }
 @Override
 public void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink) {
   sink.occurrence(JetAnnotationsIndex.getInstance().getKey(), stub.getShortName());
 }
 public void indexStub(@NotNull final PyFunctionStub stub, @NotNull final IndexSink sink) {
   final String name = stub.getName();
   if (name != null) {
     sink.occurrence(PyFunctionNameIndex.KEY, name);
   }
 }