com.intellij.psi.search.GlobalSearchScope Java Examples

The following examples show how to use com.intellij.psi.search.GlobalSearchScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoveUnusedParameterFix.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
private static List<SoyParamSpecificationIdentifier> getReferencingParamSpecificationIdentifiers(
    SoyParamDefinitionIdentifier paramDefinitionIdentifier) {
  Project project = paramDefinitionIdentifier.getProject();
  final ImmutableList.Builder<SoyParamSpecificationIdentifier> result = ImmutableList.builder();
  Collection<VirtualFile> virtualFiles =
      FileTypeIndex.getFiles(SoyFileType.INSTANCE, GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    SoyFile soyFile = (SoyFile) PsiManager.getInstance(project).findFile(virtualFile);
    if (soyFile != null) {
      soyFile.accept(new SoyRecursiveElementVisitor() {
        @Override
        public void visitParamSpecificationIdentifier(
            @NotNull SoyParamSpecificationIdentifier identifier) {
          super.visitParamSpecificationIdentifier(identifier);
          PsiReference reference = identifier.getReference();
          if (reference != null && paramDefinitionIdentifier.equals(reference.resolve())) {
            result.add(identifier);
          }
        }
      });
    }
  }
  return result.build();
}
 
Example #2
Source File: DojoModuleFileResolver.java    From needsmoredojo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: ThriftDeclarationIndex.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
public static List<String> findAllKeys(Project project, GlobalSearchScope scope) {
  final List<String> result = new ArrayList<String>();
  FileBasedIndex.getInstance().processAllKeys(
    THRIFT_DECLARATION_INDEX,
    new Processor<String>() {
      @Override
      public boolean process(String name) {
        result.add(name);
        return true;
      }
    },
    scope,
    null
  );
  return result;
}
 
Example #4
Source File: TableUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public static PsiElement[] getTableDefinitionElements(@NotNull String tableName, @NotNull Project project) {

        PsiFile[] extTablesSqlFilesInProjectContainingTable = getExtTablesSqlFilesInProjectContainingTable(tableName, project);
        Set<PsiElement> elements = new HashSet<>();

        PsiManager psiManager = PsiManager.getInstance(project);

        for (PsiFile virtualFile : extTablesSqlFilesInProjectContainingTable) {
            FileBasedIndex.getInstance().processValues(TablenameFileIndex.KEY, tableName, virtualFile.getVirtualFile(), (file, value) -> {

                PsiFile file1 = psiManager.findFile(file);
                if (file1 != null) {
                    PsiElement elementAt = file1.findElementAt(value.getEndOffset() - 2);
                    if (elementAt != null) {
                        elements.add(elementAt);
                    }
                }

                return true;
            }, GlobalSearchScope.allScope(project));
        }

        return elements.toArray(new PsiElement[0]);
    }
 
Example #5
Source File: FileModuleIndexService.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
Collection<IndexedFileModule> getFilesForNamespace(@NotNull String namespace, @NotNull GlobalSearchScope scope) {
    Collection<IndexedFileModule> result = new ArrayList<>();

    FileBasedIndex fileIndex = FileBasedIndex.getInstance();

    if (scope.getProject() != null) {
        for (String key : fileIndex.getAllKeys(m_index.getName(), scope.getProject())) {
            List<FileModuleData> values = fileIndex.getValues(m_index.getName(), key, scope);
            int valuesSize = values.size();
            if (valuesSize > 2) {
                System.out.println("ERROR, size of " + key + " is " + valuesSize);
            } else {
                for (FileModuleData value : values) {
                    if (valuesSize == 1 || value.isInterface()) {
                        if (namespace.equals(value.getNamespace())) {
                            result.add(value);
                        }
                    }
                }
            }
        }
    }

    return result;
}
 
Example #6
Source File: BlazePythonTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static List<Location> findTestMethod(
    Project project, GlobalSearchScope scope, String className, @Nullable String methodName) {
  List<Location> results = new ArrayList<>();
  if (methodName == null) {
    return findTestClass(project, scope, className);
  }
  for (PyClass pyClass : PyClassNameIndex.find(className, project, scope)) {
    ProgressManager.checkCanceled();
    if (PyTestUtils.isTestClass(pyClass)) {
      PyFunction method = findMethod(pyClass, methodName);
      if (method != null && PyTestUtils.isTestFunction(method)) {
        results.add(new PsiLocation<>(project, method));
      }
      results.add(new PsiLocation<>(project, pyClass));
    }
  }
  return results;
}
 
