Пример #1
0
 public InlineChecker(@NotNull FunctionDescriptor descriptor) {
   assert InlineUtil.isInline(descriptor)
       : "This extension should be created only for inline functions: " + descriptor;
   this.descriptor = descriptor;
   this.isEffectivelyPublicApiFunction = DescriptorUtilsKt.isEffectivelyPublicApi(descriptor);
   this.isEffectivelyPrivateApiFunction = DescriptorUtilsKt.isEffectivelyPrivateApi(descriptor);
   for (ValueParameterDescriptor param : descriptor.getValueParameters()) {
     if (isInlinableParameter(param)) {
       inlinableParameters.add(param);
     }
   }
 }
 public DataClassMethodGenerator(JetClassOrObject declaration, BindingContext bindingContext) {
   this.declaration = declaration;
   this.bindingContext = bindingContext;
   this.classDescriptor =
       BindingContextUtils.getNotNull(bindingContext, BindingContext.CLASS, declaration);
   this.builtIns = DescriptorUtilsKt.getBuiltIns(classDescriptor);
 }
Пример #3
0
 @NotNull
 private static PsiClass findClass(
     String qualifiedName, Project project, KotlinCoreEnvironment environment) {
   ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project, environment);
   ClassDescriptor classDescriptor =
       DescriptorUtilsKt.resolveTopLevelClass(
           module, new FqName(qualifiedName), NoLookupLocation.FROM_TEST);
   assertNotNull("Class descriptor wasn't resolved: " + qualifiedName, classDescriptor);
   PsiClass psiClass = (PsiClass) DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor);
   assertNotNull("Class declaration wasn't found: " + classDescriptor, psiClass);
   return psiClass;
 }
Пример #4
0
 private void checkPrivateClassMemberAccess(
     @NotNull DeclarationDescriptor declarationDescriptor,
     @NotNull KtElement expression,
     @NotNull CallCheckerContext context) {
   if (!isEffectivelyPrivateApiFunction) {
     if (DescriptorUtilsKt.isInsidePrivateClass(declarationDescriptor)) {
       context
           .getTrace()
           .report(
               Errors.PRIVATE_CLASS_MEMBER_FROM_INLINE.on(
                   expression, declarationDescriptor, descriptor));
     }
   }
 }
Пример #5
0
  @NotNull
  public Collection<KotlinType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
    ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();

    //noinspection ConstantConditions
    KotlinType functionType =
        DescriptorUtilsKt.getBuiltIns(descriptor)
            .getFunctionType(
                Annotations.Companion.getEMPTY(),
                receiverParameter == null ? null : receiverParameter.getType(),
                ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
                descriptor.getReturnType());

    return Arrays.asList(lambda.getDefaultType(), functionType);
  }
Пример #6
0
 private void checkVisibilityAndAccess(
     @NotNull CallableDescriptor declarationDescriptor,
     @NotNull KtElement expression,
     @NotNull CallCheckerContext context) {
   boolean declarationDescriptorIsPublicApi =
       DescriptorUtilsKt.isEffectivelyPublicApi(declarationDescriptor)
           || isDefinedInInlineFunction(declarationDescriptor);
   if (isEffectivelyPublicApiFunction
       && !declarationDescriptorIsPublicApi
       && declarationDescriptor.getVisibility() != Visibilities.LOCAL) {
     context
         .getTrace()
         .report(
             Errors.NON_PUBLIC_CALL_FROM_PUBLIC_INLINE.on(
                 expression, declarationDescriptor, descriptor));
   } else {
     checkPrivateClassMemberAccess(declarationDescriptor, expression, context);
   }
 }
  @NotNull
  private static KotlinType getFunctionExpectedReturnType(
      @NotNull FunctionDescriptor descriptor,
      @NotNull KtElement function,
      @NotNull ExpressionTypingContext context) {
    KotlinType expectedType;
    if (function instanceof KtSecondaryConstructor) {
      expectedType = DescriptorUtilsKt.getBuiltIns(descriptor).getUnitType();
    } else if (function instanceof KtFunction) {
      KtFunction ktFunction = (KtFunction) function;
      expectedType = context.trace.get(EXPECTED_RETURN_TYPE, ktFunction);

      if ((expectedType == null)
          && (ktFunction.getTypeReference() != null || ktFunction.hasBlockBody())) {
        expectedType = descriptor.getReturnType();
      }
    } else {
      expectedType = descriptor.getReturnType();
    }
    return expectedType != null ? expectedType : TypeUtils.NO_EXPECTED_TYPE;
  }
Пример #8
0
  @NotNull
  public Collection<KotlinType> getSupertypesForFunctionReference(
      @NotNull FunctionDescriptor descriptor) {
    ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
    ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();

    KotlinType receiverType =
        extensionReceiver != null
            ? extensionReceiver.getType()
            : dispatchReceiver != null ? dispatchReceiver.getType() : null;

    //noinspection ConstantConditions
    KotlinType functionType =
        DescriptorUtilsKt.getBuiltIns(descriptor)
            .getFunctionType(
                Annotations.Companion.getEMPTY(),
                receiverType,
                ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
                descriptor.getReturnType());

    return Arrays.asList(functionReference.getDefaultType(), functionType);
  }