Ejemplo n.º 1
0
  @NotNull
  public static <D extends CallableDescriptor, F extends D>
      List<ResolutionTask<D, F>> computePrioritizedTasks(
          @NotNull BasicResolutionContext context,
          @NotNull Name name,
          @NotNull JetReferenceExpression functionReference,
          @NotNull List<CallableDescriptorCollector<? extends D>> callableDescriptorCollectors) {
    ReceiverDescriptor explicitReceiver = context.call.getExplicitReceiver();
    final JetScope scope;
    if (explicitReceiver.exists() && explicitReceiver.getType() instanceof NamespaceType) {
      // Receiver is a namespace
      scope = explicitReceiver.getType().getMemberScope();
      explicitReceiver = NO_RECEIVER;
    } else {
      scope = context.scope;
    }
    final Predicate<ResolutionCandidate<D>> visibleStrategy =
        new Predicate<ResolutionCandidate<D>>() {
          @Override
          public boolean apply(@Nullable ResolutionCandidate<D> call) {
            if (call == null) return false;
            D candidateDescriptor = call.getDescriptor();
            if (ErrorUtils.isError(candidateDescriptor)) return true;
            return Visibilities.isVisible(candidateDescriptor, scope.getContainingDeclaration());
          }
        };

    ResolutionTaskHolder<D, F> result =
        new ResolutionTaskHolder<D, F>(functionReference, context, visibleStrategy);
    for (CallableDescriptorCollector<? extends D> callableDescriptorCollector :
        callableDescriptorCollectors) {
      doComputeTasks(scope, explicitReceiver, name, result, context, callableDescriptorCollector);
    }
    return result.getTasks();
  }
Ejemplo n.º 2
0
  private static <D extends CallableDescriptor, F extends D> void doComputeTasks(
      @NotNull JetScope scope,
      @NotNull ReceiverDescriptor receiver,
      @NotNull Name name,
      @NotNull ResolutionTaskHolder<D, F> result,
      @NotNull BasicResolutionContext context,
      @NotNull CallableDescriptorCollector<? extends D> callableDescriptorCollector) {

    ProgressIndicatorProvider.checkCanceled();

    AutoCastServiceImpl autoCastService =
        new AutoCastServiceImpl(context.dataFlowInfo, context.trace.getBindingContext());
    List<ReceiverDescriptor> implicitReceivers = Lists.newArrayList();
    scope.getImplicitReceiversHierarchy(implicitReceivers);
    boolean hasExplicitThisObject = context.call.getThisObject().exists();
    if (hasExplicitThisObject) {
      implicitReceivers.add(context.call.getThisObject());
    }
    if (receiver.exists()) {
      List<ReceiverDescriptor> variantsForExplicitReceiver =
          autoCastService.getVariantsForReceiver(receiver);

      Collection<ResolutionCandidate<D>> extensionFunctions =
          convertWithImpliedThis(
              scope,
              variantsForExplicitReceiver,
              callableDescriptorCollector.getNonMembersByName(scope, name));
      List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
      List<ResolutionCandidate<D>> locals = Lists.newArrayList();
      //noinspection unchecked,RedundantTypeArguments
      TaskPrioritizer.<D>splitLexicallyLocalDescriptors(
          extensionFunctions, scope.getContainingDeclaration(), locals, nonlocals);

      Collection<ResolutionCandidate<D>> members = Lists.newArrayList();
      for (ReceiverDescriptor variant : variantsForExplicitReceiver) {
        Collection<? extends D> membersForThisVariant =
            callableDescriptorCollector.getMembersByName(variant.getType(), name);
        convertWithReceivers(
            membersForThisVariant,
            Collections.singletonList(variant),
            Collections.singletonList(NO_RECEIVER),
            members,
            hasExplicitThisObject);
      }

      result.addLocalExtensions(locals);
      result.addMembers(members);

      for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
        Collection<? extends D> memberExtensions =
            callableDescriptorCollector.getNonMembersByName(
                implicitReceiver.getType().getMemberScope(), name);
        List<ReceiverDescriptor> variantsForImplicitReceiver =
            autoCastService.getVariantsForReceiver(implicitReceiver);
        result.addNonLocalExtensions(
            convertWithReceivers(
                memberExtensions,
                variantsForImplicitReceiver,
                variantsForExplicitReceiver,
                hasExplicitThisObject));
      }

      result.addNonLocalExtensions(nonlocals);
    } else {
      Collection<ResolutionCandidate<D>> functions =
          convertWithImpliedThis(
              scope,
              Collections.singletonList(receiver),
              callableDescriptorCollector.getNonExtensionsByName(scope, name));

      List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
      List<ResolutionCandidate<D>> locals = Lists.newArrayList();
      //noinspection unchecked,RedundantTypeArguments
      TaskPrioritizer.<D>splitLexicallyLocalDescriptors(
          functions, scope.getContainingDeclaration(), locals, nonlocals);

      result.addLocalExtensions(locals);
      result.addNonLocalExtensions(nonlocals);

      for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
        doComputeTasks(scope, implicitReceiver, name, result, context, callableDescriptorCollector);
      }
    }
  }