Example #7
Source File: ControllerActionUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public static PsiElement[] getDefinitionElements(@NotNull Project project, @NotNull String actionName) {
    Set<String> keys = new HashSet<>();
    keys.add(actionName);

    List<PsiElement> elements = new ArrayList<>();
    FileBasedIndex.getInstance().getFilesWithKey(ControllerActionIndex.KEY, keys, virtualFile -> {
        FileBasedIndex.getInstance().processValues(ControllerActionIndex.KEY, actionName, virtualFile, (file, value) -> {
            PsiFile file1 = PsiManager.getInstance(project).findFile(file);
            if (file1 != null) {
                PsiElement elementAt = file1.findElementAt(value.getTextRange().getStartOffset());
                if (elementAt != null) {
                    elements.add(elementAt.getParent().getParent());
                }
            }

            return true;
        }, GlobalSearchScope.allScope(project));

        return true;
    }, GlobalSearchScope.allScope(project));

    return elements.toArray(new PsiElement[0]);
}
 
Example #8
Source File: HaskellReference.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
private @NotNull List<PsiElementResolveResult> handleImportReferences(@NotNull HaskellImpdecl haskellImpdecl,
                                                                      @NotNull PsiNamedElement myElement, int i) {
    /**
     * Don't use the named element yet to determine which element we're
     * talking about, not necessary yet
     */
    List<PsiElementResolveResult> modulesFound = new ArrayList<PsiElementResolveResult>();
    List<HaskellQconid> qconidList = haskellImpdecl.getQconidList();
    if (qconidList.size() > 0){
        String moduleName = qconidList.get(0).getText();

        GlobalSearchScope globalSearchScope = GlobalSearchScope.projectScope(myElement.getProject());
        List<HaskellFile> filesByModuleName = HaskellModuleIndex.getFilesByModuleName(myElement.getProject(), moduleName, globalSearchScope);
        for (HaskellFile haskellFile : filesByModuleName) {
            HaskellModuledecl[] moduleDecls = PsiTreeUtil.getChildrenOfType(haskellFile, HaskellModuledecl.class);
            if (moduleDecls != null && moduleDecls.length > 0){
                HaskellQconid qconid = moduleDecls[0].getQconid();
                if (qconid != null) {
                    List<HaskellConid> conidList = moduleDecls[0].getQconid().getConidList();
                    modulesFound.add(new PsiElementResolveResult(conidList.get(i)));
                }
            }
        }
    }
    return modulesFound;
}
 
Example #9
Source File: RouteHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public static Collection<Route> getRoute(@NotNull Project project, @NotNull String routeName) {
    Map<String, Route> compiledRoutes = RouteHelper.getCompiledRoutes(project);
    if(compiledRoutes.containsKey(routeName)) {
        return Collections.singletonList(compiledRoutes.get(routeName));
    }

    Collection<Route> routes = new ArrayList<>();

    Collection<VirtualFile> routeFiles = FileBasedIndex.getInstance().getContainingFiles(RoutesStubIndex.KEY, routeName, GlobalSearchScope.allScope(project));
    for(StubIndexedRoute route: FileBasedIndex.getInstance().getValues(RoutesStubIndex.KEY, routeName, GlobalSearchScope.filesScope(project, routeFiles))) {
        routes.add(new Route(route));
    }

    return routes;
}
 
Example #10
Source File: BlazePythonTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public List<Location> getLocation(
    String protocol, String path, Project project, GlobalSearchScope scope) {
  if (protocol.equals(SmRunnerUtils.GENERIC_SUITE_PROTOCOL)) {
    return findTestClass(project, scope, path);
  }
  if (protocol.equals(SmRunnerUtils.GENERIC_TEST_PROTOCOL)) {
    path = StringUtil.trimStart(path, PY_TESTCASE_PREFIX);
    String[] components = path.split("\\.|::");
    if (components.length < 2) {
      return ImmutableList.of();
    }
    return findTestMethod(
        project, scope, components[components.length - 2], components[components.length - 1]);
  }
  return ImmutableList.of();
}
 
