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


Java ProjectFileIndex.isUnderSourceRootOfType方法代码示例

本文整理汇总了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;
}
 
开发者ID:uber,项目名称:RIBs,代码行数:32,代码来源:GenerateAction.java

示例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);
    }
}
 
开发者ID:wangtotang,项目名称:DaggerHelper,代码行数:22,代码来源:BaseAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaNavBarExtension.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PackageFileAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CreateTemplateInPackageAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LegacyNewAndroidComponentAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaSourceAction.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AbstractCreateFormAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:GrNavBarModelExtension.java

示例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 );
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:32,代码来源:CreateExtensionMethodsClassAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:CreatePackageInfoAction.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:GeneratePluginClassAction.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:JavaOutOfSourcesChecker.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiJavaDirectoryFactory.java

示例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));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:ClassesTreeStructureProvider.java


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