@Override
    public void visitClassObject(@NotNull JetClassObject classObject) {
      JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();

      DeclarationDescriptor container = owner.getOwnerForChildren();

      MutableClassDescriptor classObjectDescriptor =
          createClassDescriptorForSingleton(
              objectDeclaration, getClassObjectName(container.getName()), ClassKind.CLASS_OBJECT);

      PackageLikeBuilder.ClassObjectStatus status =
          isEnumEntry(container)
                  || isObject(container)
                  || c.getTopDownAnalysisParameters().isDeclaredLocally()
              ? PackageLikeBuilder.ClassObjectStatus.NOT_ALLOWED
              : owner.setClassObjectDescriptor(classObjectDescriptor);

      switch (status) {
        case DUPLICATE:
          trace.report(MANY_CLASS_OBJECTS.on(classObject));
          break;
        case NOT_ALLOWED:
          trace.report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
          break;
        case OK:
          // Everything is OK so no errors to trace.
          break;
      }
    }
  @Override
  public void visitClassObject(JetClassObject classObject) {
    ClassDescriptor classDescriptor = bindingContext.get(CLASS, classObject.getObjectDeclaration());
    assert classDescriptor != null;

    JvmClassName name =
        JvmClassName.byInternalName(peekFromStack(nameStack) + JvmAbi.CLASS_OBJECT_SUFFIX);
    recordClosure(
        bindingTrace, classObject, classDescriptor, peekFromStack(classStack), name, false);

    classStack.push(classDescriptor);
    nameStack.push(name.getInternalName());
    super.visitClassObject(classObject);
    nameStack.pop();
    classStack.pop();
  }
Esempio n. 3
0
 @Nullable
 private JetClassLikeInfo getClassObjectInfo(JetClassObject classObject) {
   if (classObject != null) {
     if (!DescriptorUtils.inStaticContext(this)) {
       return null;
     }
     JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
     if (objectDeclaration != null) {
       return JetClassInfoUtil.createClassLikeInfo(objectDeclaration);
     }
   } else {
     if (getKind() == ClassKind.ENUM_CLASS) {
       // Enum classes always have class objects, and enum constants are their members
       return onlyEnumEntries(originalClassInfo);
     }
   }
   return null;
 }