Java 类com.intellij.psi.search.FilenameIndex 实例源码

项目:reasonml-idea-plugin    文件:RmlPsiUtil.java   
@NotNull
public static List<PsiFile> findFileModules(@NotNull Project project, String extension, @NotNull String name, boolean exact) {
    ArrayList<PsiFile> result = new ArrayList<>();

    Bucklescript bucklescript = BucklescriptProjectComponent.getInstance(project);
    PsiManager psiManager = PsiManager.getInstance(project);

    Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, extension);
    for (VirtualFile vFile : files) {
        String canonicalPath = vFile.getCanonicalPath();
        if (bucklescript.isDependency(canonicalPath)) {
            FileBase file = (FileBase) psiManager.findFile(vFile);
            if (file != null) {
                String fileModuleName = file.asModuleName();
                boolean found = exact ? fileModuleName.equals(name) : fileModuleName.startsWith(name);
                if (found) {
                    result.add(file);
                }
            }
        }
    }

    return result;
}
项目:reasonml-idea-plugin    文件:RmlPsiUtil.java   
@NotNull
public static List<PsiModule> findModules(@NotNull Project project, @NotNull String name) {
    ArrayList<PsiModule> result = new ArrayList<>();

    Collection<VirtualFile> virtualFiles = FilenameIndex.getAllFilesByExt(project, RmlFileType.INSTANCE.getDefaultExtension());
    for (VirtualFile virtualFile : virtualFiles) {
        PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
        PsiModule[] modules = PsiTreeUtil.getChildrenOfType(file, PsiModule.class);
        if (modules != null) {
            for (PsiModule module : modules) {
                if (name.equals(module.getName())) {
                    result.add(module);
                }
            }
        }
    }

    return result;
}
项目:idea-php-typo3-plugin    文件:ConstantMatcherInspection.java   
private Set<String> getRemovedConstantsFQNs(ConstantReference element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : constantMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream()
            .map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
            .collect(Collectors.toSet());
}
项目:idea-php-typo3-plugin    文件:FunctionCallMatcherInspection.java   
private Set<String> getRemovedGlobalFuntions(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "FunctionCallMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : constantMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream()
            .map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
            .collect(Collectors.toSet());
}
项目:idea-php-typo3-plugin    文件:ClassConstantMatcherInspection.java   
private Set<String> getDeprecatedClassConstants(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : classConstantMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream().map(stringLiteral -> ((StringLiteralExpression)stringLiteral).getContents()).collect(Collectors.toSet());
}
项目:idea-php-typo3-plugin    文件:ClassNameMatcherInspection.java   
private Set<String> getDeprecatedClasses(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] classNameMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassNameMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : classNameMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream()
            .map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
            .collect(Collectors.toSet());
}
项目:magento2-phpstorm-plugin    文件:LayoutIndex.java   
public static List<XmlFile> getLayoutFiles(Project project, @Nullable String fileName) {
    List<XmlFile> results = new ArrayList<XmlFile>();
    Collection<VirtualFile> xmlFiles = FilenameIndex.getAllFilesByExt(project, "xml");

    PsiManager psiManager = PsiManager.getInstance(project);
    for (VirtualFile xmlFile: xmlFiles) {
        if (isLayoutFile(xmlFile)) {
            if (fileName != null && !xmlFile.getNameWithoutExtension().equals(fileName)) {
                continue;
            }

            PsiFile file = psiManager.findFile(xmlFile);
            if (file != null) {
                results.add((XmlFile)file);
            }
        }
    }

    return results;
}
项目:mule-intellij-plugins    文件:ConsoleFlowStackFilter.java   
@Nullable
@Override
public Result applyFilter(String textLine, int endPoint)
{
    final Matcher matcher = ELEMENT_REGEX.matcher(textLine);
    if (matcher.find())
    {
        final String element = matcher.group(1);
        final String fileName = matcher.group(4);
        final String lineNumber = matcher.group(5);
        final PsiFile[] psiFiles = FilenameIndex.getFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject));
        if (psiFiles.length == 0)
        {
            logger.debug("File: " + fileName + " not found in project: " + myProject.getName());
            return null;
        }
        else
        {
            HyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, psiFiles[0].getVirtualFile(), Integer.parseInt(lineNumber) - 1);
            return new Result(endPoint - (textLine.length() - element.length()), endPoint, info);
        }
    }
    return null;
}
项目:mule-intellij-plugins    文件:MuleSchemaProvider.java   
private Map<String, String> getSchemasFromSpringSchemas(@NotNull Module module) throws Exception {
    Map<String, String> schemasMap = new HashMap<>();

    PsiFile[] psiFiles = FilenameIndex.getFilesByName(module.getProject(), "spring.schemas", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));

    for (PsiFile nextSpringS : psiFiles) {
        VirtualFile springSchemasFile = nextSpringS.getVirtualFile();
        if (springSchemasFile != null) {
            String springSchemasContent = new String(springSchemasFile.contentsToByteArray());
            schemasMap.putAll(parseSpringSchemas(springSchemasContent));
        }
    }

    //Fix for HTTP module schema vs old HTTP transport schema
    schemasMap.put("http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd", "META-INF/mule-httpn.xsd");

    return schemasMap;
}
项目:catberry-idea-plugin    文件:CatberryComponentUtils.java   
@NotNull
public static Map<String, PsiFile> findComponents(@NotNull final Project project) {
  Map<String, PsiFile> result = new HashMap<String, PsiFile>();
  Collection<VirtualFile> virtualFiles =
      FileBasedIndex.getInstance().getContainingFiles(FilenameIndex.NAME, CatberryConstants.CAT_COMPONENT_JSON,
          GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    JsonFile psiFile = (JsonFile) PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile != null) {
      JsonProperty[] properties = PsiTreeUtil.getChildrenOfType(psiFile.getTopLevelValue(), JsonProperty.class);
      if (properties != null) {
        for (JsonProperty property : properties) {
          if (!property.getName().equals("name"))
            continue;
          if (property.getValue() != null && property.getValue() instanceof JsonStringLiteral)
            result.put(((JsonStringLiteral) property.getValue()).getValue(), psiFile);
          break;
        }
      }
    }
  }
  return result;
}
项目:intellij-nette-tester    文件:TesterTestFinder.java   
@NotNull
@Override
public Collection<PsiElement> findTestsForClass(@NotNull PsiElement psiElement) {
    Collection<PsiElement> tests = new ArrayList<>();

    PhpClass phpClass = PsiTreeUtil.getStubOrPsiParentOfType(psiElement, PhpClass.class);
    if (phpClass != null) {
        Project project = phpClass.getProject();
        Collection<PhpClass> testClasses = PhpIndex.getInstance(project).getClassesByName(phpClass.getName() + "Test");
        if (!testClasses.isEmpty()) {
            tests.addAll(testClasses);
        }

        PsiFile[] files = FilenameIndex.getFilesByName(project, phpClass.getName() + ".phpt", GlobalSearchScope.projectScope(project));
        tests.addAll(Arrays.asList(files));
    }

    return tests;
}
项目:intellij-ce-playground    文件:PsiPatchBaseDirectoryDetector.java   
@Override
@Nullable
public Result detectBaseDirectory(final String patchFileName) {
  String[] nameComponents = patchFileName.split("/");
  String patchName = nameComponents[nameComponents.length - 1];
  if (patchName.isEmpty()) {
    return null;
  }
  final PsiFile[] psiFiles = FilenameIndex.getFilesByName(myProject, patchName, GlobalSearchScope.projectScope(myProject));
  if (psiFiles.length == 1) {
    PsiDirectory parent = psiFiles [0].getContainingDirectory();
    for(int i=nameComponents.length-2; i >= 0; i--) {
      if (!parent.getName().equals(nameComponents[i]) || Comparing.equal(parent.getVirtualFile(), myProject.getBaseDir())) {
        return new Result(parent.getVirtualFile().getPresentableUrl(), i+1);
      }
      parent = parent.getParentDirectory();
    }
    if (parent == null) return null;
    return new Result(parent.getVirtualFile().getPresentableUrl(), 0);
  }
  return null;
}
项目:intellij-ce-playground    文件:PsiViewerDialog.java   
@Nullable
private PsiFile getContainingFileForClass(String fqn) {
  String filename = fqn;
  if (fqn.contains(".")) {
    filename = fqn.substring(fqn.lastIndexOf('.') + 1);
  }
  if (filename.contains("$")) {
    filename = filename.substring(0, filename.indexOf('$'));
  }
  filename += ".java";
  final PsiFile[] files = FilenameIndex.getFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject));
  if (files != null && files.length > 0) {
    return files[0];
  }
  return null;
}
项目:intellij-ce-playground    文件:DefaultFileNavigationContributor.java   
@Override
@NotNull
public String[] getNames(Project project, boolean includeNonProjectItems) {
  if (FileBasedIndex.ourEnableTracingOfKeyHashToVirtualFileMapping) {
    final THashSet<String> names = new THashSet<String>(1000);
    IdFilter filter = IdFilter.getProjectIdFilter(project, includeNonProjectItems);
    processNames(new Processor<String>() {
      @Override
      public boolean process(String s) {
        names.add(s);
        return true;
      }
    }, FindSymbolParameters.searchScopeFor(project, includeNonProjectItems), filter);
    if (IdFilter.LOG.isDebugEnabled()) {
      IdFilter.LOG.debug("All names retrieved2:" + names.size());
    }
    return ArrayUtil.toStringArray(names);
  } else {
    return FilenameIndex.getAllFilenames(project);
  }
}
项目:intellij-ce-playground    文件:PythonReferenceImporter.java   
private static Collection<PsiElement> findImportableModules(PsiFile targetFile, String reftext, Project project, GlobalSearchScope scope) {
  List<PsiElement> result = new ArrayList<PsiElement>();
  PsiFile[] files = FilenameIndex.getFilesByName(project, reftext + ".py", scope);
  for (PsiFile file : files) {
    if (isImportableModule(targetFile, file)) {
      result.add(file);
    }
  }
  // perhaps the module is a directory, not a file
  PsiFile[] initFiles = FilenameIndex.getFilesByName(project, PyNames.INIT_DOT_PY, scope);
  for (PsiFile initFile : initFiles) {
    PsiDirectory parent = initFile.getParent();
    if (parent != null && parent.getName().equals(reftext)) {
      result.add(parent);
    }
  }
  return result;
}
项目:magento2plugin    文件:LayoutUtility.java   
public static List<XmlFile> getLayoutFiles(Project project, @Nullable String fileName) {
    List<XmlFile> results = new ArrayList<XmlFile>();
    Collection<VirtualFile> xmlFiles = FilenameIndex.getAllFilesByExt(project, "xml");

    PsiManager psiManager = PsiManager.getInstance(project);
    for (VirtualFile xmlFile: xmlFiles) {
        if (LayoutUtility.isLayoutFile(xmlFile)) {
            if (fileName != null && !xmlFile.getNameWithoutExtension().equals(fileName)) {
                continue;
            }

            PsiFile file = psiManager.findFile(xmlFile);
            if (file != null) {
                results.add((XmlFile)file);
            }
        }
    }

    return results;
}
项目:idea-php-oxid-plugin    文件:TranslationUtil.java   
public static Collection<PsiElement> getTranslationTargets(@NotNull Project project, final @NotNull String translationName) {

        final Collection<PsiElement> targets = new ArrayList<PsiElement>();

        for (VirtualFile virtualFile : FilenameIndex.getAllFilesByExt(project, "php", GlobalSearchScope.allScope(project))) {

            if (!isTranslationFile(virtualFile)) {
                continue;
            }

            PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
            if (file != null) {
                MetadataUtil.visitTranslationKey(file, new MetadataUtil.TranslationKeyVisitor() {
                    @Override
                    public void visit(@NotNull String name, @NotNull PsiElement value) {
                        if(name.equalsIgnoreCase(translationName)) {
                            targets.add(value);
                        }

                    }
                });
            }
        }

        return targets;
    }
