示例#1
0
 private void renderOverride(
     @NotNull CallableMemberDescriptor callableMember, @NotNull StringBuilder builder) {
   if (!modifiers.contains(Modifier.OVERRIDE)) return;
   if (overridesSomething(callableMember)) {
     if (overrideRenderingPolicy != OverrideRenderingPolicy.RENDER_OPEN) {
       builder.append("override ");
       if (verbose) {
         builder
             .append("/*")
             .append(callableMember.getOverriddenDescriptors().size())
             .append("*/ ");
       }
     }
   }
 }
 @Override
 protected Set<CallableMemberDescriptor> collectMethodsToGenerate(
     MutableClassDescriptor descriptor) {
   final Set<CallableMemberDescriptor> superMethods =
       OverrideResolver.collectSuperMethods(descriptor).keySet();
   for (CallableMemberDescriptor member : descriptor.getDeclaredCallableMembers()) {
     superMethods.removeAll(member.getOverriddenDescriptors());
   }
   Set<CallableMemberDescriptor> result = new HashSet<CallableMemberDescriptor>();
   for (CallableMemberDescriptor superMethod : superMethods) {
     if (superMethod.getModality().isOverridable()) {
       result.add(superMethod);
     }
   }
   return result;
 }
 @NotNull
 public static LookupElement createLookupElement(
     @NotNull KotlinCodeAnalyzer analyzer,
     @NotNull BindingContext bindingContext,
     @NotNull DeclarationDescriptor descriptor) {
   if (descriptor instanceof CallableMemberDescriptor) {
     CallableMemberDescriptor callableMemberDescriptor = (CallableMemberDescriptor) descriptor;
     while (callableMemberDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
       // TODO: need to know all of them
       callableMemberDescriptor =
           callableMemberDescriptor.getOverriddenDescriptors().iterator().next();
     }
     descriptor = callableMemberDescriptor;
   }
   return createLookupElement(
       analyzer,
       descriptor,
       BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor));
 }
  private JetKeywordToken findVisibilityChangeTo(JetFile file) {
    BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(file);
    DeclarationDescriptor descriptor;
    if (element instanceof JetParameter) {
      descriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, element);
    } else {
      descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
    }
    if (!(descriptor instanceof CallableMemberDescriptor)) return null;

    CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor;
    Visibility maxVisibility = null;
    for (CallableMemberDescriptor overriddenDescriptor :
        memberDescriptor.getOverriddenDescriptors()) {
      Visibility overriddenDescriptorVisibility = overriddenDescriptor.getVisibility();
      if (maxVisibility == null) {
        maxVisibility = overriddenDescriptorVisibility;
        continue;
      }
      Integer compare = Visibilities.compare(maxVisibility, overriddenDescriptorVisibility);
      if (compare == null) {
        maxVisibility = Visibilities.PUBLIC;
      } else if (compare < 0) {
        maxVisibility = overriddenDescriptorVisibility;
      }
    }
    if (maxVisibility == memberDescriptor.getVisibility()) {
      return null;
    }
    JetKeywordToken modifier = null;
    if (maxVisibility == Visibilities.PUBLIC) {
      modifier = JetTokens.PUBLIC_KEYWORD;
    } else if (maxVisibility == Visibilities.PROTECTED) {
      modifier = JetTokens.PROTECTED_KEYWORD;
    } else if (maxVisibility == Visibilities.INTERNAL) {
      modifier = JetTokens.INTERNAL_KEYWORD;
    }
    return modifier;
  }
示例#5
0
 private boolean overridesSomething(CallableMemberDescriptor callable) {
   return !callable.getOverriddenDescriptors().isEmpty();
 }
示例#6
0
 public static boolean isOverride(@NotNull CallableMemberDescriptor descriptor) {
   return !descriptor.getOverriddenDescriptors().isEmpty();
 }