// 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; }
@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); }
@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; }
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); }