项目:FindViewByMe    文件:Utils.java   
private static PsiFile resolveLayoutResourceFile(PsiElement element, Project project, String name) {
    // restricting the search to the current module - searching the whole project could return wrong layouts
    Module module = ModuleUtil.findModuleForPsiElement(element);
    PsiFile[] files = null;
    if (module != null) {
        GlobalSearchScope moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false);
        files = FilenameIndex.getFilesByName(project, name, moduleScope);
    }
    if (files == null || files.length <= 0) {
        // fallback to search through the whole project
        // useful when the project is not properly configured - when the resource directory is not configured
        files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
        if (files.length <= 0) {
            return null; //no matching files
        }
    }

    // TODO - we have a problem here - we still can have multiple layouts (some coming from a dependency)
    // we need to resolve R class properly and find the proper layout for the R class
    return files[0];
}
项目:intellij-ocaml    文件:OCamlResolvingUtil.java   
@Nullable
private static <T extends OCamlStructuredBinding> T findFileModuleByFileName(@NotNull final Project project,
                                                                             @NotNull final GlobalSearchScope scope,
                                                                             @NotNull final Class<T> type,
                                                                             @NotNull final String fileName) {
    final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {
        public PsiFile[] compute() {
            return FilenameIndex.getFilesByName(project, fileName, scope);
        }
    });

    for (final PsiFile file : files) {
        if (file instanceof OCamlFile) {
            final T moduleBinding = ((OCamlFile) file).getModuleBinding(type);
            if (moduleBinding != null) {
                return moduleBinding;
            }
        }
    }

    return null;
}
项目:idea-php-drupal-symfony2-bridge    文件:DrupalUtil.java   
@NotNull
public static Set<String> getModuleNames(@NotNull Project project) {
    Set<String> allFilesByExt = new HashSet<>();

    for (VirtualFile virtualFile : FilenameIndex.getAllFilesByExt(project, "yml")) {
        if(!virtualFile.getName().endsWith(".info.yml")) {
            continue;
        }

        allFilesByExt.add(StringUtils.stripEnd(virtualFile.getName(), ".info.yml"));
    }

    allFilesByExt.addAll(FilenameIndex.getAllFilesByExt(project, "module").stream()
        .map(virtualFile -> StringUtils.stripEnd(virtualFile.getName(), ".module"))
        .collect(Collectors.toList()));

    return allFilesByExt;
}
项目:idea-android-studio-plugin    文件:AndroidUtils.java   
@Nullable
public static PsiFile findXmlResource(@Nullable PsiReferenceExpression referenceExpression) {
    if (referenceExpression == null) return null;

    PsiElement firstChild = referenceExpression.getFirstChild();
    if (firstChild == null || !"R.layout".equals(firstChild.getText())) {
        return null;
    }

    PsiElement lastChild = referenceExpression.getLastChild();
    if(lastChild == null) {
        return null;
    }

    String name = String.format("%s.xml", lastChild.getText());
    PsiFile[] foundFiles = FilenameIndex.getFilesByName(referenceExpression.getProject(), name, GlobalSearchScope.allScope(referenceExpression.getProject()));
    if (foundFiles.length <= 0) {
        return null;
    }

    return foundFiles[0];
}
项目:idea-android-studio-plugin    文件:AndroidUtils.java   
public static List<PsiFile> getLayoutFiles(Project project) {

        List<PsiFile> psiFileList = new ArrayList<PsiFile>();

        for (VirtualFile virtualFile : FilenameIndex.getAllFilesByExt(project, "xml")) {
            VirtualFile parent = virtualFile.getParent();
            if (parent != null && "layout".equals(parent.getName())) {
                String relative = VfsUtil.getRelativePath(virtualFile, project.getBaseDir(), '/');
                if (relative != null) {
                    PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
                    if (psiFile != null) {
                        psiFileList.add(psiFile);
                    }
                }
            }
        }

        return psiFileList;
    }