Example #11
Source File: ExtractSuperBaseProcessor.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@NotNull
protected UsageInfo[] findUsages() {
  PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]);
  final ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();
  detectTurnToSuperRefs(refs, result);
  final PsiPackage originalPackage = JavaDirectoryService.getInstance().getPackage(myClass.getContainingFile().getContainingDirectory());
  if (Comparing.equal(JavaDirectoryService.getInstance().getPackage(myTargetDirectory), originalPackage)) {
    result.clear();
  }
  for (final PsiReference ref : refs) {
    final PsiElement element = ref.getElement();
    if (!canTurnToSuper(element) && !RefactoringUtil.inImportStatement(ref, element)) {
      result.add(new BindToOldUsageInfo(element, ref, myClass));
    }
  }
  UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
  return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
 
Example #12
Source File: ResourceFileUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static VirtualFile findResourceFileInScope(final String resourceName,
                                                  final Project project,
                                                  final GlobalSearchScope scope) {
  int index = resourceName.lastIndexOf('/');
  String packageName = index >= 0 ? resourceName.substring(0, index).replace('/', '.') : "";
  final String fileName = index >= 0 ? resourceName.substring(index+1) : resourceName;
  Query<VirtualFile> directoriesByPackageName = DirectoryIndex.getInstance(project).getDirectoriesByPackageName(packageName, true);
  for (VirtualFile virtualFile : directoriesByPackageName) {
    final VirtualFile child = virtualFile.findChild(fileName);
    if(child != null && scope.contains(child)) {
      return child;
    }
  }
  return null;
}
 
Example #13
Source File: FileIndexCaches.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @param dataHolderKey Main data to cache
 * @param dataHolderNames Cache extracted name Set
 */
static public synchronized <T> Map<String, List<T>> getSetDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<T>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, T> ID, @NotNull final GlobalSearchScope scope) {
    return CachedValuesManager.getManager(project).getCachedValue(
        project,
        dataHolderKey,
        () -> {
            Map<String, List<T>> items = new HashMap<>();

            final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

            getIndexKeysCache(project, dataHolderNames, ID).forEach(service ->
                items.put(service, fileBasedIndex.getValues(ID, service, scope))
            );

            return CachedValueProvider.Result.create(items, getModificationTrackerForIndexId(project, ID));
        },
        false
    );
}
 
Example #14
Source File: AnnotationUtil.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@NotNull
private static Collection<PsiFile> getFilesImplementingAnnotation(@NotNull Project project, @NotNull String phpClassName) {
    Collection<VirtualFile> files = new HashSet<>();

    FileBasedIndex.getInstance().getFilesWithKey(AnnotationUsageIndex.KEY, new HashSet<>(Collections.singletonList(phpClassName)), virtualFile -> {
        files.add(virtualFile);
        return true;
    }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), PhpFileType.INSTANCE));

    Collection<PsiFile> elements = new ArrayList<>();

    for (VirtualFile file : files) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(file);

        if(psiFile == null) {
            continue;
        }

        elements.add(psiFile);
    }

    return elements;
}
 
Example #15
Source File: EnvironmentVariablesApi.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
/**
 * @param project project
 * @param key     environment variable key
 * @return All key usages, like getenv('KEY')
 */
@NotNull
public static PsiElement[] getKeyUsages(Project project, String key) {
    List<PsiElement> targets = new ArrayList<>();

    PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project);

    Processor<PsiFile> psiFileProcessor = psiFile -> {
        for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) {
            targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile)));
        }

        return true;
    };

    searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true);
    searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor);

    return targets.toArray(PsiElement.EMPTY_ARRAY);
}
 
Example #16
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
    List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
    for (T t : values) {
        if(tAssert.match(t)) {
            return;
        }
    }

    fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size()));
}
 
Example #17
Source File: PsiFinder.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Nullable
public PsiException findException(@Nullable String qname, ORFileType fileType, @NotNull GlobalSearchScope scope) {
    if (qname == null) {
        return null;
    }

    Collection<PsiException> items = ExceptionFqnIndex.getInstance().get(qname.hashCode(), m_project, scope);
    if (items.isEmpty()) {
        return null;
    }

    if (items.size() == 1) {
        return items.iterator().next();
    }

    if (items.size() == 2) {
        boolean useInterface = fileType == ORFileType.interfaceOrImplementation || fileType == ORFileType.interfaceOnly;
        Iterator<PsiException> itException = items.iterator();
        PsiException first = itException.next();
        boolean isInterface = FileHelper.isInterface(first.getContainingFile().getFileType());
        if ((useInterface && isInterface) || (!useInterface && !isInterface)) {
            return first;
        }
        return itException.next();
    }

    LOG.debug("Incorrect size for retrieved exception items", items);
    return null;
}
 
