当前位置: 首页>>代码示例>>Java>>正文


Java ProjectFileIndex类代码示例

本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex类的具体用法?Java ProjectFileIndex怎么用?Java ProjectFileIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProjectFileIndex类属于com.intellij.openapi.roots包,在下文中一共展示了ProjectFileIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@CheckReturnValue
@VisibleForTesting
@SuppressWarnings("WeakerAccess")
static boolean isAvailable(@Nonnull AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return false;
    }

    final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return false;
    }

    final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    final ProjectFileIndex fileIndex = rootManager.getFileIndex();
    final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories())
            .filter(directory -> {
                final VirtualFile virtualFile = directory.getVirtualFile();
                return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
            })
            .findFirst();
    return sourceDirectory.isPresent();
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:25,代码来源:NewClassAction.java

示例2: isAvailable

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
/**
 * Checked whether or not this action can be enabled.
 *
 * <p>Requirements to be enabled: * User must be in a Java source folder.
 *
 * @param dataContext to figure out where the user is.
 * @return {@code true} when the action is available, {@code false} when the action is not
 *     available.
 */
private boolean isAvailable(DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null || view.getDirectories().length == 0) {
    return false;
  }

  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (PsiDirectory dir : view.getDirectories()) {
    if (projectFileIndex.isUnderSourceRootOfType(
            dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES)
        && checkPackageExists(dir)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:uber,项目名称:RIBs,代码行数:32,代码来源:GenerateAction.java

示例3: createUIComponents

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
private void createUIComponents() {
    testTargetTextField = new EditorTextField("", getProject(), FileTypes.PLAIN_TEXT);
    namespaceComboBox = new PhpNamespaceComboBox(getProject(), "", getDisposable());
    directoryComboBox = new PhpPsrDirectoryComboBox(getProject()) {
        @Override
        public void init(@NotNull VirtualFile baseDir, @NotNull String namespace) {
            super.init(baseDir, namespace);
            ProjectFileIndex index = ProjectRootManager.getInstance(TesterNewTestCaseDialog.this.getProject()).getFileIndex();
            this.setDirectoriesFilter(index::isInTestSourceContent);

            this.updateDirectories(TesterNewTestCaseDialog.this.getNamespace());
        }
    };

    classToTestLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.classToTest"));
    testClassLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.testClass"));
    namespaceLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.namespace"));
    fileNameLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.fileName"));
    directoryLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.directory"));

    testTargetCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
    namespaceCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
    directoryCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:25,代码来源:TesterNewTestCaseDialog.java

示例4: getReferencePath

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
public static String getReferencePath(Project project, VirtualFile file) {
  final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(file);
  if (logicalRoot != null) {
    return getRelativePath(file, logicalRoot.getVirtualFile());
  }

  ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file);
  if (sourceRoot != null) {
    return getRelativePath(file, sourceRoot);
  }

  VirtualFile root = fileIndex.getContentRootForFile(file);
  if (root != null) {
    return getRelativePath(file, root);
  }

  return file.getPath();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:IfsUtil.java

示例5: addCompletions

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
    Project project = parameters.getOriginalFile().getManager().getProject();

    List<VirtualFile> resourceRoots = ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
    resourceRoots.addAll(ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.TESTS));
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (final VirtualFile sourceRoot : resourceRoots) {
        if (sourceRoot.isValid() && sourceRoot.getCanonicalFile() != null) {
            VfsUtil.processFilesRecursively(sourceRoot.getCanonicalFile(), virtualFile -> {
                propertyCompletionProviders.stream()
                    .filter(p -> p.isValidExtension(virtualFile.getCanonicalPath()) && !projectFileIndex.isExcluded(sourceRoot))
                    .forEach(p -> p.buildResultSet(resultSet, virtualFile));
                return true;
            });
        }
    }
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:19,代码来源:CamelPropertyPlaceholderSmartCompletionExtension.java

示例6: toString

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@Override
public String toString() {
  if (myText == null) {
    Module module = ModuleUtilCore.findModuleForPsiElement(myClass);
    if (module != null) {
      myText = module.getName();
    }
    else {
      VirtualFile virtualFile = myClass.getContainingFile().getVirtualFile();
      final ProjectFileIndex index = ProjectRootManager.getInstance(myClass.getProject()).getFileIndex();
      VirtualFile root = index.getSourceRootForFile(virtualFile);
      if (root == null) {
        root = index.getClassRootForFile(virtualFile);
      }
      if (root != null) {
        myText = root.getName();
      }
      else {
        myText = virtualFile.getPath();
      }
    }
  }
  return myText;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AlternativeSourceNotificationProvider.java

示例7: checkPackageAndClassConflict

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@Nullable
static HighlightInfo checkPackageAndClassConflict(@NotNull PsiJavaCodeReferenceElement ref, @NotNull PsiFile containingFile) {
  if (ref.isQualified() && isInsidePackageStatement(ref)) {
    VirtualFile file = containingFile.getVirtualFile();
    if (file != null) {
      Module module = ProjectFileIndex.SERVICE.getInstance(ref.getProject()).getModuleForFile(file);
      if (module != null) {
        GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
        PsiClass aClass = JavaPsiFacade.getInstance(ref.getProject()).findClass(ref.getCanonicalText(), scope);
        if (aClass != null) {
          String message = JavaErrorMessages.message("package.clashes.with.class", ref.getText());
          return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref).descriptionAndTooltip(message).create();
        }
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:HighlightUtil.java

示例8: findContainingMavenizedModule

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@Nullable
public static Module findContainingMavenizedModule(@NotNull PsiFile psiFile) {
  VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return null;

  Project project = psiFile.getProject();

  MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
  if (!manager.isMavenizedProject()) return null;

  ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();

  Module module = index.getModuleForFile(file);
  if (module == null || !manager.isMavenizedModule(module)) return null;
  return module;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MavenDomUtil.java

示例9: MoveClassToModuleFix

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
public MoveClassToModuleFix(String referenceName, Module currentModule, PsiDirectory root, PsiElement psiElement) {
  myReferenceName = referenceName;
  myCurrentModule = currentModule;
  mySourceRoot = root;
  final Project project = psiElement.getProject();
  final PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(referenceName, GlobalSearchScope.allScope(project));
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (final PsiClass aClass : classes) {
    if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue;
    final PsiFile psiFile = aClass.getContainingFile();
    if (!(psiFile instanceof PsiJavaFile)) continue;
    if (aClass.getQualifiedName() == null) continue;
    VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null) continue;
    final Module classModule = fileIndex.getModuleForFile(virtualFile);
    if (classModule != null && classModule != currentModule && !ModuleRootManager.getInstance(currentModule).isDependsOn(classModule)) {
      myModules.put(aClass, classModule);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MoveClassToModuleFix.java

示例10: elementHasSourceCode

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
private boolean elementHasSourceCode() {
  PsiFileSystemItem[] items;
  if (myElement instanceof PsiDirectory) {
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)myElement);
    if (aPackage == null) return false;
    items = aPackage.getDirectories(new EverythingGlobalScope(myProject));
  }
  else if (myElement instanceof PsiPackage) {
    items = ((PsiPackage)myElement).getDirectories(new EverythingGlobalScope(myProject));
  }
  else {
    PsiFile containingFile = myElement.getNavigationElement().getContainingFile();
    if (containingFile == null) return false;
    items = new PsiFileSystemItem[] {containingFile};
  }
  ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
  for (PsiFileSystemItem item : items) {
    VirtualFile file = item.getVirtualFile();
    if (file != null && projectFileIndex.isInSource(file)) return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaDocInfoGenerator.java

示例11: isUnsynced

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
static boolean isUnsynced(Project project, VirtualFile virtualFile) {
  if (!virtualFile.isInLocalFileSystem()) {
    return false;
  }
  if (ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile) == null) {
    return false;
  }
  OCWorkspace workspace = OCWorkspaceProvider.getWorkspace(project);
  if (!(workspace instanceof BlazeCWorkspace)) {
    // Skip if the project isn't a Blaze project or doesn't have C support enabled anyway.
    return false;
  }
  if (workspace.getConfigurations().isEmpty()) {
    // The workspace configurations may not have been loaded yet.
    return false;
  }
  SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
  return sourceToTargetMap
      .getRulesForSourceFile(VfsUtilCore.virtualToIoFile(virtualFile))
      .isEmpty();
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:22,代码来源:SyncStatusHelper.java

示例12: isAvailable

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
private static boolean isAvailable(DataContext dataContext) {
  final Module module = LangDataKeys.MODULE.getData(dataContext);
  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

  if (module == null ||
      view == null ||
      view.getDirectories().length == 0) {
    return false;
  }
  final AndroidFacet facet = AndroidFacet.getInstance(module);

  if (facet == null || facet.isGradleProject()) {
    return false;
  }
  final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
  final JavaDirectoryService dirService = JavaDirectoryService.getInstance();

  for (PsiDirectory dir : view.getDirectories()) {
    if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
        dirService.getPackage(dir) != null) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LegacyNewAndroidComponentAction.java

示例13: isUnsynced

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
static boolean isUnsynced(Project project, VirtualFile virtualFile) {
  if (!virtualFile.isInLocalFileSystem()) {
    return false;
  }
  if (ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile) == null) {
    return false;
  }
  Set<File> syncedJavaFiles =
      SyncCache.getInstance(project)
          .get(SyncStatusHelper.class, SyncStatusHelper::getSyncedJavaFiles);
  if (syncedJavaFiles == null) {
    return false;
  }
  File file = new File(virtualFile.getPath());
  return !syncedJavaFiles.contains(file);
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:17,代码来源:SyncStatusHelper.java

示例14: findTarget

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
@Nullable
private static VirtualFile findTarget(@NotNull AnActionEvent e, @NotNull Project project) {
  VirtualFile[] virtualFiles = VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
  if (virtualFiles != null && virtualFiles.length == 1) {
    VirtualFile target = virtualFiles[0];
    if (isModuleSourceRoot(target, project) || project.getBaseDir().equals(target)) {
      // Module folders and project folder are ignored.
      return null;
    }
    ProjectFileIndex projectIndex = ProjectRootManager.getInstance(project).getFileIndex();
    if (projectIndex.isExcluded(target)) {
      // Excluded folders are ignored.
      return null;
    }
    return target;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:IncludeModuleForFileAction.java

示例15: processResources

import com.intellij.openapi.roots.ProjectFileIndex; //导入依赖的package包/类
static boolean processResources(Project project,
                                VirtualFile sourceRoot,
                                VirtualFile file,
                                List<Pattern> includes,
                                List<Pattern> excludes,
                                String resOutputDir,
                                ResourceProcessor processor) {
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (!fileIndex.isExcluded(file)) {
    String relPath = VfsUtilCore.getRelativePath(file, sourceRoot, '/');
    if (relPath != null && MavenUtil.isIncluded(relPath, includes, excludes)) {
      if (processor.process(file, resOutputDir + "/" + relPath)) {
        return true;
      }
    }
  }
  if (file.isDirectory()) {
    for (VirtualFile child : file.getChildren()) {
      if (processResources(project, sourceRoot, child, includes, excludes, resOutputDir, processor)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:AndroidMavenProviderImpl.java


注:本文中的com.intellij.openapi.roots.ProjectFileIndex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。