@Nullable
  protected VirtualFile findCoreJar(@Nullable Module module) {
    if (module == null) return null;

    JavaPsiFacade javaFacade = JavaPsiFacade.getInstance(module.getProject());

    for (PsiClass aClass :
        javaFacade.findClasses(
            getSomeFrameworkClass(), GlobalSearchScope.moduleWithLibrariesScope(module))) {
      VirtualFile virtualFile = aClass.getContainingFile().getVirtualFile();
      if (virtualFile != null && virtualFile.getFileSystem() instanceof JarFileSystem) {
        VirtualFile localFile = PathUtil.getLocalFile(virtualFile);
        if (isCoreJar(localFile)) {
          return localFile;
        }
      }
    }

    return null;
  }
  @NotNull
  private Set<JetFile> getBuiltInSourceFiles(@NotNull URL url) {
    String fromUrl = VfsUtilCore.convertFromUrl(url);
    VirtualFile vf = VirtualFileManager.getInstance().findFileByUrl(fromUrl);
    assert vf != null : "Virtual file not found by URL: " + url;

    // Refreshing VFS: in case the plugin jar was updated, the caches may hold the old value
    vf.getChildren();
    vf.refresh(false, true);
    PathUtil.getLocalFile(vf).refresh(false, true);

    PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(vf);
    assert psiDirectory != null : "No PsiDirectory for " + vf;
    return new HashSet<JetFile>(
        ContainerUtil.mapNotNull(
            psiDirectory.getFiles(),
            new Function<PsiFile, JetFile>() {
              @Override
              public JetFile fun(PsiFile file) {
                return file instanceof JetFile ? (JetFile) file : null;
              }
            }));
  }
Ejemplo n.º 3
0
  protected List<File> getImplicitClasspathRoots(@NotNull Module module) {
    final List<File> toExclude = new ArrayList<File>();

    VirtualFile sdkRoot = getSdkRoot(module);
    if (sdkRoot != null) toExclude.add(VfsUtil.virtualToIoFile(sdkRoot));

    ContainerUtil.addIfNotNull(getCommonPluginsDir(module), toExclude);
    final VirtualFile appRoot = findAppRoot(module);
    if (appRoot != null) {
      VirtualFile pluginDir = appRoot.findChild(MvcModuleStructureUtil.PLUGINS_DIRECTORY);
      if (pluginDir != null) toExclude.add(VfsUtil.virtualToIoFile(pluginDir));

      VirtualFile libDir = appRoot.findChild("lib");
      if (libDir != null) toExclude.add(VfsUtil.virtualToIoFile(libDir));
    }

    final Library library = MvcModuleStructureUtil.findUserLibrary(module, getUserLibraryName());
    if (library != null) {
      for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
        toExclude.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(file)));
      }
    }
    return toExclude;
  }
Ejemplo n.º 4
0
 @Override
 public boolean contains(@NotNull VirtualFile file) {
   return super.contains(file)
       || isArchive() && Comparing.equal(PathUtil.getLocalFile(file), getVirtualFile());
 }