Exemplo n.º 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;
      }
    }
Exemplo n.º 2
0
    @Override
    public void visitClass(@NotNull JetClass klass) {
      MutableClassDescriptor mutableClassDescriptor =
          createClassDescriptorForClass(klass, owner.getOwnerForChildren());

      owner.addClassifierDescriptor(mutableClassDescriptor);
    }
Exemplo n.º 3
0
    @Override
    public void visitEnumEntry(@NotNull JetEnumEntry declaration) {
      MutableClassDescriptor descriptor =
          createClassDescriptorForSingleton(
              declaration, JetPsiUtil.safeName(declaration.getName()), ClassKind.ENUM_ENTRY);

      owner.addClassifierDescriptor(descriptor);

      descriptor.getBuilder().setClassObjectDescriptor(createSyntheticClassObject(descriptor));
    }
Exemplo n.º 4
0
    @NotNull
    private MutableClassDescriptor createClassDescriptorForSingleton(
        @NotNull JetClassOrObject declaration, @NotNull Name name, @NotNull ClassKind kind) {
      MutableClassDescriptor descriptor =
          new MutableClassDescriptor(owner.getOwnerForChildren(), outerScope, kind, false, name);

      prepareForDeferredCall(
          descriptor.getScopeForMemberDeclarationResolution(), descriptor, declaration);

      createPrimaryConstructorForObject(declaration, descriptor);
      trace.record(BindingContext.CLASS, declaration, descriptor);

      c.getClasses().put(declaration, descriptor);

      return descriptor;
    }
Exemplo n.º 5
0
    @Override
    public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) {
      if (declaration.isObjectLiteral()) {
        createClassDescriptorForSingleton(
            declaration, SpecialNames.NO_NAME_PROVIDED, ClassKind.CLASS);
        return;
      }

      MutableClassDescriptor descriptor =
          createClassDescriptorForSingleton(
              declaration, JetPsiUtil.safeName(declaration.getName()), ClassKind.OBJECT);

      owner.addClassifierDescriptor(descriptor);
      trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getUnsafeFQName(declaration), descriptor);

      descriptor.getBuilder().setClassObjectDescriptor(createSyntheticClassObject(descriptor));
    }