private void renderModalityForCallable( @NotNull CallableMemberDescriptor callable, @NotNull StringBuilder builder) { if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.getModality() != Modality.FINAL) { if (overridesSomething(callable) && overrideRenderingPolicy == OverrideRenderingPolicy.RENDER_OVERRIDE && callable.getModality() == Modality.OPEN) { return; } renderModality(callable.getModality(), builder); } }
private static boolean isSamInterface(@NotNull ClassDescriptor klass) { if (klass.getKind() != ClassKind.TRAIT) { return false; } List<CallableMemberDescriptor> abstractMembers = getAbstractMembers(klass.getDefaultType()); if (abstractMembers.size() == 1) { CallableMemberDescriptor member = abstractMembers.get(0); if (member instanceof SimpleFunctionDescriptor) { return member.getTypeParameters().isEmpty(); } } return false; }
@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; }
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("*/ "); } } } }
private void renderWhereSuffix( @NotNull CallableMemberDescriptor callable, @NotNull StringBuilder builder) { boolean first = true; for (TypeParameterDescriptor typeParameter : callable.getTypeParameters()) { if (typeParameter.getUpperBounds().size() > 1) { for (JetType upperBound : typeParameter.getUpperBounds()) { if (first) { builder.append(" "); builder.append(renderKeyword("where")); builder.append(" "); } else { builder.append(", "); } builder.append(typeParameter.getName()); builder.append(" : "); builder.append(escape(renderType(upperBound))); first = false; } } } }
private void renderMemberKind(CallableMemberDescriptor callableMember, StringBuilder builder) { if (!modifiers.contains(Modifier.MEMBER_KIND)) return; if (verbose && callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) { builder.append("/*").append(callableMember.getKind().name().toLowerCase()).append("*/ "); } }
private boolean overridesSomething(CallableMemberDescriptor callable) { return !callable.getOverriddenDescriptors().isEmpty(); }
public static boolean isOverride(@NotNull CallableMemberDescriptor descriptor) { return !descriptor.getOverriddenDescriptors().isEmpty(); }