项目:idea-android-studio-plugin    文件:AndroidUtils.java   
@Nullable
public static PsiFile findXmlResource(Project project, String layoutName) {

    if (!layoutName.startsWith("R.layout.")) {
        return null;
    }

    layoutName = layoutName.substring("R.layout.".length());

    String name = String.format("%s.xml", layoutName);
    PsiFile[] foundFiles = FilenameIndex.getFilesByName(project, name, GlobalSearchScope.allScope(project));
    if (foundFiles.length <= 0) {
        return null;
    }

    return foundFiles[0];
}
项目:android-viewbyid-generator    文件:Utils.java   
/**
 * Try to find layout XML file in selected element
 *
 * @param element
 * @return
 */
public static PsiFile findLayoutResource(PsiElement element) {
    if (element == null) {
        return null; // nothing to be used
    }
    if (!(element instanceof PsiIdentifier)) {
        return null; // nothing to be used
    }

    PsiElement layout = element.getParent().getFirstChild();
    if (layout == null) {
        return null; // no file to process
    }
    if (!"R.layout".equals(layout.getText())) {
        return null; // not layout file
    }

    Project project = element.getProject();
    String name = String.format("%s.xml", element.getText());
    PsiFile[] files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
    if (files.length <= 0) {
        return null; //no matching files
    }

    return files[0];
}
项目:tools-idea    文件:UniqueVFilePathBuilderImpl.java   
@NotNull
@Override
public String getUniqueVirtualFilePath(Project project, VirtualFile file) {
  final Collection<VirtualFile> filesWithSameName = FilenameIndex.getVirtualFilesByName(project, file.getName(),
                                                                                        ProjectScope.getProjectScope(project));
  if (filesWithSameName.size() > 1 && filesWithSameName.contains(file)) {
    String path = project.getBasePath();
    path = path == null ? "" : FileUtil.toSystemIndependentName(path);
    UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<VirtualFile>(path, File.separator, 25);
    for (VirtualFile virtualFile: filesWithSameName) {
      builder.addPath(virtualFile, virtualFile.getPath());
    }
    return builder.getShortPath(file);
  }
  return file.getName();
}
项目:tools-idea    文件:PsiPatchBaseDirectoryDetector.java   
@Override
@Nullable
public Result detectBaseDirectory(final String patchFileName) {
  String[] nameComponents = patchFileName.split("/");
  String patchName = nameComponents[nameComponents.length - 1];
  if (patchName.isEmpty()) {
    return null;
  }
  final PsiFile[] psiFiles = FilenameIndex.getFilesByName(myProject, patchName, GlobalSearchScope.projectScope(myProject));
  if (psiFiles.length == 1) {
    PsiDirectory parent = psiFiles [0].getContainingDirectory();
    for(int i=nameComponents.length-2; i >= 0; i--) {
      if (!parent.getName().equals(nameComponents[i]) || Comparing.equal(parent.getVirtualFile(), myProject.getBaseDir())) {
        return new Result(parent.getVirtualFile().getPresentableUrl(), i+1);
      }
      parent = parent.getParentDirectory();
    }
    if (parent == null) return null;
    return new Result(parent.getVirtualFile().getPresentableUrl(), 0);
  }
  return null;
}
项目:tools-idea    文件:PsiViewerDialog.java   
@Nullable
private PsiFile getContainingFileForClass(String fqn) {
  String filename = fqn;
  if (fqn.contains(".")) {
    filename = fqn.substring(fqn.lastIndexOf('.') + 1);
  }
  if (filename.contains("$")) {
    filename = filename.substring(0, filename.indexOf('$'));
  }
  filename += ".java";
  final PsiFile[] files = FilenameIndex.getFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject));
  if (files != null && files.length > 0) {
    return files[0];
  }
  return null;
}
项目:afinal-view-helper    文件:Utils.java   
/**
 * Try to find layout XML file in selected element
 *
 * @param element
 * @return
 */
