示例#1
0
 public static <D extends CallableDescriptor>
     Collection<ResolutionCandidate<D>> convertWithImpliedThis(
         JetScope scope,
         Collection<ReceiverDescriptor> receiverParameters,
         Collection<? extends D> descriptors) {
   Collection<ResolutionCandidate<D>> result = Lists.newArrayList();
   for (ReceiverDescriptor receiverParameter : receiverParameters) {
     for (D descriptor : descriptors) {
       ResolutionCandidate<D> candidate = ResolutionCandidate.create(descriptor);
       candidate.setReceiverArgument(receiverParameter);
       candidate.setExplicitReceiverKind(
           receiverParameter.exists()
               ? ExplicitReceiverKind.RECEIVER_ARGUMENT
               : ExplicitReceiverKind.NO_EXPLICIT_RECEIVER);
       if (setImpliedThis(scope, candidate)) {
         result.add(candidate);
       }
     }
   }
   if (receiverParameters.size() == 1 && !receiverParameters.iterator().next().exists()) {
     for (D descriptor : descriptors) {
       if (descriptor.getExpectedThisObject().exists()
           && !descriptor.getReceiverParameter().exists()) {
         DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
         if (descriptor instanceof ConstructorDescriptor) {
           assert containingDeclaration != null;
           containingDeclaration = containingDeclaration.getContainingDeclaration();
         }
         if (containingDeclaration != null && isClassObject(containingDeclaration)) {
           ResolutionCandidate<D> candidate = ResolutionCandidate.create(descriptor);
           candidate.setThisObject(new ClassReceiver((ClassDescriptor) containingDeclaration));
           candidate.setExplicitReceiverKind(ExplicitReceiverKind.NO_EXPLICIT_RECEIVER);
           result.add(candidate);
         }
       }
     }
   }
   return result;
 }
示例#2
0
  @Nullable
  private <D extends DeclarationDescriptor> D substitute(@Nullable D descriptor) {
    if (descriptor == null) return null;
    if (substitutor.isEmpty()) return descriptor;

    if (substitutedDescriptors == null) {
      substitutedDescriptors = Maps.newHashMap();
    }

    DeclarationDescriptor substituted = substitutedDescriptors.get(descriptor);
    if (substituted == null && !substitutedDescriptors.containsKey(descriptor)) {
      substituted = descriptor.substitute(substitutor);

      //noinspection ConstantConditions
      substitutedDescriptors.put(descriptor, substituted);
    }

    //noinspection unchecked
    return (D) substituted;
  }
 public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
   return (D) candidate.substitute(MAKE_TYPE_PARAMETERS_FRESH);
 }