@NotNull public ResolveResult[] multiResolve(final boolean incompleteCode) { final String refName = getName(); if (refName == null) return LuaResolveResult.EMPTY_ARRAY; ResolveProcessor processor = new SymbolResolveProcessor(refName, this, incompleteCode); final LuaDocCommentOwner docOwner = LuaDocCommentUtil.findDocOwner(this); if (docOwner != null) { final LuaStatementElement statementElement = PsiTreeUtil.getParentOfType(docOwner, LuaStatementElement.class, false); if (statementElement != null) statementElement.processDeclarations(processor, ResolveState.initial(), this, this); } if (processor.hasCandidates()) { return processor.getCandidates(); } LuaGlobalDeclarationIndex index = LuaGlobalDeclarationIndex.getInstance(); Collection<LuaDeclarationExpression> names = index.get(refName, getProject(), new ProjectAndLibrariesScope(getProject())); for (LuaDeclarationExpression name : names) { name.processDeclarations(processor, ResolveState.initial(), this, this); } if (processor.hasCandidates()) { return processor.getCandidates(); } return LuaResolveResult.EMPTY_ARRAY; }
@Override public Collection<LuaDeclarationExpression> call() throws Exception { DumbService.getInstance(project).waitForSmartMode(); return ApplicationManager.getApplication() .runReadAction(new Computable<Collection<LuaDeclarationExpression>>() { @Override public Collection<LuaDeclarationExpression> compute() { return ResolveUtil.getFilteredGlobals(project, new ProjectAndLibrariesScope(project)); } }); }
/** * includes the GraphQL schema virtual file in the provided "Project and Libraries" scope * @see JSGraphQLProjectAndLibrariesScope */ private static void addGraphQLSchemaFileToProjectAndLibrariesScope(FindUsagesOptions options) { if(options.searchScope instanceof ProjectAndLibrariesScope) { final ProjectAndLibrariesScope projectAndLibrariesScope = (ProjectAndLibrariesScope) options.searchScope; options.searchScope = new JSGraphQLProjectAndLibrariesScope(projectAndLibrariesScope); } }
private Map<PsiElement,Item> getGlobalEnvItems() { if (global_envitems_ready) { return global_envitems; } else { synchronized (global_envitems_lock) { if (global_envitems == null) { // get all classes from IntelliJ global_envitems = new HashMap<PsiElement, Item>(); } logger.info("making global_envitems (" + global_envitems.size() + " items already there)"); PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project); String[] classnames = cache.getAllClassNames(); GlobalSearchScope scope = new ProjectAndLibrariesScope(project, true); // Add all classes. TODO: This includes local classes, but probably shouldn't Map<PsiElement,Item> fake_globals = new HashMap<PsiElement,Item>(); for (String name : classnames) for (PsiClass cls : cache.getClassesByName(name, scope)) if (!isInaccessible(cls, true)) addClass(fake_globals, global_envitems, cls, true, true); logger.info("making global_env with " + global_envitems.size() + " items."); // update global_env global_env = Tarski.environment(global_envitems.values()); logger.info("global_env ready."); global_envitems_ready = true; } return global_envitems; } }
public static TheRCallExpression findCall(Project project, String functionName, Predicate<TheRCallExpression> predicate) { ProjectAndLibrariesScope scope = new ProjectAndLibrariesScope(project); Collection<TheRAssignmentStatement> possibleDefinitions = TheRAssignmentNameIndex.find(functionName, project, scope); TheRAssignmentStatement functionDefinition = null; for (TheRAssignmentStatement assignment : possibleDefinitions) { if (assignment.getAssignedValue() instanceof TheRFunctionExpression) { functionDefinition = assignment; break; } } if (functionDefinition == null) { return null; } for (PsiReference reference : ReferencesSearch.search(functionDefinition, scope)) { PsiElement referenceFrom = reference.getElement(); PsiElement parent = referenceFrom.getParent(); if (parent == null || !TheRCallExpression.class.isInstance(parent)) { continue; } TheRCallExpression call = (TheRCallExpression)parent; if (predicate.apply(call)) { return call; } } return null; }
@SuppressWarnings("ConstantConditions") public JSGraphQLProjectAndLibrariesScope(ProjectAndLibrariesScope delegate) { super(delegate.getProject(), delegate.isSearchOutsideRootModel()); this.delegate = delegate; }