Exemplo n.º 1
0
 @NotNull
 @KotlinSignature(
     "fun getTopmostOverridenDescriptors(originalDescriptor: CallableDescriptor): List<out CallableDescriptor>")
 public static List<? extends CallableDescriptor> getTopmostOverridenDescriptors(
     @NotNull CallableDescriptor originalDescriptor) {
   return DFS.dfs(
       Collections.singletonList(originalDescriptor),
       new DFS.Neighbors<CallableDescriptor>() {
         @NotNull
         @Override
         public Iterable<? extends CallableDescriptor> getNeighbors(CallableDescriptor current) {
           return current.getOverriddenDescriptors();
         }
       },
       new DFS.CollectingNodeHandler<
           CallableDescriptor, CallableDescriptor, ArrayList<CallableDescriptor>>(
           new ArrayList<CallableDescriptor>()) {
         @Override
         public void afterChildren(CallableDescriptor current) {
           if (current.getOverriddenDescriptors().isEmpty()) {
             result.add(current);
           }
         }
       });
 }
Exemplo n.º 2
0
  public static boolean traverseOverridenDescriptors(
      @NotNull CallableDescriptor originalDescriptor,
      @NotNull final Function1<CallableDescriptor, Boolean> handler) {
    return DFS.dfs(
        Collections.singletonList(originalDescriptor),
        new DFS.Neighbors<CallableDescriptor>() {
          @NotNull
          @Override
          public Iterable<? extends CallableDescriptor> getNeighbors(CallableDescriptor current) {
            return current.getOverriddenDescriptors();
          }
        },
        new DFS.AbstractNodeHandler<CallableDescriptor, Boolean>() {
          private boolean result = true;

          @Override
          public boolean beforeChildren(CallableDescriptor current) {
            if (!handler.invoke(current)) {
              result = false;
            }
            return result;
          }

          @Override
          public Boolean result() {
            return result;
          }
        });
  }
Exemplo n.º 3
0
  private static void createAndBindFakeOverrides(
      @NotNull ClassDescriptor current,
      @NotNull Collection<CallableMemberDescriptor> notOverridden,
      @NotNull OverridingStrategy strategy) {
    // Optimization: If all notOverridden descriptors have the same containing declaration,
    // then we can just create fake overrides for them, because they should be matched correctly in
    // their containing declaration
    if (allHasSameContainingDeclaration(notOverridden)) {
      for (CallableMemberDescriptor descriptor : notOverridden) {
        createAndBindFakeOverride(Collections.singleton(descriptor), current, strategy);
      }
      return;
    }

    Queue<CallableMemberDescriptor> fromSuperQueue =
        new LinkedList<CallableMemberDescriptor>(notOverridden);
    while (!fromSuperQueue.isEmpty()) {
      CallableMemberDescriptor notOverriddenFromSuper =
          VisibilityUtilKt.findMemberWithMaxVisibility(fromSuperQueue);
      Collection<CallableMemberDescriptor> overridables =
          extractMembersOverridableInBothWays(notOverriddenFromSuper, fromSuperQueue, strategy);
      createAndBindFakeOverride(overridables, current, strategy);
    }
  }