private ClassDescriptor recordClassForFunction(FunctionDescriptor funDescriptor) {
    ClassDescriptor classDescriptor;
    int arity = funDescriptor.getValueParameters().size();

    classDescriptor =
        new ClassDescriptorImpl(
            funDescriptor.getContainingDeclaration(),
            Collections.<AnnotationDescriptor>emptyList(),
            Modality.FINAL,
            Name.special("<closure>"));
    ((ClassDescriptorImpl) classDescriptor)
        .initialize(
            false,
            Collections.<TypeParameterDescriptor>emptyList(),
            Collections.singleton(
                (funDescriptor.getReceiverParameter().exists()
                        ? JetStandardClasses.getReceiverFunction(arity)
                        : JetStandardClasses.getFunction(arity))
                    .getDefaultType()),
            JetScope.EMPTY,
            Collections.<ConstructorDescriptor>emptySet(),
            null);

    assert PsiCodegenPredictor.checkPredictedClassNameForFun(
        bindingContext, funDescriptor, classDescriptor);
    bindingTrace.record(CLASS_FOR_FUNCTION, funDescriptor, classDescriptor);
    return classDescriptor;
  }
  @Override
  public void visitClassType(String name, boolean nullable, boolean forceReal) {
    FqName ourName =
        new FqName(
            name.replace('/', '.').replace('$', '.') // TODO: not sure
            );

    this.classDescriptor = null;
    if (!forceReal) {
      classDescriptor =
          javaSemanticServices
              .getTypeTransformer()
              .getKotlinAnalog(ourName, JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_INVARIANT);
    }

    if (classDescriptor == null) {
      // TODO: this is the worst code in Kotlin project
      Matcher matcher = Pattern.compile("jet\\.Function(\\d+)").matcher(ourName.getFqName());
      if (matcher.matches()) {
        classDescriptor = JetStandardClasses.getFunction(Integer.parseInt(matcher.group(1)));
      }
    }

    if (classDescriptor == null) {
      Matcher matcher = Pattern.compile("jet\\.Tuple(\\d+)").matcher(ourName.getFqName());
      if (matcher.matches()) {
        classDescriptor = JetStandardClasses.getTuple(Integer.parseInt(matcher.group(1)));
      }
    }

    if (this.classDescriptor == null) {
      this.classDescriptor =
          javaDescriptorResolver.resolveClass(ourName, DescriptorSearchRule.INCLUDE_KOTLIN);
    }

    if (this.classDescriptor == null) {
      // TODO: report in to trace
      this.errorType = ErrorUtils.createErrorType("class not found by name: " + ourName);
    }
    this.nullable = nullable;
    this.typeArguments = new ArrayList<TypeProjection>();
  }
示例#3
0
  public static SimpleFunctionDescriptor createInvoke(FunctionDescriptor fd) {
    int arity = fd.getValueParameters().size();
    SimpleFunctionDescriptorImpl invokeDescriptor =
        new SimpleFunctionDescriptorImpl(
            fd.getExpectedThisObject().exists()
                ? JetStandardClasses.getReceiverFunction(arity)
                : JetStandardClasses.getFunction(arity),
            Collections.<AnnotationDescriptor>emptyList(),
            Name.identifier("invoke"),
            CallableMemberDescriptor.Kind.DECLARATION);

    invokeDescriptor.initialize(
        fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
        fd.getExpectedThisObject(),
        Collections.<TypeParameterDescriptorImpl>emptyList(),
        fd.getValueParameters(),
        fd.getReturnType(),
        Modality.FINAL,
        Visibilities.PUBLIC,
        /*isInline = */ false);
    return invokeDescriptor;
  }