Example #1
0
  public ClosureCodegen(
      @NotNull GenerationState state,
      @NotNull JetElement element,
      @Nullable SamType samType,
      @NotNull ClosureContext context,
      @NotNull KotlinSyntheticClass.Kind syntheticClassKind,
      @NotNull FunctionGenerationStrategy strategy,
      @NotNull MemberCodegen<?> parentCodegen,
      @NotNull ClassBuilder classBuilder) {
    super(state, parentCodegen, context, element, classBuilder);

    this.funDescriptor = context.getFunctionDescriptor();
    this.classDescriptor = context.getContextDescriptor();
    this.samType = samType;
    this.syntheticClassKind = syntheticClassKind;
    this.strategy = strategy;

    if (samType == null) {
      this.superInterfaceTypes = new ArrayList<JetType>();

      JetType superClassType = null;
      for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
        ClassifierDescriptor classifier = supertype.getConstructor().getDeclarationDescriptor();
        if (DescriptorUtils.isTrait(classifier)) {
          superInterfaceTypes.add(supertype);
        } else {
          assert superClassType == null
              : "Closure class can't have more than one superclass: " + funDescriptor;
          superClassType = supertype;
        }
      }
      assert superClassType != null : "Closure class should have a superclass: " + funDescriptor;

      this.superClassType = superClassType;
    } else {
      this.superInterfaceTypes = Collections.singletonList(samType.getType());
      this.superClassType = getBuiltIns(funDescriptor).getAnyType();
    }

    this.closure = bindingContext.get(CLOSURE, classDescriptor);
    assert closure != null : "Closure must be calculated for class: " + classDescriptor;

    this.asmType = typeMapper.mapClass(classDescriptor);

    visibilityFlag = AsmUtil.getVisibilityAccessFlagForAnonymous(classDescriptor);
  }
Example #2
0
  @NotNull
  private static InnerModifierCheckResult checkIllegalInner(
      @NotNull DeclarationDescriptor descriptor) {
    if (!(descriptor instanceof ClassDescriptor)) return InnerModifierCheckResult.ILLEGAL_POSITION;
    ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;

    if (classDescriptor.getKind() != ClassKind.CLASS)
      return InnerModifierCheckResult.ILLEGAL_POSITION;

    DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
    if (!(containingDeclaration instanceof ClassDescriptor))
      return InnerModifierCheckResult.ILLEGAL_POSITION;

    if (DescriptorUtils.isTrait(containingDeclaration)) {
      return InnerModifierCheckResult.IN_TRAIT;
    } else if (DescriptorUtils.isObject(containingDeclaration)) {
      return InnerModifierCheckResult.IN_OBJECT;
    } else {
      return InnerModifierCheckResult.ALLOWED;
    }
  }