private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
      NamespaceDescriptor packageDescriptor, FqName path, boolean includeObjectDeclarations) {
    if (path.isRoot()) {
      return Collections.emptyList();
    }

    Collection<JetScope> scopes = Arrays.asList(packageDescriptor.getMemberScope());

    List<Name> names = path.pathSegments();
    if (names.size() > 1) {
      for (Name subName : path.pathSegments().subList(0, names.size() - 1)) {
        Collection<JetScope> tempScopes = Lists.newArrayList();
        for (JetScope scope : scopes) {
          ClassifierDescriptor classifier = scope.getClassifier(subName);
          if (classifier instanceof ClassDescriptorBase) {
            ClassDescriptorBase classDescriptor = (ClassDescriptorBase) classifier;
            tempScopes.add(classDescriptor.getUnsubstitutedInnerClassesScope());
          }
        }
        scopes = tempScopes;
      }
    }

    Name shortName = path.shortName();
    Collection<ClassDescriptor> resultClassifierDescriptors = Lists.newArrayList();
    for (JetScope scope : scopes) {
      ClassifierDescriptor classifier = scope.getClassifier(shortName);
      if (classifier instanceof ClassDescriptor) {
        resultClassifierDescriptors.add((ClassDescriptor) classifier);
      }
      if (includeObjectDeclarations) {
        ClassDescriptor objectDescriptor = scope.getObjectDescriptor(shortName);
        if (objectDescriptor != null) {
          resultClassifierDescriptors.add(objectDescriptor);
        }
      }
    }

    return resultClassifierDescriptors;
  }
  @NotNull
  private LookupResult lookupSimpleNameReference(
      @NotNull JetSimpleNameExpression referenceExpression,
      @NotNull JetScope outerScope,
      @NotNull LookupMode lookupMode,
      boolean namespaceLevel) {

    Name referencedName = referenceExpression.getReferencedNameAsName();

    Set<DeclarationDescriptor> descriptors = Sets.newHashSet();
    NamespaceDescriptor namespaceDescriptor = outerScope.getNamespace(referencedName);
    if (namespaceDescriptor != null) {
      descriptors.add(namespaceDescriptor);
    }

    ClassifierDescriptor classifierDescriptor = outerScope.getClassifier(referencedName);
    if (classifierDescriptor != null) {
      descriptors.add(classifierDescriptor);
    }

    if (lookupMode == LookupMode.ONLY_CLASSES) {
      ClassDescriptor objectDescriptor = outerScope.getObjectDescriptor(referencedName);
      if (objectDescriptor != null) {
        descriptors.add(objectDescriptor);
      }
    } else {
      descriptors.addAll(outerScope.getFunctions(referencedName));
      descriptors.addAll(outerScope.getProperties(referencedName));

      VariableDescriptor localVariable = outerScope.getLocalVariable(referencedName);
      if (localVariable != null) {
        descriptors.add(localVariable);
      }
    }
    return new SuccessfulLookupResult(descriptors, outerScope, namespaceLevel);
  }