Esempio n. 1
0
 @Override
 public boolean isVisible(
     @NotNull ReceiverValue receiver,
     @NotNull DeclarationDescriptorWithVisibility what,
     @NotNull DeclarationDescriptor from) {
   DeclarationDescriptor parent = what;
   while (parent != null) {
     parent = parent.getContainingDeclaration();
     if ((parent instanceof ClassDescriptor && !DescriptorUtils.isCompanionObject(parent))
         || parent instanceof PackageFragmentDescriptor) {
       break;
     }
   }
   if (parent == null) {
     return false;
   }
   DeclarationDescriptor fromParent = from;
   while (fromParent != null) {
     if (parent == fromParent) {
       return true;
     }
     if (fromParent instanceof PackageFragmentDescriptor) {
       return parent instanceof PackageFragmentDescriptor
           && ((PackageFragmentDescriptor) parent)
               .getFqName()
               .equals(((PackageFragmentDescriptor) fromParent).getFqName())
           && DescriptorUtils.areInSameModule(fromParent, parent);
     }
     fromParent = fromParent.getContainingDeclaration();
   }
   return false;
 }
Esempio n. 2
0
 @Nullable
 private LazyClassDescriptor computeCompanionObjectDescriptor(
     @Nullable KtObjectDeclaration companionObject) {
   KtClassLikeInfo companionObjectInfo = getCompanionObjectInfo(companionObject);
   if (!(companionObjectInfo instanceof KtClassOrObjectInfo)) {
     return null;
   }
   Name name = ((KtClassOrObjectInfo) companionObjectInfo).getName();
   assert name != null;
   getUnsubstitutedMemberScope()
       .getContributedClassifier(name, NoLookupLocation.WHEN_GET_COMPANION_OBJECT);
   ClassDescriptor companionObjectDescriptor =
       c.getTrace().get(BindingContext.CLASS, companionObject);
   if (companionObjectDescriptor instanceof LazyClassDescriptor) {
     assert DescriptorUtils.isCompanionObject(companionObjectDescriptor)
         : "Not a companion object: " + companionObjectDescriptor;
     return (LazyClassDescriptor) companionObjectDescriptor;
   } else {
     return null;
   }
 }
Esempio n. 3
0
        @Override
        public boolean isVisible(
            @NotNull ReceiverValue receiver,
            @NotNull DeclarationDescriptorWithVisibility what,
            @NotNull DeclarationDescriptor from) {
          ClassDescriptor classDescriptor =
              DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
          if (DescriptorUtils.isCompanionObject(classDescriptor)) {
            classDescriptor =
                DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
          }
          if (classDescriptor == null) return false;

          ClassDescriptor fromClass =
              DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
          if (fromClass == null) return false;
          if (DescriptorUtils.isSubclass(fromClass, classDescriptor)) {
            return true;
          }
          return isVisible(receiver, what, fromClass.getContainingDeclaration());
        }