コード例 #1
0
    public KotlinPsiElementFinderImpl(Project project) {
      this.javaFileManager = findJavaFileManager(project);
      this.psiPackageManager = PsiPackageManager.getInstance(project);
      this.isCliFileManager = javaFileManager instanceof KotlinCliJavaFileManager;

      this.packageIndex = DirectoryIndex.getInstance(project);
      this.psiManager = PsiManager.getInstance(project);
    }
コード例 #2
0
    @Override
    public PsiJavaPackage findPackage(
        @NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
      if (isCliFileManager) {
        return (PsiJavaPackage)
            psiPackageManager.findPackage(qualifiedName, JavaModuleExtension.class);
      }

      Query<VirtualFile> dirs = packageIndex.getDirectoriesByPackageName(qualifiedName, true);
      return hasDirectoriesInScope(dirs, scope)
          ? new PsiPackageImpl(
              psiManager, psiPackageManager, JavaModuleExtension.class, qualifiedName)
          : null;
    }
コード例 #3
0
  public CoreModule(
      @NotNull Disposable parentDisposable, @NotNull Project project, String moduleFilePath) {
    super(project.getPicoContainer(), parentDisposable);
    myLifetime = parentDisposable;
    myProject = project;
    myPath = moduleFilePath;

    Extensions.instantiateArea(ExtensionAreas.IDEA_MODULE, this, null);
    CoreApplicationEnvironment.registerExtensionPoint(
        Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class);
    Disposer.register(
        parentDisposable,
        new Disposable() {
          @Override
          public void dispose() {
            Extensions.disposeArea(CoreModule.this);
          }
        });
    initModuleExtensions();

    final ModuleRootManagerImpl moduleRootManager =
        new ModuleRootManagerImpl(
            this,
            ProjectRootManagerImpl.getInstanceImpl(project),
            VirtualFilePointerManager.getInstance()) {
          @Override
          public void loadState(ModuleRootManagerState object) {
            loadState(object, false);
          }
        };
    Disposer.register(
        parentDisposable,
        new Disposable() {
          @Override
          public void dispose() {
            moduleRootManager.disposeComponent();
          }
        });
    getPicoContainer().registerComponentInstance(ModuleRootManager.class, moduleRootManager);
    getPicoContainer()
        .registerComponentInstance(
            PathMacroManager.class, new ModulePathMacroManager(PathMacros.getInstance(), this));
    getPicoContainer()
        .registerComponentInstance(
            ModuleFileIndex.class,
            new ModuleFileIndexImpl(this, DirectoryIndex.getInstance(project)));
    myModuleScopeProvider = createModuleScopeProvider();
  }
コード例 #4
0
  /**
   * Here we check if a given file belongs to our plugin. We take this road because we need the
   * actual file and not a filename to check files without extension.
   *
   * <p>A file is checked according to the rules defined in the facet settings. A file can be set to
   * ignored, accepted or auto. Auto means that the content is checked.
   *
   * @param file The file to check
   * @return True if BashSupport wants to take that file
   */
  public boolean isMyFileType(VirtualFile file) {
    if (file == null) {
      return false;
    }

    if (file.isDirectory()) {
      return false;
    }

    if (extensionList.contains(file.getExtension())) {
      return true;
    } else if (!file.isInLocalFileSystem()) {
      return false;
    } else if (StringUtils.isEmpty(file.getExtension())) {
      BashFacet facet = null;
      try {
        // no extensions, special checks (looking at the content, etc)

        // guess project
        Project project = ProjectUtil.guessProjectForFile(file);
        if (project == null) {
          return false;
        }

        DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project);
        if (dumbService == null || dumbService.isDumb()) {
          return false;
        }

        DirectoryIndex directoryIndex = DirectoryIndex.getInstance(project);
        if (directoryIndex == null || !directoryIndex.isInitialized()) {
          return false;
        }

        Module module = ModuleUtil.findModuleForFile(file, project);
        if (module == null) {
          return false;
        }

        facet = BashFacet.getInstance(module);
        if (facet == null) {
          return false;
        }

        BashFacetConfiguration config = facet.getConfiguration();
        FileMode mode = config.findMode(file);

        if (mode == FileMode.accept()) {
          return true;
        } else if (mode == FileMode.ignore()) {
          return false;
        } else if (mode == FileMode.auto()) {
          return BashContentUtil.isProbablyBashFile(
              VfsUtil.virtualToIoFile(file),
              MIN_FILE_PROBABILIY,
              ProjectUtil.guessProjectForFile(file));
        }
      } catch (Exception e) {
        // ignore this
        LOG.warn("Could not check the file type due to exception", e);
      }
    }

    return false;
  }