本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex.isUnderSourceRootOfType方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex.isUnderSourceRootOfType方法的具体用法?Java ProjectFileIndex.isUnderSourceRootOfType怎么用?Java ProjectFileIndex.isUnderSourceRootOfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectFileIndex
的用法示例。
在下文中一共展示了ProjectFileIndex.isUnderSourceRootOfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: update
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public void update(AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
if(presentation.isEnabled()) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getProject();
if (view != null && project != null) {
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
PsiDirectory[] dirs = view.getDirectories();
for (PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
JavaDirectoryService.getInstance().getPackage(dir) != null && isValidForClass(project,dir)) {
return;
}
}
}
presentation.setEnabled(false);
presentation.setVisible(false);
}
}
示例3: adjustElement
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement adjustElement(final PsiElement psiElement) {
final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
if (file != null &&
(index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
if (psiElement instanceof PsiJavaFile) {
final PsiJavaFile psiJavaFile = (PsiJavaFile)psiElement;
if (psiJavaFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) {
final PsiClass[] psiClasses = psiJavaFile.getClasses();
if (psiClasses.length == 1) {
return psiClasses[0];
}
}
}
if (psiElement instanceof PsiClass) {
return psiElement;
}
}
return containingFile;
}
return psiElement;
}
示例4: getFilesToPackage
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@NotNull
private static List<VirtualFile> getFilesToPackage(@NotNull AnActionEvent e, @NotNull Project project) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (files == null) return Collections.emptyList();
List<VirtualFile> result = new ArrayList<VirtualFile>();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final CompilerManager compilerManager = CompilerManager.getInstance(project);
for (VirtualFile file : files) {
if (file == null || file.isDirectory() ||
fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && compilerManager.isCompilableFileType(file.getFileType())) {
return Collections.emptyList();
}
final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
for (Artifact artifact : artifacts) {
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
result.add(file);
break;
}
}
}
return result;
}
示例5: isAvailable
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
protected boolean isAvailable(final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || view == null || view.getDirectories().length == 0) {
return false;
}
if (mySourceRootTypes == null) {
return true;
}
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiDirectory dir : view.getDirectories()) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), mySourceRootTypes) && checkPackageExists(dir)) {
return true;
}
}
return false;
}
示例6: 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;
}
示例7: isAvailable
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
protected 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 ||
AndroidFacet.getInstance(module) == null) {
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 &&
!dirService.getPackage(dir).getQualifiedName().isEmpty()) {
return true;
}
}
return false;
}
示例8: update
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public void update(final AnActionEvent e) {
super.update(e);
final Project project = e.getData(CommonDataKeys.PROJECT);
final Presentation presentation = e.getPresentation();
if (presentation.isEnabled()) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
if (view != null) {
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiDirectory[] dirs = view.getDirectories();
for (final PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
return;
}
}
}
presentation.setEnabled(false);
presentation.setVisible(false);
}
}
示例9: adjustElement
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public PsiElement adjustElement(PsiElement psiElement) {
final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile instanceof GroovyFileBase) {
final VirtualFile file = containingFile.getVirtualFile();
if (file != null && (index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
if (psiElement instanceof GroovyFileBase) {
final GroovyFileBase grFile = (GroovyFileBase)psiElement;
if (grFile.getViewProvider().getBaseLanguage().equals(GroovyLanguage.INSTANCE)) {
final PsiClass[] psiClasses = grFile.getClasses();
if (psiClasses.length == 1 && !grFile.isScript()) {
return psiClasses[0];
}
}
}
else if (psiElement instanceof GrTypeDefinition) {
return psiElement;
}
}
return containingFile;
}
return psiElement;
}
示例10: update
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public void update( AnActionEvent e )
{
super.update( e );
boolean enabled;
final DataContext dataContext = e.getDataContext();
final IdeView view = LangDataKeys.IDE_VIEW.getData( dataContext );
if( view == null )
{
enabled = false;
}
else
{
final Project project = PlatformDataKeys.PROJECT.getData( dataContext );
final PsiDirectory dir = view.getOrChooseDirectory();
if( dir == null || project == null )
{
enabled = false;
}
else
{
PsiPackage pkg = JavaDirectoryService.getInstance().getPackage( dir );
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance( project).getFileIndex();
enabled = pkg != null && projectFileIndex.isUnderSourceRootOfType( dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES );
}
}
e.getPresentation().setEnabled( enabled );
}
示例11: isAvailable
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private static boolean isAvailable(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || view == null) {
return false;
}
final PsiDirectory[] directories = view.getDirectories();
if (directories.length == 0) {
return false;
}
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
for (PsiDirectory directory : directories) {
if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
PsiUtil.isLanguageLevel5OrHigher(directory)) {
final PsiPackage aPackage = directoryService.getPackage(directory);
if (aPackage != null) {
final String qualifiedName = aPackage.getQualifiedName();
if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
return true;
}
}
}
}
return false;
}
示例12: update
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public void update(final AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
if (presentation.isEnabled()) {
final DataContext context = e.getDataContext();
final Module module = LangDataKeys.MODULE.getData(context);
if (PluginModuleType.isPluginModuleOrDependency(module)) {
final IdeView view = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (view != null && project != null) {
// from com.intellij.ide.actions.CreateClassAction.update()
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
PsiDirectory[] dirs = view.getDirectories();
for (PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
JavaDirectoryService.getInstance().getPackage(dir) != null) {
return;
}
}
}
}
presentation.setEnabled(false);
presentation.setVisible(false);
}
}
示例13: isOutOfSources
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public boolean isOutOfSources(@NotNull Project project, @NotNull VirtualFile virtualFile) {
ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
return !index.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
}
示例14: isPackage
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public boolean isPackage(@NotNull PsiDirectory directory) {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myManager.getProject()).getFileIndex();
VirtualFile virtualFile = directory.getVirtualFile();
return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES) && fileIndex.getPackageNameByDirectory(virtualFile) != null;
}
示例15: fileInRoots
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private boolean fileInRoots(VirtualFile file) {
final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
return file != null && (index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file));
}