Example #1
0
 // TODO: maybe we have similar routine
 @Nullable
 public static ClassDescriptor getContainingClass(@NotNull DeclarationDescriptor descriptor) {
   DeclarationDescriptor containing = descriptor.getContainingDeclaration();
   while (containing != null) {
     if (containing instanceof ClassDescriptor && !isClassObject(containing)) {
       return (ClassDescriptor) containing;
     }
     containing = containing.getContainingDeclaration();
   }
   return null;
 }
Example #2
0
  @NotNull
  private static DeclarationDescriptor getDeclarationDescriptorForReceiver(
      @NotNull ReceiverValue receiverParameter) {
    if (receiverParameter instanceof ThisReceiver) {
      DeclarationDescriptor declarationDescriptor =
          ((ThisReceiver) receiverParameter).getDeclarationDescriptor();
      return declarationDescriptor.getOriginal();
    }

    throw new UnsupportedOperationException(
        "Unsupported receiver type: "
            + receiverParameter.getClass()
            + ", receiverParameter = "
            + receiverParameter);
  }
Example #3
0
 @NotNull
 public static DeclarationDescriptor getContainingDeclaration(
     @NotNull DeclarationDescriptor descriptor) {
   DeclarationDescriptor containing = descriptor.getContainingDeclaration();
   assert containing != null : "Should be called on objects that have containing declaration.";
   return containing;
 }
Example #4
0
  public static ReceiverParameterDescriptor getReceiverParameterForDeclaration(
      DeclarationDescriptor declarationDescriptor) {
    if (declarationDescriptor instanceof ClassDescriptor) {
      return ((ClassDescriptor) declarationDescriptor).getThisAsReceiverParameter();
    } else if (declarationDescriptor instanceof CallableMemberDescriptor) {
      ReceiverParameterDescriptor receiverDescriptor =
          ((CallableMemberDescriptor) declarationDescriptor).getReceiverParameter();
      assert receiverDescriptor != null;
      return receiverDescriptor;
    }

    throw new UnsupportedOperationException(
        "Unsupported declaration type: "
            + declarationDescriptor.getClass()
            + ", declarationDescriptor = "
            + declarationDescriptor);
  }