Exemplo n.º 1
0
 public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
   for (JetFile file : bodiesResolveContext.getFiles()) {
     checkDeclarationContainer(file);
   }
   for (JetClass aClass : bodiesResolveContext.getClasses().keySet()) {
     if (!bodiesResolveContext.completeAnalysisNeeded(aClass)) continue;
     checkDeclarationContainer(aClass);
   }
   for (JetObjectDeclaration objectDeclaration : bodiesResolveContext.getObjects().keySet()) {
     if (!bodiesResolveContext.completeAnalysisNeeded(objectDeclaration)) continue;
     checkDeclarationContainer(objectDeclaration);
   }
   for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry :
       bodiesResolveContext.getFunctions().entrySet()) {
     JetNamedFunction function = entry.getKey();
     SimpleFunctionDescriptor functionDescriptor = entry.getValue();
     if (!bodiesResolveContext.completeAnalysisNeeded(function)) continue;
     final JetType expectedReturnType =
         !function.hasBlockBody() && !function.hasDeclaredReturnType()
             ? NO_EXPECTED_TYPE
             : functionDescriptor.getReturnType();
     checkFunction(function, expectedReturnType);
   }
   for (Map.Entry<JetProperty, PropertyDescriptor> entry :
       bodiesResolveContext.getProperties().entrySet()) {
     JetProperty property = entry.getKey();
     if (!bodiesResolveContext.completeAnalysisNeeded(property)) continue;
     PropertyDescriptor propertyDescriptor = entry.getValue();
     checkProperty(property, propertyDescriptor);
   }
 }
  @NotNull
  public static SimpleFunctionDescriptor createSamAdapterFunction(
      @NotNull SimpleFunctionDescriptor original) {
    SimpleFunctionDescriptorImpl result =
        new SimpleFunctionDescriptorImpl(
            original.getContainingDeclaration(),
            original.getAnnotations(),
            original.getName(),
            CallableMemberDescriptor.Kind.SYNTHESIZED);

    TypeParameters typeParameters =
        recreateAndInitializeTypeParameters(original.getTypeParameters(), result);

    JetType returnTypeUnsubstituted = original.getReturnType();
    assert returnTypeUnsubstituted != null : original;
    JetType returnType =
        typeParameters.substitutor.substitute(returnTypeUnsubstituted, Variance.OUT_VARIANCE);
    assert returnType != null
        : "couldn't substitute type: "
            + returnType
            + ", substitutor = "
            + typeParameters.substitutor;

    List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
    for (ValueParameterDescriptor originalParam : original.getValueParameters()) {
      JetType originalType = originalParam.getType();
      JetType newTypeUnsubstituted =
          isSamType(originalType) ? getFunctionTypeForSamType(originalType) : originalType;
      JetType newType =
          typeParameters.substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE);
      assert newType != null
          : "couldn't substitute type: "
              + newTypeUnsubstituted
              + ", substitutor = "
              + typeParameters.substitutor;

      ValueParameterDescriptor newParam =
          new ValueParameterDescriptorImpl(
              result,
              originalParam.getIndex(),
              originalParam.getAnnotations(),
              originalParam.getName(),
              newType,
              false,
              null);
      valueParameters.add(newParam);
    }

    result.initialize(
        null,
        original.getExpectedThisObject(),
        typeParameters.descriptors,
        valueParameters,
        returnType,
        original.getModality(),
        original.getVisibility(),
        false);

    return result;
  }
Exemplo n.º 3
0
  private void resolveFunctionBodies() {
    for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry :
        this.context.getFunctions().entrySet()) {
      JetNamedFunction declaration = entry.getKey();
      SimpleFunctionDescriptor descriptor = entry.getValue();

      computeDeferredType(descriptor.getReturnType());

      JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
      assert declaringScope != null;

      resolveFunctionBody(trace, declaration, descriptor, declaringScope);

      assert descriptor.getReturnType() != null;
    }
  }
 public static boolean isSamAdapterNecessary(@NotNull SimpleFunctionDescriptor fun) {
   for (ValueParameterDescriptor param : fun.getValueParameters()) {
     if (isSamType(param.getType())) {
       return true;
     }
   }
   return false;
 }