示例#1
0
  @NotNull
  public Collection<JetType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
    ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();

    List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);

    ClassDescriptor classDescriptor;
    if (receiverParameter != null) {
      classDescriptor = extensionFunctionImpl;
      typeArguments.add(new TypeProjectionImpl(receiverParameter.getType()));
    } else {
      classDescriptor = functionImpl;
    }

    //noinspection ConstantConditions
    typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));

    JetType functionImplType =
        new JetTypeImpl(
            classDescriptor.getDefaultType().getAnnotations(),
            classDescriptor.getTypeConstructor(),
            false,
            typeArguments,
            classDescriptor.getMemberScope(typeArguments));

    JetType functionType =
        KotlinBuiltIns.getInstance()
            .getFunctionType(
                Annotations.EMPTY,
                receiverParameter == null ? null : receiverParameter.getType(),
                DescriptorUtils.getValueParametersTypes(descriptor.getValueParameters()),
                descriptor.getReturnType());

    return Arrays.asList(functionImplType, functionType);
  }
示例#2
0
  @NotNull
  public Collection<JetType> getSupertypesForCallableReference(
      @NotNull FunctionDescriptor descriptor) {
    ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
    ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();

    List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);

    ClassDescriptor classDescriptor;
    JetType receiverType;
    if (receiverParameter != null) {
      classDescriptor = kExtensionFunctionImpl;
      receiverType = receiverParameter.getType();
      typeArguments.add(new TypeProjectionImpl(receiverType));
    } else if (expectedThisObject != null) {
      classDescriptor = kMemberFunctionImpl;
      receiverType = expectedThisObject.getType();
      typeArguments.add(new TypeProjectionImpl(receiverType));
    } else {
      classDescriptor = kFunctionImpl;
      receiverType = null;
    }

    //noinspection ConstantConditions
    typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));

    JetType kFunctionImplType =
        new JetTypeImpl(
            classDescriptor.getDefaultType().getAnnotations(),
            classDescriptor.getTypeConstructor(),
            false,
            typeArguments,
            classDescriptor.getMemberScope(typeArguments));

    JetType kFunctionType =
        reflectionTypes.getKFunctionType(
            Annotations.EMPTY,
            receiverType,
            DescriptorUtils.getValueParametersTypes(descriptor.getValueParameters()),
            descriptor.getReturnType(),
            receiverParameter != null);

    return Arrays.asList(kFunctionImplType, kFunctionType);
  }
  private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
      NamespaceDescriptor packageDescriptor, FqName path, boolean includeObjectDeclarations) {
    if (path.isRoot()) {
      return Collections.emptyList();
    }

    Collection<JetScope> scopes = Arrays.asList(packageDescriptor.getMemberScope());

    List<Name> names = path.pathSegments();
    if (names.size() > 1) {
      for (Name subName : path.pathSegments().subList(0, names.size() - 1)) {
        Collection<JetScope> tempScopes = Lists.newArrayList();
        for (JetScope scope : scopes) {
          ClassifierDescriptor classifier = scope.getClassifier(subName);
          if (classifier instanceof ClassDescriptorBase) {
            ClassDescriptorBase classDescriptor = (ClassDescriptorBase) classifier;
            tempScopes.add(classDescriptor.getUnsubstitutedInnerClassesScope());
          }
        }
        scopes = tempScopes;
      }
    }

    Name shortName = path.shortName();
    Collection<ClassDescriptor> resultClassifierDescriptors = Lists.newArrayList();
    for (JetScope scope : scopes) {
      ClassifierDescriptor classifier = scope.getClassifier(shortName);
      if (classifier instanceof ClassDescriptor) {
        resultClassifierDescriptors.add((ClassDescriptor) classifier);
      }
      if (includeObjectDeclarations) {
        ClassDescriptor objectDescriptor = scope.getObjectDescriptor(shortName);
        if (objectDescriptor != null) {
          resultClassifierDescriptors.add(objectDescriptor);
        }
      }
    }

    return resultClassifierDescriptors;
  }
示例#4
0
 @Override
 public void getAllClassNames(@NotNull HashSet<String> destination) {
   destination.addAll(Arrays.asList(getAllClassNames()));
 }