Example #1
0
 // TODO: move mapping logic to front-end java
 public static int getVisibilityAccessFlag(@NotNull MemberDescriptor descriptor) {
   Integer specialCase = specialCaseVisibility(descriptor);
   if (specialCase != null) {
     return specialCase;
   }
   Integer defaultMapping = visibilityToAccessFlag.get(descriptor.getVisibility());
   if (defaultMapping == null) {
     throw new IllegalStateException(
         descriptor.getVisibility() + " is not a valid visibility in backend.");
   }
   return defaultMapping;
 }
Example #2
0
 @Nullable
 private static Integer specialCaseVisibility(@NotNull MemberDescriptor memberDescriptor) {
   DeclarationDescriptor containingDeclaration = memberDescriptor.getContainingDeclaration();
   if (isInterface(containingDeclaration)) {
     return ACC_PUBLIC;
   }
   Visibility memberVisibility = memberDescriptor.getVisibility();
   if (memberVisibility == Visibilities.LOCAL
       && memberDescriptor instanceof CallableMemberDescriptor) {
     return ACC_PUBLIC;
   }
   if (memberVisibility != Visibilities.PRIVATE) {
     return null;
   }
   // the following code is only for PRIVATE visibility of member
   if (isClassObject(containingDeclaration)) {
     return NO_FLAG_PACKAGE_PRIVATE;
   }
   if (memberDescriptor instanceof ConstructorDescriptor) {
     ClassKind kind = ((ClassDescriptor) containingDeclaration).getKind();
     if (kind == ClassKind.OBJECT) {
       // TODO: should be NO_FLAG_PACKAGE_PRIVATE
       // see http://youtrack.jetbrains.com/issue/KT-2700
       return ACC_PUBLIC;
     } else if (kind == ClassKind.ENUM_ENTRY) {
       return NO_FLAG_PACKAGE_PRIVATE;
     } else if (kind == ClassKind.ENUM_CLASS) {
       // TODO: should be ACC_PRIVATE
       // see http://youtrack.jetbrains.com/issue/KT-2680
       return ACC_PROTECTED;
     }
   }
   if (containingDeclaration instanceof NamespaceDescriptor) {
     return ACC_PUBLIC;
   }
   return null;
 }