public static PsiFile findLayoutResource(PsiElement element) {
    if (element == null) {
        return null; // nothing to be used
    }
    if (!(element instanceof PsiIdentifier)) {
        return null; // nothing to be used
    }

    PsiElement layout = element.getParent().getFirstChild();
    if (layout == null) {
        return null; // no file to process
    }
    if (!"R.layout".equals(layout.getText())) {
        return null; // not layout file
    }

    Project project = element.getProject();
    String name = String.format("%s.xml", element.getText());
    PsiFile[] files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
    if (files.length <= 0) {
        return null; //no matching files
    }

    return files[0];
}
项目:intellij-xquery    文件:XQueryModuleReferenceTest.java   
public void testRenameOfTheFileWithReference() {
    myFixture.configureByFiles("ModuleReference.xq", "ModuleReference_ReferencedModule.xq");
    PsiFile[] files = FilenameIndex.getFilesByName(myFixture.getProject(), "ModuleReference_ReferencedModule.xq",
            GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(myFixture.getProject()),
                    XQueryFileType
                            .INSTANCE));

    myFixture.renameElement(files[0], "ModuleReference_RenamedFile.xq");
    myFixture.checkResultByFile("ModuleReference.xq", "ModuleReferenceAfterRenameOfReferencedFile.xq", false);
    PsiFile[] filesAfterRename = FilenameIndex.getFilesByName(myFixture.getProject(),
            "ModuleReference_RenamedFile.xq",
            GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(myFixture.getProject()),
                    XQueryFileType
                            .INSTANCE));
    assertEquals(1, files.length);
    assertNotNull(filesAfterRename[0]);
}
项目:needsmoredojo    文件:DojoModuleFileResolver.java   
/**
 * gets a list of all files that are part of your dojo project sources.
 * only retrieves javascript files
 *
 * @param project
 * @return
 */
