本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex.isInSource方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex.isInSource方法的具体用法?Java ProjectFileIndex.isInSource怎么用?Java ProjectFileIndex.isInSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectFileIndex
的用法示例。
在下文中一共展示了ProjectFileIndex.isInSource方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stepIntoSingleClass
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
public static Location stepIntoSingleClass(@NotNull final Location location) {
PsiElement element = location.getPsiElement();
if (!(element instanceof PsiClassOwner)) {
if (PsiTreeUtil.getParentOfType(element, PsiClass.class) != null) return location;
element = PsiTreeUtil.getParentOfType(element, PsiClassOwner.class);
if (element == null) return location;
}
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(location.getProject()).getFileIndex();
if (virtualFile == null || !fileIndex.isInSource(virtualFile)) {
return null;
}
final PsiClassOwner psiFile = (PsiClassOwner)element;
final PsiClass[] classes = psiFile.getClasses();
if (classes.length != 1) return location;
return PsiLocation.fromPsiElement(classes[0]);
}
示例2: 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;
}
示例3: getResolveScope
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
// For java only! For other languages resolve may be implemented with different rules, requiring larger scope.
final FileType type = file.getFileType();
if (type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() == JavaLanguage.INSTANCE) {
ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
if (index.isInContent(file) && !index.isInSource(file)) {
return GlobalSearchScope.fileScope(project, file);
}
}
return null;
}
示例4: patchIcon
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public Icon patchIcon(final Icon baseIcon, final VirtualFile file, final int flags, final Project project) {
if (project == null) {
return baseIcon;
}
Icon icon = replaceIcon(file, flags, project, baseIcon);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (fileIndex.isInSource(file) && CompilerManager.getInstance(project).isExcludedFromCompilation(file)) {
return new LayeredIcon(icon, PlatformIcons.EXCLUDED_FROM_COMPILE_ICON);
}
return icon;
}
示例5: patchIcon
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public Icon patchIcon(Icon baseIcon, VirtualFile file, @Iconable.IconFlags int flags, @Nullable Project project) {
if (project == null) {
return baseIcon;
}
Icon icon = replaceIcon(file, flags, project, baseIcon);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (fileIndex.isInSource(file) && CompilerManager.getInstance(project).isExcludedFromCompilation(file)) {
return new LayeredIcon(icon, PlatformIcons.EXCLUDED_FROM_COMPILE_ICON);
}
return icon;
}
示例6: buildDescriptor
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@NotNull
private static TestDataDescriptor buildDescriptor(@NotNull String test,
@NotNull PsiClass psiClass)
{
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(psiClass.getProject()).getFileIndex();
GotoFileModel gotoModel = new GotoFileModel(psiClass.getProject());
Set<TestLocationDescriptor> descriptors = new HashSet<TestLocationDescriptor>();
Collection<String> fileNames = getAllFileNames(test, gotoModel);
for (String name : fileNames) {
ProgressManager.checkCanceled();
boolean currentNameProcessed = false;
final Object[] elements = gotoModel.getElementsByName(name, false, name);
for (Object element : elements) {
if (!(element instanceof PsiFile)) {
continue;
}
final VirtualFile file = ((PsiFile)element).getVirtualFile();
if (file == null || fileIndex.isInSource(file) && !fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.RESOURCES)) {
continue;
}
final String filePath = PathUtil.getFileName(file.getPath()).toLowerCase();
int i = filePath.indexOf(test.toLowerCase());
// Skip files that doesn't contain target test name and files that contain digit after target test name fragment.
// Example: there are tests with names 'testEnter()' and 'testEnter2()' and we don't want test data file 'testEnter2'
// to be matched to the test 'testEnter()'.
if (i < 0 || (i + test.length() < filePath.length())
&& Character.isDigit(filePath.charAt(i + test.length())))
{
continue;
}
TestLocationDescriptor current = new TestLocationDescriptor();
current.populate(test, file);
if (!current.isComplete()) {
continue;
}
currentNameProcessed = true;
if (descriptors.isEmpty() || (descriptors.iterator().next().dir.equals(current.dir) && !descriptors.contains(current))) {
descriptors.add(current);
continue;
}
if (moreRelevantPath(current, descriptors, psiClass)) {
descriptors.clear();
descriptors.add(current);
}
}
if (currentNameProcessed) {
break;
}
}
return new TestDataDescriptor(descriptors, test);
}
示例7: collectRelativeLocations
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@NotNull
protected static List<Location> collectRelativeLocations(Project project, VirtualFile file) {
if (DumbService.isDumb(project)) return Collections.emptyList();
final List<Location> locations = new ArrayList<Location>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (fileIndex.isInContent(file) && !fileIndex.isInSource(file) && !fileIndex.isInLibraryClasses(file)) {
final VirtualFile parent = file.getParent();
final VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (contentRoot != null) {
final String relativePath = VfsUtilCore.getRelativePath(parent, contentRoot, '/');
if (relativePath != null) {
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
final List<String> words = StringUtil.getWordsIn(relativePath);
// put longer strings first
Collections.sort(words, new Comparator<String>() {
@Override
public int compare(final String o1, final String o2) {
return o2.length() - o1.length();
}
});
final GlobalSearchScope testScope = GlobalSearchScopesCore.projectTestScope(project);
Set<PsiFile> resultFiles = null;
for (String word : words) {
if (word.length() < 5) {
continue;
}
final Set<PsiFile> files = new THashSet<PsiFile>();
searchHelper.processAllFilesWithWordInLiterals(word, testScope, new CommonProcessors.CollectProcessor<PsiFile>(files));
if (resultFiles == null) {
resultFiles = files;
}
else {
resultFiles.retainAll(files);
}
if (resultFiles.isEmpty()) break;
}
if (resultFiles != null) {
for (Iterator<PsiFile> iterator = resultFiles.iterator(); iterator.hasNext(); ) {
if (!VfsUtilCore.isAncestor(contentRoot, iterator.next().getVirtualFile(), true)) {
iterator.remove();
}
}
final String fileName = file.getName();
final String nameWithoutExtension = file.getNameWithoutExtension();
for (PsiFile resultFile : resultFiles) {
if (resultFile instanceof PsiClassOwner) {
final PsiClass[] classes = ((PsiClassOwner)resultFile).getClasses();
if (classes.length > 0) {
ContainerUtil.addIfNotNull(locations, getLocation(project, fileName, nameWithoutExtension, classes[0]));
}
}
}
}
}
}
}
return locations;
}
示例8: isInLibraryClasses
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public boolean isInLibraryClasses(Project project, VirtualFile file) {
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
return projectFileIndex.isInLibraryClasses(file) && !projectFileIndex.isInSource(file);
}
示例9: isFileInRoots
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private boolean isFileInRoots(@NotNull final VirtualFile file) {
Validate.notNull(file);
final ProjectFileIndex index = ProjectRootManager.getInstance(this.project).getFileIndex();
return index.isInSource(file) || index.isInLibraryClasses(file);
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:8,代码来源:HybrisProjectView.java