Example #18
Source File: NutzLineUtil.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
/**
 * 取得文件
 *
 * @param bindingElement
 * @return
 */
public static List<VirtualFile> findTemplteFileList(PsiElement bindingElement) {
    JavaNutzTemplateVO nutzTemplate = getTemplateFilePathAndName(bindingElement);
    List<VirtualFile> fileList = new ArrayList<>();
    String[] exts = nutzTemplate.getFileExtension().split(";");
    for (String ext : exts) {
        if (ext.trim() != "") {
            //优化定位至当前Module 跨模块资源无法取得还是返回
            //GlobalSearchScope globalSearchScope = ((ModuleWithDependenciesScope) bindingElement.getResolveScope()).getModule().getModuleScope();
            Collection<VirtualFile> tempVirtualFiles = FilenameIndex.getAllFilesByExt(bindingElement.getProject(), ext.replaceAll("\\.", ""), GlobalSearchScope.projectScope(bindingElement.getProject()));
            if (tempVirtualFiles != null && tempVirtualFiles.size() > 0) {
                String tempNutzFileName = nutzTemplate.getTemplatePath();
                //兼容绝对路径模式
                if (tempNutzFileName.endsWith(ext) && tempNutzFileName.indexOf("/") > -1) {
                    tempNutzFileName = tempNutzFileName.substring(0, tempNutzFileName.length() - ext.length());
                }
                //去除前缀
                tempNutzFileName = tempNutzFileName.substring(nutzTemplate.getName().length());
                //补上文件后缀
                tempNutzFileName = tempNutzFileName.replace(".", "/") + ext;
                String finalTempNutzFileName = tempNutzFileName;
                tempVirtualFiles.stream().filter(virtualFile -> virtualFile.getCanonicalPath().endsWith(finalTempNutzFileName))
                        .forEach(virtualFile -> fileList.add(virtualFile));
            }
        }
    }
    return fileList;
}
 
Example #19
Source File: ORFileUtilsTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    initMocks(this);
    mockStatic(ID.class);
    mockStatic(EsyPackageJson.class);
    mockStatic(FilenameIndex.class);
    mockStatic(GlobalSearchScope.class);
    when(GlobalSearchScope.allScope(mockProject)).thenReturn(mockScope);
}
 
Example #20
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
protected PsiClass findClassAndAssert(@NonNls @NotNull String qualifiedName) {
  final PsiClass[] classes = JavaPsiFacade.getInstance(myProject).findClasses(qualifiedName, GlobalSearchScope.allScope(myProject));
  Set<PsiClass> deduppedClasses = Stream.of(classes).collect(Collectors.toSet());
  assertTrue("Several classes with the same qualified name " + qualifiedName, deduppedClasses.size() < 2);
  assertFalse(qualifiedName + " class not found!", deduppedClasses.isEmpty());
  return deduppedClasses.iterator().next();
}
 
Example #21
Source File: SymfonyProcessors.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public Set<String> getResult() {
    return stringSet.stream()
        .filter(
            s -> FileBasedIndex.getInstance().getContainingFiles(id, s, GlobalSearchScope.allScope(project)).size() > 0)
        .collect(Collectors.toSet()
    );
}
 
Example #22
Source File: PolygeneConcernUtil.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param searchContext Search context.
 * @return {@code GenericConcern} psi class if found, {@code null} otherwise.
 * @since 0.1
 */
@Nullable
public static PsiClass getGenericConcernClass( @NotNull PsiElement searchContext )
{
    Project project = searchContext.getProject();
    GlobalSearchScope searchScope = determineSearchScope( searchContext );
    return getGenericConcernClass( project, searchScope );
}
 
Example #23
Source File: IncludeVariableCollector.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private Collection<VirtualFile> getImplements(TwigFile twigFile) {
    final Set<VirtualFile> targets = new HashSet<>();

    for(String templateName: TwigUtil.getTemplateNamesForFile(twigFile)) {
        FileBasedIndex.getInstance().getFilesWithKey(TwigIncludeStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> {
            targets.add(virtualFile);
            return true;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(twigFile.getProject()), TwigFileType.INSTANCE));
    }

    return targets;
}
 
