Пример #1
0
    @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;
      }
    }
  private static String getJvmInternalFQNameImpl(
      BindingTrace bindingTrace, DeclarationDescriptor descriptor) {
    if (descriptor instanceof FunctionDescriptor) {
      throw new IllegalStateException("requested fq name for function: " + descriptor);
    }

    if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor
        || descriptor instanceof ScriptDescriptor) {
      return "";
    }

    if (descriptor instanceof ModuleDescriptor) {
      throw new IllegalStateException("missed something");
    }

    if (descriptor instanceof ClassDescriptor) {
      ClassDescriptor klass = (ClassDescriptor) descriptor;
      if (klass.getKind() == ClassKind.OBJECT || klass.getKind() == ClassKind.CLASS_OBJECT) {
        if (klass.getContainingDeclaration() instanceof ClassDescriptor) {
          ClassDescriptor containingKlass = (ClassDescriptor) klass.getContainingDeclaration();
          if (containingKlass.getKind() == ClassKind.ENUM_CLASS) {
            return getJvmInternalName(bindingTrace, containingKlass).getInternalName();
          } else {
            return getJvmInternalName(bindingTrace, containingKlass).getInternalName()
                + JvmAbi.CLASS_OBJECT_SUFFIX;
          }
        }
      }

      JvmClassName name = bindingTrace.getBindingContext().get(FQN, descriptor);
      if (name != null) {
        return name.getInternalName();
      }
    }

    DeclarationDescriptor container = descriptor.getContainingDeclaration();

    if (container == null) {
      throw new IllegalStateException("descriptor has no container: " + descriptor);
    }

    Name name = descriptor.getName();

    String baseName = getJvmInternalName(bindingTrace, container).getInternalName();
    if (!baseName.isEmpty()) {
      return baseName
          + (container instanceof NamespaceDescriptor ? "/" : "$")
          + name.getIdentifier();
    }

    return name.getIdentifier();
  }