@Override public Set<TSVarExpr> generate(Project project) { Set<TSVarExpr> items = new HashSet<>(); //Search every file in the project Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, TSFileType.INSTANCE, GlobalSearchScope.projectScope(project)); for (VirtualFile virtualFile : virtualFiles) { TSFile tsFile = (TSFile) PsiManager.getInstance(project).findFile(virtualFile); if (tsFile != null) { Collection<TSAssignExpr> assignments = PsiTreeUtil.findChildrenOfType(tsFile, TSAssignExpr.class); for (TSAssignExpr assignment : assignments) { PsiElement first = assignment.getFirstChild(); if (!(first instanceof TSVarExpr)) continue; if (((TSVarExpr)first).isLocal()) continue; items.add((TSVarExpr) first); } } ProgressManager.progress("Loading Symbols"); } return items; }
@NotNull private static PsiElement[] getTargetMethods(@NotNull Project project, @NotNull String routeName) { List<PsiElement> result = new ArrayList<>(); List<RouteStub> values = FileBasedIndex.getInstance().getValues(RouteIndex.KEY, routeName, GlobalSearchScope.allScope(project)); PhpIndex phpIndex = PhpIndex.getInstance(project); for (RouteStub routeStub : values) { String fqn = routeStub.getController(); Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(fqn); classesByFQN.forEach(c -> { if (c.findMethodByName(routeStub.getMethod()) != null) { result.add(c.findMethodByName(routeStub.getMethod())); } }); } return result.toArray(new PsiElement[result.size()]); }
@Override public void projectOpened() { TYPO3CMSSettings instance = TYPO3CMSSettings.getInstance(project); IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.cedricziel.idea.typo3")); if (plugin == null) { return; } String version = instance.getVersion(); if (version == null || !plugin.getVersion().equals(version)) { instance.setVersion(plugin.getVersion()); FileBasedIndex index = FileBasedIndex.getInstance(); index.scheduleRebuild(CoreServiceMapStubIndex.KEY, new Throwable()); index.scheduleRebuild(ExtensionNameStubIndex.KEY, new Throwable()); index.scheduleRebuild(IconIndex.KEY, new Throwable()); index.scheduleRebuild(ResourcePathIndex.KEY, new Throwable()); index.scheduleRebuild(RouteIndex.KEY, new Throwable()); index.scheduleRebuild(TablenameFileIndex.KEY, new Throwable()); index.scheduleRebuild(LegacyClassesForIDEIndex.KEY, new Throwable()); index.scheduleRebuild(MethodArgumentDroppedIndex.KEY, new Throwable()); index.scheduleRebuild(ControllerActionIndex.KEY, new Throwable()); } }
public static PsiElement[] findDefinitionElements(@NotNull Project project, @NotNull String translationId) { Set<String> keys = new HashSet<>(); keys.add(translationId); List<PsiElement> elements = new ArrayList<>(); FileBasedIndex.getInstance().getFilesWithKey(TranslationIndex.KEY, keys, virtualFile -> { FileBasedIndex.getInstance().processValues(TranslationIndex.KEY, translationId, 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()); } } return true; }, GlobalSearchScope.allScope(project)); return true; }, GlobalSearchScope.allScope(project)); return elements.toArray(new PsiElement[elements.size()]); }
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[elements.size()]); }
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[elements.size()]); }
private void collectServices(Project project) { FileBasedIndex index = FileBasedIndex.getInstance(); Collection<VirtualFile> containingFiles = index.getContainingFiles( FileTypeIndex.NAME, PhpFileType.INSTANCE, GlobalSearchScope.allScope(project) ); containingFiles.removeIf(virtualFile -> !(virtualFile.getName().contains("ext_localconf.php"))); for (VirtualFile projectFile : containingFiles) { PsiFile psiFile = PsiManager.getInstance(project).findFile(projectFile); if (psiFile != null) { psiFile.accept(new CoreServiceDefinitionParserVisitor(serviceMap)); } } }
public static List<GCMTypeDeclaration> findProperties(Project project) { final List<GCMTypeDeclaration> result = new ArrayList<GCMTypeDeclaration>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, GCMLanguageType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { GCMFile simpleFile = (GCMFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { simpleFile.acceptChildren(new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if (element instanceof GCMDeclaration) { GCMDeclaration declaration = (GCMDeclaration) element; if (declaration.getClassDeclaration() != null) { result.add(declaration.getClassDeclaration().getTypeDeclaration()); } if (declaration.getCustomTypeDeclaration() != null) { //result.add(declaration.getCustomTypeDeclaration().getTypeDeclaration()); } } super.visitElement(element); } }); } } return result; }
public Collection<PsiElement> getVirtualTypeElements(final String name, final GlobalSearchScope scope) { Collection<PsiElement> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(VirtualTypeIndex.KEY, name, scope); for (VirtualFile virtualFile : virtualFiles) { XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile); if (xmlFile != null) { Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil .findAttributeValueElements(xmlFile, "virtualType", "name", name); result.addAll(valueElements); } } return result; }
@NotNull private String getTopTypeOfVirtualType(@NonNull String name) { List<String> values; int parentNestingLevel = 0; int maxNestingLevel = 5; do { values = FileBasedIndex.getInstance() .getValues(VirtualTypeIndex.KEY, name, GlobalSearchScope.allScope(project)); if (values.size() > 0 && values.get(0) != null) { name = values.get(0); } } while (values.size() > 0 || maxNestingLevel > parentNestingLevel++); return name; }
private static List<XmlTag> getComponentDeclarations(String componentValue, String componentType, ID<String, Void> id, Project project, ComponentMatcher componentMatcher) { List<XmlTag> results = new ArrayList<XmlTag>(); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles( id, componentValue, GlobalSearchScope.allScope(project) ); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile virtualFile: containingFiles) { XmlFile xmlFile = (XmlFile)psiManager.findFile(virtualFile); if (xmlFile == null) { continue; } XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) { continue; } collectComponentDeclarations(rootTag, results, componentValue, componentType, componentMatcher); } return results; }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { PsiElement position = parameters.getPosition().getOriginalElement(); if (position == null) { return; } String prefix = result.getPrefixMatcher().getPrefix(); Collection<String> moduleNames = FileBasedIndex.getInstance().getAllKeys(ModuleNameIndex.KEY, position.getProject()); moduleNames.removeIf(m -> !m.startsWith(prefix)); for (String moduleName : moduleNames) { result.addElement( LookupElementBuilder .create(moduleName) .withIcon(AllIcons.Modules.ModulesNode) ); } }
public static Collection<VirtualFile> findViewVfsByModuleName(String moduleName, Project project) { Collection<VirtualFile> viewVfs = new ArrayList<>(); Pattern pattern = Pattern.compile(RegExUtil.Magento.MODULE_NAME); Matcher matcher = pattern.matcher(moduleName); if (!matcher.find()) { return viewVfs; } Collection<VirtualFile> moduleVfs = FileBasedIndex.getInstance().getContainingFiles(ModuleNameIndex.KEY, moduleName, GlobalSearchScope.getScopeRestrictedByFileTypes( GlobalSearchScope.allScope(project), PhpFileType.INSTANCE ) ); for (VirtualFile moduleVf : moduleVfs) { viewVfs.addAll(getValues(moduleName, moduleVf, project)); } return viewVfs; }
private static Collection<VirtualFile> getValues(String moduleName, VirtualFile moduleVf, Project project) { Collection<VirtualFile> viewVfs = new ArrayList<>(); FileBasedIndex.getInstance() .processValues( ModuleNameIndex.KEY, moduleName, moduleVf, (file, value) -> { VirtualFile viewVf = file.getParent().findFileByRelativePath(value.concat("/view")); if (viewVf != null) { viewVfs.add(viewVf); } return false; }, GlobalSearchScope.fileScope(project, moduleVf) ); return viewVfs; }
List<PhpClass> getPluginsForClass(@NotNull PhpClass phpClass, @NotNull String classFQN) { List<PhpClass> results = new ArrayList<>(); if (classPluginsMap.containsKey(classFQN)) { return classPluginsMap.get(classFQN); } List<Set<String>> plugins = FileBasedIndex.getInstance() .getValues(PluginIndex.KEY, classFQN, GlobalSearchScope.allScope(phpClass.getProject())); if (plugins.size() == 0) { classPluginsMap.put(classFQN, results); return results; } PhpIndex phpIndex = PhpIndex.getInstance(phpClass.getProject()); for (Set<String> pluginClassNames: plugins) { for (String pluginClassName: pluginClassNames) { results.addAll(phpIndex.getClassesByFQN(pluginClassName)); } } classPluginsMap.put(classFQN, results); return results; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { String value = StringUtil.unquoteString(element.getText()); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles(EventNameIndex.KEY, value, GlobalSearchScope.getScopeRestrictedByFileTypes( GlobalSearchScope.allScope(element.getProject()), PhpFileType.INSTANCE ) ); PsiManager psiManager = PsiManager.getInstance(element.getProject()); for (VirtualFile virtualFile: containingFiles) { PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile); if (phpFile != null) { List<PsiElement> psiElements = new ArrayList<>(); recursiveFill(psiElements, phpFile, value); if (psiElements.size() > 0) { return new PsiReference[] {new PolyVariantReferenceBase(element, psiElements)}; } } } return PsiReference.EMPTY_ARRAY; }
@NotNull public static Map<String, String> getAllKeyValues(Project project) { FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); Map<String, String> keyValues = new HashMap<>(); fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, s -> { if(fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, s, GlobalSearchScope.allScope(project)).size() > 0) { EnvironmentKeyValue keyValue = EnvironmentVariablesUtil.getKeyValueFromString(s); if(keyValues.containsKey(keyValue.getKey())) return true; keyValues.put(keyValue.getKey(), keyValue.getValue()); } return true; }, project); return keyValues; }
/** * * @param project project * @param key environment variable key * @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc */ @NotNull public static PsiElement[] getKeyDeclarations(Project project, String key) { List<PsiElement> targets = new ArrayList<>(); FileBasedIndex.getInstance().getFilesWithKey(DotEnvKeysIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); if(psiFileTarget == null) { return true; } for(EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { if(provider.acceptFile(virtualFile)) { targets.addAll(EnvironmentVariablesUtil.getElementsByKey(key, provider.getElements(psiFileTarget))); } } return true; }, GlobalSearchScope.allScope(project)); return targets.toArray(new PsiElement[0]); }
/** * * @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<>(); FileBasedIndex.getInstance().getFilesWithKey(DotEnvUsagesIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); if(psiFileTarget == null) { return true; } for(EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) { if(provider.acceptFile(virtualFile)) { targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFileTarget))); } } return true; }, GlobalSearchScope.allScope(project)); return targets.toArray(new PsiElement[0]); }
public static List<CptMapping> findMappings(Project project, String key) { List<CptMapping> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, CptFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { CptFile cptFile = (CptFile) PsiManager.getInstance(project).findFile(virtualFile); if (cptFile != null) { CptMapping[] mappings = PsiTreeUtil.getChildrenOfType(cptFile, CptMapping.class); if (mappings != null) { for (CptMapping mapping : mappings) { if (key.equals(mapping.getMatchingClass())) { if (result == null) { result = new ArrayList<>(); } result.add(mapping); } } } } } return result != null ? result : Collections.emptyList(); }
public static List<CptMapping> findMappings(Project project) { List<CptMapping> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, CptFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { CptFile cptFile = (CptFile) PsiManager.getInstance(project).findFile(virtualFile); if (cptFile != null) { CptMapping[] mappings = PsiTreeUtil.getChildrenOfType(cptFile, CptMapping.class); if (mappings != null) { Collections.addAll(result, mappings); } } } return result; }
public static List<CrystalProperty> findProperties(Project project, String key) { List<CrystalProperty> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, CrystalFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { CrystalFile simpleFile = (CrystalFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { CrystalProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, CrystalProperty.class); if (properties != null) { for (CrystalProperty property : properties) { if (key.equals(property.getKey())) { if (result == null) { result = new ArrayList<CrystalProperty>(); } result.add(property); } } } } } return result != null ? result : Collections.<CrystalProperty>emptyList(); }
public static List<CrystalProperty> findProperties(Project project) { List<CrystalProperty> result = new ArrayList<CrystalProperty>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, CrystalFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { CrystalFile simpleFile = (CrystalFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { CrystalProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, CrystalProperty.class); if (properties != null) { Collections.addAll(result, properties); } } } return result; }
public static List<SmcTransition> findTransitions(Project project, String name) { List<SmcTransition> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SmcFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SmcFile smcFile = (SmcFile) PsiManager.getInstance(project).findFile(virtualFile); if (smcFile != null) { SmcTransition[] properties = PsiTreeUtil.getChildrenOfType(smcFile, SmcTransition.class); if (properties != null) { for (SmcTransition property : properties) { if (name.equals(property.getName())) { if (result == null) { result = new ArrayList<SmcTransition>(); } result.add(property); } } } } } return result != null ? result : Collections.<SmcTransition>emptyList(); }
public static List<SmcMap> findMapGlobally(Project project, String name) { List<SmcMap> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SmcFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SmcFile simpleFile = (SmcFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { Collection<SmcMap> properties = PsiTreeUtil.findChildrenOfType(simpleFile, SmcMap.class); for (SmcMap property : properties) { if (name.equals(property.getName())) { if (result == null) { result = new ArrayList<SmcMap>(); } result.add(property); } } } } return result != null ? result : Collections.<SmcMap>emptyList(); }
public static List<SmcFile> findSmcFile(Project project, Predicate<SmcFile> predicate) { List<SmcFile> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SmcFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SmcFile smcFile = (SmcFile) PsiManager.getInstance(project).findFile(virtualFile); if (smcFile != null && (predicate == null || predicate.apply(smcFile))) { if (result == null) { result = new ArrayList<>(); } result.add(smcFile); } } return result != null ? result : Collections.<SmcFile>emptyList(); }
public static List<? extends SmcMethodLikeElement> findMethodLikeForMethod(PsiMethod psiMethod, Class<? extends SmcMethodLikeElement> aClass, Predicate<SmcMethodLikeElement> predicate) { List<SmcMethodLikeElement> result = null; Project project = psiMethod.getProject(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SmcFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SmcFile simpleFile = (SmcFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { Collection<? extends SmcMethodLikeElement> methodLikeElements = PsiTreeUtil.findChildrenOfType(simpleFile, aClass); for (SmcMethodLikeElement methodLike : methodLikeElements) { if (psiMethod.getName().equals(methodLike.getName()) && psiMethod.getParameterList().getParametersCount() == methodLike.getArgumentCount() && (predicate == null || predicate.apply(methodLike))) { if (result == null) { result = new ArrayList<>(); } result.add(methodLike); } } } } return result != null ? result : Collections.<SmcMethodLikeElement>emptyList(); }
public static List<SmcTransition> findTransitionByMethod(PsiMethod psiMethod, Predicate<SmcTransition> predicate) { List<SmcTransition> result = null; Project project = psiMethod.getProject(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SmcFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SmcFile simpleFile = (SmcFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { Collection<SmcTransition> smcTransitions = PsiTreeUtil.findChildrenOfType(simpleFile, SmcTransition.class); for (SmcTransition transition : smcTransitions) { if (psiMethod.getName().equals(transition.getName()) && (psiMethod.getParameterList().getParametersCount() == transition.getArgumentCount() + 1) && (predicate == null || predicate.apply(transition))) { if (result == null) { result = new ArrayList<>(); } result.add(transition); } } } } return result != null ? result : Collections.<SmcTransition>emptyList(); }
public static List<PsiMethodCallExpression> findMethodLikeCalls(SmcMethodLikeElement psiMethodLike) { SmcFile containingFile = (SmcFile) psiMethodLike.getContainingFile().getContainingFile(); PsiClass fsmClass = containingFile.getFsmClass(); Project project = psiMethodLike.getProject(); if (fsmClass == null) return Collections.emptyList(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, JavaFileType.INSTANCE, GlobalSearchScope.projectScope(project)); List<PsiMethodCallExpression> result = new ArrayList<>(); for (VirtualFile virtualFile : virtualFiles) { PsiJavaFile psiJavaFile = (PsiJavaFile) PsiManager.getInstance(project).findFile(virtualFile); if (psiJavaFile != null) { Collection<PsiMethodCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(psiJavaFile, PsiMethodCallExpression.class); for (PsiMethodCallExpression methodCall : methodCallExpressions) { PsiMethod psiMethod = methodCall.resolveMethod(); if (psiMethod != null && psiMethodLike.matches(psiMethod)) { result.add(methodCall); } } } } return result; }
public static List<PsiMethod> findJavaMethod(Project project, String name) { List<PsiMethod> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, JavaFileType.INSTANCE, GlobalSearchScope.projectScope(project)); for (VirtualFile virtualFile : virtualFiles) { PsiJavaFile javaFile = (PsiJavaFile) PsiManager.getInstance(project).findFile(virtualFile); if (javaFile != null) { Collection<PsiMethod> properties = PsiTreeUtil.findChildrenOfType(javaFile, PsiMethod.class); for (PsiMethod javaMethod : properties) { if (name.equals(javaMethod.getName())) { if (result == null) { result = new ArrayList<PsiMethod>(); } result.add(javaMethod); } } } } return result != null ? result : Collections.<PsiMethod>emptyList(); }
@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; }
@NotNull @Override public ResolveResult[] multiResolve(boolean incompleteCode) { String nodeTypeNameToFindReferenceFor = yamlElement.getKeyText(); // files which contain the NodeType definition Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NodeTypesYamlFileIndex.KEY, nodeTypeNameToFindReferenceFor, GlobalSearchScope.allScope(yamlElement.getProject())); return files .stream() // get the PSI for each file .map(file -> PsiManager.getInstance(yamlElement.getProject()).findFile(file)) // ensure we only have YAML files .filter(psiFile -> psiFile instanceof YAMLFile) .map(psiFile -> (YAMLFile) psiFile) // get all YAML keys in these files .flatMap(yamlFile -> YAMLUtil.getTopLevelKeys(yamlFile).stream()) // get the correct YAML key .filter(yamlKeyValue -> yamlKeyValue.getKeyText().equals(nodeTypeNameToFindReferenceFor)) // remove "current" element if it exists .filter(yamlKeyValue -> yamlElement != yamlKeyValue) // build up the result object .map(yamlKeyValue -> new PsiElementResolveResult(yamlKeyValue, true)) .toArray(PsiElementResolveResult[]::new); }
@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof FusionMethodCall) { FusionMethodCall methodCall = (FusionMethodCall) element; if (methodCall.getPrevSibling() != null && methodCall.getPrevSibling().getPrevSibling() instanceof FusionCompositeIdentifier) { FusionCompositeIdentifier compositeId = (FusionCompositeIdentifier) methodCall.getPrevSibling().getPrevSibling(); List<String> helpers = FileBasedIndex.getInstance().getValues(DefaultContextFileIndex.KEY, compositeId.getText(), GlobalSearchScope.allScope(element.getProject())); if (!helpers.isEmpty()) { for (String helper : helpers) { if (PhpElementsUtil.getClassMethod(element.getProject(), helper, methodCall.getMethodName().getText()) != null) { return; } } holder.createErrorAnnotation(methodCall, "Unresolved EEL helper method"); } } } }
public OpenApiFileType getOpenApiFileType(final VirtualFile virtualFile, final Project project) { final Set<String> partialOpenApiFilesWithTypeInfo = getPartialOpenApiFilesWithTypeInfo(project); final Collection<VirtualFile> mainOpenApiFiles = FileBasedIndex.getInstance().getContainingFiles( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.MAIN_OPEN_API_FILE, GlobalSearchScope.allScope(project)); if (mainOpenApiFiles.isEmpty()) { return OpenApiFileType.UNDEFINED; } final VirtualFile mainOpenApiFileFolder = mainOpenApiFiles.iterator().next().getParent(); return partialOpenApiFilesWithTypeInfo.stream() .filter(nameWithTypeInfo -> { final VirtualFile foundFile = mainOpenApiFileFolder.findFileByRelativePath(substringBeforeLast(nameWithTypeInfo, OpenApiDataIndexer.DELIMITER)); return virtualFile.equals(foundFile); }) .findFirst() .map(nameWithTypeInfo -> substringAfterLast(nameWithTypeInfo, OpenApiDataIndexer.DELIMITER)) .map(OpenApiFileType::valueOf) .orElse(OpenApiFileType.UNDEFINED); }
private Set<VirtualFile> getPartialOpenApiFiles(final Project project) { final Set<String> partialOpenApiFilesWithTypeInfo = getPartialOpenApiFilesWithTypeInfo(project); final Collection<VirtualFile> mainOpenApiFiles = FileBasedIndex.getInstance().getContainingFiles( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.MAIN_OPEN_API_FILE, GlobalSearchScope.allScope(project)); if (mainOpenApiFiles.isEmpty()) { return new HashSet<>(); } final VirtualFile mainOpenApiFileFolder = mainOpenApiFiles.iterator().next().getParent(); return partialOpenApiFilesWithTypeInfo.stream() .map(v -> substringBeforeLast(v, OpenApiDataIndexer.DELIMITER)) .map(mainOpenApiFileFolder::findFileByRelativePath) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
public SwaggerFileType getSwaggerFileType(final VirtualFile virtualFile, final Project project) { final Set<String> partialSwaggerFilesWithTypeInfo = getPartialSwaggerFilesWithTypeInfo(project); final Collection<VirtualFile> mainSwaggerFiles = FileBasedIndex.getInstance().getContainingFiles( SwaggerFileIndex.SWAGGER_INDEX_ID, SwaggerFileIndex.MAIN_SWAGGER_FILE, GlobalSearchScope.allScope(project)); if (mainSwaggerFiles.isEmpty()) { return SwaggerFileType.UNDEFINED; } final VirtualFile mainSwaggerFileFolder = mainSwaggerFiles.iterator().next().getParent(); return partialSwaggerFilesWithTypeInfo.stream() .filter(nameWithTypeInfo -> { final VirtualFile foundFile = mainSwaggerFileFolder.findFileByRelativePath(substringBeforeLast(nameWithTypeInfo, SwaggerDataIndexer.DELIMITER)); return virtualFile.equals(foundFile); }) .findFirst() .map(nameWithTypeInfo -> substringAfterLast(nameWithTypeInfo, SwaggerDataIndexer.DELIMITER)) .map(SwaggerFileType::valueOf) .orElse(SwaggerFileType.UNDEFINED); }
private Set<VirtualFile> getPartialSwaggerFiles(final Project project) { final Set<String> partialSwaggerFilesWithTypeInfo = getPartialSwaggerFilesWithTypeInfo(project); final Collection<VirtualFile> mainSwaggerFiles = FileBasedIndex.getInstance().getContainingFiles( SwaggerFileIndex.SWAGGER_INDEX_ID, SwaggerFileIndex.MAIN_SWAGGER_FILE, GlobalSearchScope.allScope(project)); if (mainSwaggerFiles.isEmpty()) { return new HashSet<>(); } final VirtualFile mainSwaggerFileFolder = mainSwaggerFiles.iterator().next().getParent(); return partialSwaggerFilesWithTypeInfo.stream() .map(v -> substringBeforeLast(v, SwaggerDataIndexer.DELIMITER)) .map(mainSwaggerFileFolder::findFileByRelativePath) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
public static List<RythmRythm> findRythms(Project project, String key) { List<RythmRythm> result = null; Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, RythmFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { RythmFile rythmFile = (RythmFile) PsiManager.getInstance(project).findFile(virtualFile); if (rythmFile != null) { RythmRythm[] rythms = PsiTreeUtil.getChildrenOfType(rythmFile, RythmRythm.class); if (rythms != null) { for (RythmRythm rythm : rythms) { // if (key.equals(rythm.getKey())) { if (result == null) { result = new ArrayList<RythmRythm>(); } result.add(rythm); } } } } // } return result != null ? result : Collections.<RythmRythm>emptyList(); }
public static List<RythmRythm> findRythms(Project project) { List<RythmRythm> result = new ArrayList<RythmRythm>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, RythmFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { RythmFile rythmFile = (RythmFile) PsiManager.getInstance(project).findFile(virtualFile); if (rythmFile != null) { RythmRythm[] rythms = PsiTreeUtil.getChildrenOfType(rythmFile, RythmRythm.class); if (rythms != null) { Collections.addAll(result, rythms); } } } return result; }
public static List<HackVarname> findVarnames(Project project) { List<HackVarname> result = new ArrayList<HackVarname>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance() .getContainingFiles(FileTypeIndex.NAME, HackFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { HackFile hackFile = (HackFile) PsiManager.getInstance(project).findFile(virtualFile); if (hackFile != null) { HackVarname[] varnames = PsiTreeUtil.getChildrenOfType(hackFile, HackVarname.class); if (varnames != null) { Collections.addAll(result, varnames); } } } return result; }