Example #24
Source File: SubscriberMetadata.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public PsiMethod getBusPostMethod(Project project) {
  JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
  GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project);

  PsiClass busClass = javaPsiFacade.findClass(getBusClassName(), globalSearchScope);
  if (busClass != null) {
    for (PsiMethod psiMethod : busClass.getMethods()) {
      if (psiMethod.getName().equals("post")) {
        return psiMethod;
      }
    }
  }
  return null;
}
 
Example #25
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all {@link SQFCommand} instances in the current module that is equal to findCommand into a list and returns it
 *
 * @param project     project
 * @param findCommand the command
 * @return list
 */
@NotNull
public static List<SQFCommand> findAllCommandInstances(@NotNull Project project, @NotNull SQFCommand findCommand) {
	List<SQFCommand> result = new ArrayList<>();
	Module m = ModuleUtil.findModuleForPsiElement(findCommand);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFCommand) {
				SQFCommand command = (SQFCommand) nodeAsElement;
				if (command.commandNameEquals(findCommand.getCommandName())) {
					result.add(command);
				}
			}
			return false;
		});
	}
	return result;
}
 
Example #26
Source File: LogConsoleImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LogConsoleImpl(Project project,
                      @Nonnull File file,
                      @Nonnull Charset charset,
                      long skippedContents,
                      String title,
                      final boolean buildInActions,
                      final GlobalSearchScope searchScope) {
  super(project, getReader(file, charset, skippedContents), title, buildInActions, new DefaultLogFilterModel(project),
        searchScope);
  myPath = file.getAbsolutePath();
  myFile = file;
  myCharset = charset;
}
 
Example #27
Source File: FileIncludeIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static MultiMap<VirtualFile, FileIncludeInfoImpl> getIncludingFileCandidates(String fileName, @Nonnull GlobalSearchScope scope) {
  final MultiMap<VirtualFile, FileIncludeInfoImpl> result = new MultiMap<>();
  FileBasedIndex.getInstance().processValues(INDEX_ID, fileName, null, (file, value) -> {
    result.put(file, value);
    return true;
  }, scope);
  return result;
}
 
Example #28
Source File: DeprecationUtility.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static Set<String> getDeprecatedClassConstants(@NotNull Project project) {
    Set<String> constants = new HashSet<>();
    PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(project, "ClassConstantMatcher.php", GlobalSearchScope.allScope(project));
    for (PsiFile file : classConstantMatcherFiles) {
        constants.addAll(CachedValuesManager.getManager(project).getCachedValue(
            file,
            DEPRECATED_CLASS_CONSTANTS,
            () -> CachedValueProvider.Result.create(getDeprecatedClassConstantsFromFile(file), PsiModificationTracker.MODIFICATION_COUNT),
            false
        ));
    }

    return constants;
}
 
Example #29
Source File: FilesIndexCacheProjectComponent.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Finds {@link VirtualFile} instances for the specific {@link Pattern} and caches them.
 *
 * @param project current project
 * @param pattern to handle
 * @return matched files list
 */
@NotNull
public Collection<VirtualFile> getFilesForPattern(@NotNull final Project project, @NotNull Pattern pattern) {
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    final String[] parts = MatcherUtil.getParts(pattern);

    if (parts.length > 0) {
        final String key = StringUtil.join(parts, Constants.DOLLAR);
        if (cacheMap.get(key) == null) {
            final THashSet<VirtualFile> files = new THashSet<>(1000);

            projectFileIndex.iterateContent(fileOrDir -> {
                final String name = fileOrDir.getName();
                if (MatcherUtil.matchAnyPart(parts, name)) {
                    for (VirtualFile file : FilenameIndex.getVirtualFilesByName(project, name, scope)) {
                        if (file.isValid() && MatcherUtil.matchAllParts(parts, file.getPath())) {
                            files.add(file);
                        }
                    }
                }
                return true;
            });

            cacheMap.put(key, files);
        }

        return cacheMap.get(key);
    }

    return new ArrayList<>();
}
 
Example #30
Source File: TwigTranslationKeyIntention.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private boolean isDomainAndKeyInPsi(@NotNull PsiFile psiFile, @NotNull String key, @NotNull String domain) {
    List<Set<String>> values = FileBasedIndex.getInstance()
        .getValues(TranslationStubIndex.KEY, domain, GlobalSearchScope.fileScope(psiFile));

    for (Set<String> value : values) {
        if(value.contains(key)) {
            return true;
        }
    }

    return false;
}