public Collection<VirtualFile> getAllDojoProjectSourceFiles(Project project)
{
    VirtualFile[] sourceDirectories = SourcesLocator.getProjectSourceDirectories(project, true);
    List<VirtualFile> files = new ArrayList<VirtualFile>();
    for(VirtualFile file : sourceDirectories)
    {
        files.add(file);
    }

    Set<VirtualFile> psiFiles = new HashSet<VirtualFile>();
    Collection<VirtualFile> results = FilenameIndex.getAllFilesByExt(project, "js", GlobalSearchScope.projectScope(project));
    for(VirtualFile result : results)
    {
        for(VirtualFile directory : sourceDirectories)
        {
            if(VfsUtilCore.isAncestor(directory, result, false))
            {
                psiFiles.add(result);
                continue;
            }
        }
    }

    return results;
}
项目:needsmoredojo    文件:DojoModuleFileResolver.java   
public Set<String> getDirectoriesForDojoModules(Project project, Set<String> modules)
{
    Set<String> possibleDirectories = new HashSet<String>();

    for(String module : modules)
    {
        String moduleParent = module;

        if(module.contains("/"))
        {
            module = module.substring(module.lastIndexOf("/") + 1);
        }

        PsiFile[] files = FilenameIndex.getFilesByName(project, module + ".js", GlobalSearchScope.projectScope(project));

        for(PsiFile file : files)
        {
            if( file.getVirtualFile().getCanonicalPath().contains(moduleParent))
            {
                possibleDirectories.add(file.getParent().getParent().getName() +  " (" + file.getParent().getParent().getVirtualFile().getCanonicalPath() + ")");
            }
        }
    }

    return possibleDirectories;
}
项目:consulo    文件:PsiPatchBaseDirectoryDetector.java   
@Override
@Nullable
public Result detectBaseDirectory(final String patchFileName) {
  String[] nameComponents = patchFileName.split("/");
  String patchName = nameComponents[nameComponents.length - 1];
  if (patchName.isEmpty()) {
    return null;
  }
  final PsiFile[] psiFiles = FilenameIndex.getFilesByName(myProject, patchName, GlobalSearchScope.projectScope(myProject));
  if (psiFiles.length == 1) {
    PsiDirectory parent = psiFiles [0].getContainingDirectory();
    for(int i=nameComponents.length-2; i >= 0; i--) {
      if (!parent.getName().equals(nameComponents[i]) || Comparing.equal(parent.getVirtualFile(), myProject.getBaseDir())) {
        return new Result(parent.getVirtualFile().getPresentableUrl(), i+1);
      }
      parent = parent.getParentDirectory();
    }
    if (parent == null) return null;
    return new Result(parent.getVirtualFile().getPresentableUrl(), 0);
  }
  return null;
}
项目:consulo    文件:PsiViewerDialog.java   
@Nullable
private PsiFile getContainingFileForClass(String fqn) {
  String filename = fqn;
  if (fqn.contains(".")) {
    filename = fqn.substring(fqn.lastIndexOf('.') + 1);
  }
  if (filename.contains("$")) {
    filename = filename.substring(0, filename.indexOf('$'));
  }
  filename += ".java";
  final PsiFile[] files = FilenameIndex.getFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject));
  if (files != null && files.length > 0) {
    return files[0];
  }
  return null;
}
项目:consulo    文件:DefaultFileNavigationContributor.java   
@Override
@Nonnull
public String[] getNames(Project project, boolean includeNonProjectItems) {
  if (FileBasedIndex.ourEnableTracingOfKeyHashToVirtualFileMapping) {
    final THashSet<String> names = new THashSet<String>(1000);
    IdFilter filter = IdFilter.getProjectIdFilter(project, includeNonProjectItems);
    processNames(new Processor<String>() {
      @Override
      public boolean process(String s) {
        names.add(s);
        return true;
      }
    }, FindSymbolParameters.searchScopeFor(project, includeNonProjectItems), filter);
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("All names retrieved2:" + names.size());
    }
    return ArrayUtil.toStringArray(names);
  } else {
    return FilenameIndex.getAllFilenames(project);
  }
}
项目:consulo-javascript    文件:JavaScriptSymbolContributor.java   
@NotNull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems)
{
    final Set<String> result = new HashSet<String>();

    result.addAll(StubIndex.getInstance().getAllKeys(JavaScriptIndexKeys.ELEMENTS_BY_NAME, project));

    FileBasedIndex.getInstance().processAllKeys(FilenameIndex.NAME, new Processor<String>()
    {
        @Override
        public boolean process(String s)
        {
            if(JavaScriptSupportLoader.isFlexMxmFile(s))
            {
                result.add(FileUtil.getNameWithoutExtension(s));
            }
            return true;
        }
    }, project);
    return result.toArray(new String[result.size()]);
}
项目:consulo-java    文件:ModuleHighlightUtil.java   
@Nullable
static HighlightInfo checkFileDuplicates(@NotNull PsiJavaModule element, @NotNull PsiFile file)
{
    Module module = findModule(file);
    if(module != null)
    {
        Project project = file.getProject();
        Collection<VirtualFile> others = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope());
        if(others.size() > 1)
        {
            String message = JavaErrorMessages.message("module.file.duplicate");
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).descriptionAndTooltip(message).create();
            others.stream().map(f -> PsiManager.getInstance(project).findFile(f)).filter(f -> f != file).findFirst().ifPresent(duplicate -> QuickFixAction.registerQuickFixAction(info, new
                    GoToSymbolFix(duplicate, JavaErrorMessages.message("module.open.duplicate.text"))));
            return info;
        }
    }

    return null;
}
项目:reasonml-idea-plugin    文件:RmlPsiUtil.java   
@NotNull
public static List<PsiModule> findModules(@NotNull Project project) {
    ArrayList<PsiModule> result = new ArrayList<>();

    Collection<VirtualFile> virtualFiles = FilenameIndex.getAllFilesByExt(project, RmlFileType.INSTANCE.getDefaultExtension());
    for (VirtualFile virtualFile : virtualFiles) {
        PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
        PsiModule[] modules = PsiTreeUtil.getChildrenOfType(file, PsiModule.class);
        if (modules != null) {
            result.addAll(Arrays.asList(modules));
        }
    }

    return result;
}
项目:catberry-idea-plugin    文件:CatberryAttributeDescriptor.java   
@Override
public String[] getEnumeratedValues() {
  CatberryProjectConfigurationManager configurationManager = CatberryProjectConfigurationManager.getInstance(project);
  if(!configurationManager.isCatberryEnabled())
    return ArrayUtil.EMPTY_STRING_ARRAY;

  PsiDirectory storesDirectory = configurationManager.getStoresDirectory();
  if(storesDirectory == null)
    return ArrayUtil.EMPTY_STRING_ARRAY;

  final String storesPath = storesDirectory.getVirtualFile().getPath();

  GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
  Collection<VirtualFile> virtualFiles = FilenameIndex.getAllFilesByExt(project, "js", scope);
  List<String> keys = new LinkedList<String>();
  PsiManager psiManager = PsiManager.getInstance(project);
  for(VirtualFile virtualFile : virtualFiles) {
    if(!virtualFile.getPath().startsWith(storesPath))
      continue;
    String prefix = virtualFile.getPath().substring(storesPath.length(), virtualFile.getPath().lastIndexOf("/"));
    if(prefix.startsWith("/"))
      prefix = prefix.substring(1);
    if(prefix.length() != 0)
      prefix += "/";
    PsiFile psiFile = psiManager.findFile(virtualFile);
    if(psiFile == null)
      continue;
    for(JSClass jsClass: PsiTreeUtil.findChildrenOfType(psiFile, JSClass.class)) {
      keys.add(prefix+jsClass.getName());
    }
  }
  return keys.toArray(new String[keys.size()]);
}
项目:catberry-idea-plugin    文件:CatberryComponentUtils.java   
@Nullable
public static PsiFile findComponentTemplate(@NotNull final Project project, @NotNull String name) {
  Collection<VirtualFile> virtualFiles =
      FileBasedIndex.getInstance().getContainingFiles(FilenameIndex.NAME, CatberryConstants.CAT_COMPONENT_JSON,
          GlobalSearchScope.allScope(project));
  CatberryProjectConfigurationManager manager = CatberryProjectConfigurationManager.getInstance(project);
  final TemplateEngine engine = manager.getTemplateEngine();
  if(engine == null)
    return null;
  for (VirtualFile virtualFile : virtualFiles) {
    JsonFile psiFile = (JsonFile) PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile != null) {
      JsonStringLiteralImpl value = ObjectUtils.tryCast(JsonPsiUtil.findPropertyValue(
          psiFile.getTopLevelValue(), "name"), JsonStringLiteralImpl.class);
      if (value == null || !name.equals(value.getValue()))
        continue;

      String template = "./" + CatberryConstants.DEFAULT_TEMPLATE_PREFIX + engine.getExtension();
      value = ObjectUtils.tryCast(JsonPsiUtil.findPropertyValue(
          psiFile.getTopLevelValue(), "template"), JsonStringLiteralImpl.class);
      if (value != null)
        template = value.getValue();

      VirtualFile f = psiFile.getVirtualFile().getParent();
      f = f.findFileByRelativePath(template);
      return f != null ? PsiManager.getInstance(project).findFile(f) : null;
    }
  }
  return null;
}
项目:appetizer-intellij    文件:ProjectAll.java   
public static Map<Project, Collection<VirtualFile>> setFoundFilesInAllProjects(String filename, boolean isId) {
  Map<Project, Collection<VirtualFile>> foundFilesInAllProjects = new HashMap<Project, Collection<VirtualFile>>();
  Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    if (isId) {
      foundFilesInAllProjects.put(project, FilenameIndex.getVirtualFilesByName(project, new File(androidManifestName).getName(), GlobalSearchScope.allScope(project)));
    } else {
      foundFilesInAllProjects.put(project, FilenameIndex.getVirtualFilesByName(project, new File(filename).getName(), GlobalSearchScope.allScope(project)));
    }
  }
  return foundFilesInAllProjects;
}