Exemple #1
0
  private KotlinBuiltIns() {
    builtInsModule =
        new ModuleDescriptorImpl(
            Name.special("<built-ins lazy module>"),
            Collections.<ImportPath>emptyList(),
            PlatformToKotlinClassMap.EMPTY);
    builtinsPackageFragment =
        new BuiltinsPackageFragment(
            BUILT_INS_PACKAGE_FQ_NAME,
            new LockBasedStorageManager(),
            builtInsModule,
            new Function1<String, InputStream>() {
              @Override
              public InputStream invoke(String path) {
                return KotlinBuiltIns.class.getClassLoader().getResourceAsStream(path);
              }
            });
    builtInsModule.initialize(builtinsPackageFragment.getProvider());
    builtInsModule.addDependencyOnModule(builtInsModule);
    builtInsModule.seal();

    primitiveTypeToNullableJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
    primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
    primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
    jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>();
  }
  @NotNull
  private static FunctionDescriptor standardFunction(
      ClassDescriptor classDescriptor, String name, Project project, KotlinType... parameterTypes) {
    ModuleDescriptorImpl emptyModule = KotlinTestUtils.createEmptyModule();
    ContainerForTests container = InjectionKt.createContainerForTests(project, emptyModule);
    emptyModule.setDependencies(emptyModule);
    emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE);

    LexicalScopeImpl lexicalScope =
        new LexicalScopeImpl(
            ImportingScope.Empty.INSTANCE,
            classDescriptor,
            false,
            classDescriptor.getThisAsReceiverParameter(),
            LexicalScopeKind.SYNTHETIC);

    ExpressionTypingContext context =
        ExpressionTypingContext.newContext(
            new BindingTraceContext(),
            lexicalScope,
            DataFlowInfoFactory.EMPTY,
            TypeUtils.NO_EXPECTED_TYPE);

    OverloadResolutionResults<FunctionDescriptor> functions =
        container
            .getFakeCallResolver()
            .resolveFakeCall(
                context,
                null,
                Name.identifier(name),
                null,
                null,
                FakeCallKind.OTHER,
                parameterTypes);

    for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
      List<ValueParameterDescriptor> unsubstitutedValueParameters =
          resolvedCall.getResultingDescriptor().getValueParameters();
      for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size();
          i < unsubstitutedValueParametersSize;
          i++) {
        ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
        if (unsubstitutedValueParameter.getType().equals(parameterTypes[i])) {
          return resolvedCall.getResultingDescriptor();
        }
      }
    }
    throw new IllegalArgumentException(
        "Not found: kotlin::"
            + classDescriptor.getName()
            + "."
            + name
            + "("
            + Arrays.toString(parameterTypes)
            + ")");
  }
  protected KotlinBuiltIns() {
    LockBasedStorageManager storageManager = new LockBasedStorageManager();
    builtInsModule =
        new ModuleDescriptorImpl(
            Name.special("<built-ins module>"),
            storageManager,
            ModuleParameters.Empty.INSTANCE,
            this);

    PackageFragmentProvider packageFragmentProvider =
        BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(
            storageManager,
            builtInsModule,
            BUILT_INS_PACKAGE_FQ_NAMES,
            new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule),
            getAdditionalSupertypesProvider(),
            new Function1<String, InputStream>() {
              @Override
              public InputStream invoke(String path) {
                return KotlinBuiltIns.class.getClassLoader().getResourceAsStream(path);
              }
            });

    builtInsModule.initialize(packageFragmentProvider);
    builtInsModule.setDependencies(builtInsModule);

    builtinsPackageFragment =
        (BuiltinsPackageFragment)
            single(packageFragmentProvider.getPackageFragments(BUILT_INS_PACKAGE_FQ_NAME));
    annotationPackageFragment =
        (BuiltinsPackageFragment)
            single(packageFragmentProvider.getPackageFragments(ANNOTATION_PACKAGE_FQ_NAME));

    primitiveTypeToArrayKotlinType = new EnumMap<PrimitiveType, KotlinType>(PrimitiveType.class);
    primitiveKotlinTypeToKotlinArrayType = new HashMap<KotlinType, KotlinType>();
    kotlinArrayTypeToPrimitiveKotlinType = new HashMap<KotlinType, KotlinType>();
    for (PrimitiveType primitive : PrimitiveType.values()) {
      makePrimitive(primitive);
    }
  }