@Nullable
  private JetType getExtendedClassObjectType(
      @NotNull JetType classObjectType,
      @NotNull Name referencedName,
      @NotNull ClassifierDescriptor classifier,
      @NotNull ResolutionContext context) {
    if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
        && classifier instanceof ClassDescriptor) {
      List<JetScope> scopes = new ArrayList<JetScope>(3);

      scopes.add(classObjectType.getMemberScope());
      scopes.add(getStaticNestedClassesScope((ClassDescriptor) classifier));

      NamespaceDescriptor namespace = context.scope.getNamespace(referencedName);
      if (namespace != null) {
        scopes.add(namespace.getMemberScope());
      }

      JetScope scope = new ChainedScope(classifier, scopes.toArray(new JetScope[scopes.size()]));
      return new NamespaceType(referencedName, scope);
    } else if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
        || classifier.isClassObjectAValue()) {
      return classObjectType;
    } else {
      return null;
    }
  }
 @Nullable
 private JetType lookupNamespaceOrClassObject(
     @NotNull JetSimpleNameExpression expression, @NotNull ResolutionContext context) {
   Name referencedName = expression.getReferencedNameAsName();
   ClassifierDescriptor classifier = context.scope.getClassifier(referencedName);
   if (classifier != null) {
     JetType classObjectType = classifier.getClassObjectType();
     if (classObjectType != null) {
       context.trace.record(REFERENCE_TARGET, expression, classifier);
       JetType result;
       if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
           && classifier instanceof ClassDescriptor) {
         JetScope scope =
             new ChainedScope(
                 classifier,
                 classObjectType.getMemberScope(),
                 getStaticNestedClassesScope((ClassDescriptor) classifier));
         result = new NamespaceType(referencedName, scope);
       } else if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
           || classifier.isClassObjectAValue()) {
         result = classObjectType;
       } else {
         context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
         result = null;
       }
       return DataFlowUtils.checkType(result, expression, context);
     }
   }
   JetType[] result = new JetType[1];
   TemporaryBindingTrace temporaryTrace =
       TemporaryBindingTrace.create(
           context.trace, "trace for namespace/class object lookup of name", referencedName);
   if (furtherNameLookup(expression, result, context.replaceBindingTrace(temporaryTrace))) {
     temporaryTrace.commit();
     return DataFlowUtils.checkType(result[0], expression, context);
   }
   // To report NO_CLASS_OBJECT when no namespace found
   if (classifier != null) {
     if (context.expressionPosition == ExpressionPosition.FREE) {
       context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
     }
     context.trace.record(REFERENCE_TARGET, expression, classifier);
     JetScope scopeForStaticMembersResolution =
         classifier instanceof ClassDescriptor
             ? getStaticNestedClassesScope((ClassDescriptor) classifier)
             : JetScope.EMPTY;
     return new NamespaceType(referencedName, scopeForStaticMembersResolution);
   }
   temporaryTrace.commit();
   return result[0];
 }