private void addToClasspath(File path) throws CoreException {
   if (path.isFile()) {
     VirtualFile jarFile = applicationEnvironment.getJarFileSystem().findFileByPath(path + "!/");
     if (jarFile == null) {
       throw new CoreException(
           new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't find jar: " + path));
     }
     projectEnvironment.addJarToClassPath(path);
     classPath.add(jarFile);
   } else {
     VirtualFile root =
         applicationEnvironment.getLocalFileSystem().findFileByPath(path.getAbsolutePath());
     if (root == null) {
       throw new CoreException(
           new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't find jar: " + path));
     }
     projectEnvironment.addSourcesToClasspath(root);
     classPath.add(root);
   }
 }
  private KotlinEnvironment(@NotNull IJavaProject javaProject) {
    this.javaProject = javaProject;

    applicationEnvironment = createJavaCoreApplicationEnvironment();

    projectEnvironment = new JavaCoreProjectEnvironment(DISPOSABLE, applicationEnvironment);

    project = projectEnvironment.getProject();

    CoreExternalAnnotationsManager annotationsManager =
        new CoreExternalAnnotationsManager(project.getComponent(PsiManager.class));
    project.registerService(ExternalAnnotationsManager.class, annotationsManager);
    project.registerService(
        CoreJavaFileManager.class,
        (CoreJavaFileManager) ServiceManager.getService(project, JavaFileManager.class));

    CliLightClassGenerationSupport cliLightClassGenerationSupport =
        new CliLightClassGenerationSupport();
    project.registerService(LightClassGenerationSupport.class, cliLightClassGenerationSupport);
    project.registerService(CliLightClassGenerationSupport.class, cliLightClassGenerationSupport);
    project.registerService(
        KotlinLightClassForPackage.FileStubCache.class,
        new KotlinLightClassForPackage.FileStubCache(project));

    VirtualFile ktJDKAnnotations =
        PathUtil.jarFileOrDirectoryToVirtualFile(new File(KT_JDK_ANNOTATIONS_PATH));
    annotationsManager.addExternalAnnotationsRoot(ktJDKAnnotations);

    addJreClasspath();
    addSourcesToClasspath();
    addLibsToClasspath();

    project.registerService(
        VirtualFileFinderFactory.class, new EclipseVirtualFileFinder(classPath));

    CoreApplicationEnvironment.registerExtensionPoint(
        Extensions.getRootArea(),
        ClsCustomNavigationPolicy.EP_NAME,
        ClsCustomNavigationPolicy.class);
    CoreApplicationEnvironment.registerExtensionPoint(
        Extensions.getRootArea(),
        ClassFileDecompilers.EP_NAME,
        ClassFileDecompilers.Decompiler.class);

    cachedEnvironment.put(javaProject, this);
  }