本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex.isInTestSourceContent方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex.isInTestSourceContent方法的具体用法?Java ProjectFileIndex.isInTestSourceContent怎么用?Java ProjectFileIndex.isInTestSourceContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectFileIndex
的用法示例。
在下文中一共展示了ProjectFileIndex.isInTestSourceContent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groupUsage
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public UsageGroup groupUsage(@NotNull Usage usage) {
if (!(usage instanceof PsiElementUsage)) {
return null;
}
PsiElementUsage elementUsage = (PsiElementUsage)usage;
PsiElement element = elementUsage.getElement();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (virtualFile == null) {
return null;
}
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
boolean isInLib = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
if (isInLib) return LIBRARY;
boolean isInTest = fileIndex.isInTestSourceContent(virtualFile);
return isInTest ? TEST : PRODUCTION;
}
示例2: adjustScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public static GlobalSearchScope adjustScope(PsiDirectory baseDir,
GlobalSearchScope scope,
boolean skipSourceDirsForBaseTestDirectory,
boolean skipTestDirsForBaseSourceDirectory) {
if (baseDir != null) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(baseDir.getProject()).getFileIndex();
if (fileIndex.isInTestSourceContent(baseDir.getVirtualFile())) {
if (skipSourceDirsForBaseTestDirectory) {
return scope.intersectWith(GlobalSearchScopes.projectTestScope(baseDir.getProject()));
}
}
else {
if (skipTestDirsForBaseSourceDirectory) {
return scope.intersectWith(GlobalSearchScopes.projectProductionScope(baseDir.getProject()));
}
}
}
return scope;
}
示例3: getResolveScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
if (file.getFileType() != GroovyFileType.GROOVY_FILE_TYPE) return null;
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = projectFileIndex.getModuleForFile(file);
if (module == null) return null; //groovy files are only in modules
boolean includeTests = projectFileIndex.isInTestSourceContent(file) || !projectFileIndex.isInSourceContent(file);
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
final PsiFile psi = PsiManager.getInstance(project).findFile(file);
if (psi instanceof GroovyFile && ((GroovyFile)psi).isScript()) {
return GroovyScriptTypeDetector.patchResolveScope((GroovyFile)psi, scope);
}
else {
return scope;
}
}
示例4: getDirCoverageInformationString
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
public String getDirCoverageInformationString(@NotNull final PsiDirectory directory,
@NotNull final CoverageSuitesBundle currentSuite,
@NotNull final CoverageDataManager coverageDataManager) {
final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(directory);
if (psiPackage == null) return null;
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(directory.getProject()).getFileIndex();
final VirtualFile virtualFile = directory.getVirtualFile();
final boolean isInTestContent = projectFileIndex.isInTestSourceContent(virtualFile);
if (!currentSuite.isTrackTestFolders() && isInTestContent) {
return null;
}
return isInTestContent ? getCoverageInformationString(myTestDirCoverageInfos.get(virtualFile), coverageDataManager.isSubCoverageActive())
: getCoverageInformationString(myDirCoverageInfos.get(virtualFile), coverageDataManager.isSubCoverageActive());
}
示例5: getDirCoverageInfo
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
protected DirCoverageInfo getDirCoverageInfo(@NotNull final PsiDirectory directory,
@NotNull final CoverageSuitesBundle currentSuite) {
final VirtualFile dir = directory.getVirtualFile();
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(directory.getProject()).getFileIndex();
//final Module module = projectFileIndex.getModuleForFile(dir);
final boolean isInTestContent = projectFileIndex.isInTestSourceContent(dir);
if (!currentSuite.isTrackTestFolders() && isInTestContent) {
return null;
}
final String path = normalizeFilePath(dir.getPath());
return isInTestContent ? myTestDirCoverageInfos.get(path) : myDirCoverageInfos.get(path);
}
示例6: getSearchScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@NotNull
public static GlobalSearchScope getSearchScope(@NotNull PsiElement element) {
Project project = element.getProject();
// ignore scopes in test mode. Todo: set up tests properly and remove this hack
if (ApplicationManager.getApplication().isUnitTestMode()) return GlobalSearchScope.projectScope(project);
PsiFile psiFile = element.getContainingFile();
VirtualFile virtualFile = VirtualFileUtil.getOriginalVirtualFile(psiFile);
if (!SchemaFileIndexUtil.isSchemaSourceFile(project, virtualFile))
return GlobalSearchScope.fileScope(psiFile);
Module module = ModuleUtil.findModuleForPsiElement(element);
if (module == null)
return GlobalSearchScope.projectScope(project); // or file scope?
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
boolean inTestSourceContent = fileIndex.isInTestSourceContent(virtualFile);
return module.getModuleWithDependenciesAndLibrariesScope(inTestSourceContent);
}
示例7: expand
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public String expand(DataContext dataContext) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return null;
}
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (file != null) {
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = projectFileIndex.getModuleForFile(file);
if (module != null){
boolean isTest = projectFileIndex.isInTestSourceContent(file);
String outputPathUrl = isTest ? CompilerModuleExtension.getInstance(module).getCompilerOutputUrlForTests()
: CompilerModuleExtension.getInstance(module).getCompilerOutputUrl();
if (outputPathUrl == null) return null;
return VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar);
}
}
Module[] allModules = ModuleManager.getInstance(project).getSortedModules();
if (allModules.length == 0) {
return null;
}
String[] paths = CompilerPathsEx.getOutputPaths(allModules);
final StringBuffer outputPath = new StringBuffer();
for (int idx = 0; idx < paths.length; idx++) {
String path = paths[idx];
if (idx > 0) {
outputPath.append(File.pathSeparator);
}
outputPath.append(path);
}
return outputPath.toString();
}
示例8: chooseSelection
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
private static DirectoryChooser.ItemWrapper chooseSelection(final VirtualFile initialTargetDirectorySourceRoot,
final ProjectFileIndex fileIndex,
final ArrayList<DirectoryChooser.ItemWrapper> items,
final DirectoryChooser.ItemWrapper initial,
final DirectoryChooser.ItemWrapper oldOne) {
if (initial != null || ((initialTargetDirectorySourceRoot == null || items.size() > 2) && items.contains(NULL_WRAPPER)) || items.isEmpty()) {
return initial;
}
else {
if (oldOne != null) {
return oldOne;
}
else if (initialTargetDirectorySourceRoot != null) {
final boolean inTest = fileIndex.isInTestSourceContent(initialTargetDirectorySourceRoot);
for (DirectoryChooser.ItemWrapper item : items) {
PsiDirectory directory = item.getDirectory();
if (directory != null) {
final VirtualFile virtualFile = directory.getVirtualFile();
if (fileIndex.isInTestSourceContent(virtualFile) == inTest) {
return item;
}
}
}
}
}
return items.get(0);
}
示例9: chooseDestinationPackage
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
public static PsiDirectory chooseDestinationPackage(Project project, String packageName, @Nullable PsiDirectory baseDir) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PackageWrapper packageWrapper = new PackageWrapper(psiManager, packageName);
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
PsiDirectory directory;
PsiDirectory[] directories = aPackage != null ? aPackage.getDirectories() : null;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile baseDirVirtualFile = baseDir != null ? baseDir.getVirtualFile() : null;
final boolean isBaseDirInTestSources = baseDirVirtualFile != null && fileIndex.isInTestSourceContent(baseDirVirtualFile);
if (directories != null && directories.length == 1 && (baseDirVirtualFile == null ||
fileIndex.isInTestSourceContent(directories[0].getVirtualFile()) == isBaseDirInTestSources)) {
directory = directories[0];
}
else {
final List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
if (contentSourceRoots.size() == 1 && (baseDirVirtualFile == null || fileIndex.isInTestSourceContent(contentSourceRoots.get(0)) == isBaseDirInTestSources)) {
directory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
@Override
public PsiDirectory compute() {
return RefactoringUtil.createPackageDirectoryInSourceRoot(packageWrapper, contentSourceRoots.get(0));
}
});
}
else {
final VirtualFile sourceRootForFile = chooseSourceRoot(packageWrapper, contentSourceRoots, baseDir);
if (sourceRootForFile == null) return null;
directory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
@Override
public PsiDirectory compute() {
return new AutocreatingSingleSourceRootMoveDestination(packageWrapper, sourceRootForFile).getTargetDirectory((PsiDirectory)null);
}
});
}
}
return directory;
}
示例10: getInherentResolveScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private GlobalSearchScope getInherentResolveScope(VirtualFile vFile) {
ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
Module module = projectFileIndex.getModuleForFile(vFile);
if (module != null) {
boolean includeTests = projectFileIndex.isInTestSourceContent(vFile);
return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
}
if (!projectFileIndex.isInLibrarySource(vFile) && !projectFileIndex.isInLibraryClasses(vFile)) {
return GlobalSearchScope.allScope(myProject);
}
return LibraryScopeCache.getInstance(myProject).getLibraryScope(projectFileIndex.getOrderEntriesForFile(vFile));
}
示例11: getSearchScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
@Nullable
public GlobalSearchScope getSearchScope() {
GlobalSearchScope scope = null;
Module[] modules = getConvertContextModules();
if (modules.length != 0) {
PsiFile file = getFile();
file = file.getOriginalFile();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(file.getProject()).getFileIndex();
boolean tests = fileIndex.isInTestSourceContent(virtualFile);
for (Module module : modules) {
if (scope == null) {
scope = module.getModuleRuntimeScope(tests);
}
else {
scope = scope.union(module.getModuleRuntimeScope(tests));
}
}
}
}
return scope; // ??? scope == null ? GlobalSearchScope.allScope(getProject()) : scope; ???
}
示例12: acceptedByFilters
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public boolean acceptedByFilters(@NotNull final PsiFile psiFile, @NotNull final CoverageSuitesBundle suite) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) return false;
final Project project = psiFile.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (!suite.isTrackTestFolders() && fileIndex.isInTestSourceContent(virtualFile)) {
return false;
}
for (CoverageSuite coverageSuite : suite.getSuites()) {
final JavaCoverageSuite javaSuite = (JavaCoverageSuite)coverageSuite;
final List<PsiPackage> packages = javaSuite.getCurrentSuitePackages(project);
if (isUnderFilteredPackages((PsiClassOwner)psiFile, packages)) {
return true;
} else {
final List<PsiClass> classes = javaSuite.getCurrentSuiteClasses(project);
for (PsiClass aClass : classes) {
final PsiFile containingFile = aClass.getContainingFile();
if (psiFile.equals(containingFile)) {
return true;
}
}
}
}
return false;
}
示例13: getUseScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
@NotNull
public GlobalSearchScope getUseScope(@NotNull PsiElement element) {
VirtualFile vDirectory;
final VirtualFile virtualFile;
final PsiFile containingFile;
final GlobalSearchScope allScope = GlobalSearchScope.allScope(myManager.getProject());
if (element instanceof PsiDirectory) {
vDirectory = ((PsiDirectory)element).getVirtualFile();
virtualFile = null;
containingFile = null;
}
else {
containingFile = element.getContainingFile();
if (containingFile == null) return allScope;
virtualFile = containingFile.getVirtualFile();
if (virtualFile == null) return allScope;
if (virtualFile instanceof VirtualFileWindow) {
return GlobalSearchScope.fileScope(myProject, ((VirtualFileWindow)virtualFile).getDelegate());
}
vDirectory = virtualFile.getParent();
}
if (vDirectory == null) return allScope;
final ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
final Module module = projectFileIndex.getModuleForFile(vDirectory);
if (module == null) {
VirtualFile notNullVFile = virtualFile != null ? virtualFile : vDirectory;
final List<OrderEntry> entries = projectFileIndex.getOrderEntriesForFile(notNullVFile);
if (entries.isEmpty() && myAdditionalIndexableFileSet.isInSet(notNullVFile)) {
return allScope;
}
GlobalSearchScope result = LibraryScopeCache.getInstance(myProject).getLibraryUseScope(entries);
return containingFile == null || virtualFile.isDirectory() || result.contains(virtualFile)
? result : GlobalSearchScope.fileScope(containingFile).uniteWith(result);
}
boolean isTest = projectFileIndex.isInTestSourceContent(vDirectory);
GlobalSearchScope scope = isTest
? GlobalSearchScope.moduleTestsWithDependentsScope(module)
: GlobalSearchScope.moduleWithDependentsScope(module);
RefResolveService resolveService;
if (virtualFile instanceof VirtualFileWithId && RefResolveService.ENABLED && (resolveService = RefResolveService.getInstance(myProject)).isUpToDate()) {
return resolveService.restrictByBackwardIds(virtualFile, scope);
}
return scope;
}