@NotNull private static SearchScope notNullizeScope( @NotNull FindUsagesOptions options, @NotNull Project project) { SearchScope scope = options.searchScope; if (scope == null) return ProjectScope.getAllScope(project); return scope; }
public ReplInterpreter( @NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) { KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction( disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES); Project project = environment.getProject(); this.psiFileFactory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project); this.trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(); MutableModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project); this.module = moduleContext.getModule(); scriptDeclarationFactory = new ScriptMutableDeclarationProviderFactory(); FileScopeProvider.AdditionalScopes scopeProvider = new FileScopeProvider.AdditionalScopes() { @NotNull @Override public List<JetScope> scopes(@NotNull JetFile file) { return lastLineScope != null ? new SmartList<JetScope>(lastLineScope) : Collections.<JetScope>emptyList(); } }; ContainerForReplWithJava container = DiPackage.createContainerForReplWithJava( moduleContext, trace, scriptDeclarationFactory, ProjectScope.getAllScope(project), scopeProvider); this.topDownAnalysisContext = new TopDownAnalysisContext( TopDownAnalysisMode.LocalDeclarations, DataFlowInfo.EMPTY, container.getResolveSession().getDeclarationScopeProvider()); this.topDownAnalyzer = container.getLazyTopDownAnalyzerForTopLevel(); this.resolveSession = container.getResolveSession(); moduleContext.initializeModuleContents( new CompositePackageFragmentProvider( Arrays.asList( container.getResolveSession().getPackageFragmentProvider(), container.getJavaDescriptorResolver().getPackageFragmentProvider()))); List<URL> classpath = Lists.newArrayList(); for (File file : getJvmClasspathRoots(configuration)) { try { classpath.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw UtilsPackage.rethrow(e); } } this.classLoader = new ReplClassLoader(new URLClassLoader(classpath.toArray(new URL[classpath.size()]), null)); }
@Nullable public PsiClass getContainingClassElement() { final PsiClassType containingClassType = JavaPsiFacade.getInstance(getProject()) .getElementFactory() .createTypeByFQClassName(myContainingClassName, ProjectScope.getAllScope(getProject())); return containingClassType.resolve(); }
public static List<PsiFile> findFxmlWithController(final Project project, String className) { return findFxmlWithController( project, className, new Function<VirtualFile, PsiFile>() { @Override public PsiFile fun(VirtualFile file) { return PsiManager.getInstance(project).findFile(file); } }, ProjectScope.getAllScope(project)); }
@NotNull private Object[] getSubclassVariants( @NotNull PsiPackage context, @NotNull String[] extendClasses) { HashSet<Object> lookups = new HashSet<Object>(); GlobalSearchScope packageScope = PackageScope.packageScope(context, true); GlobalSearchScope scope = myJavaClassReferenceSet.getProvider().getScope(); if (scope != null) { packageScope = packageScope.intersectWith(scope); } final GlobalSearchScope allScope = ProjectScope.getAllScope(context.getProject()); final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(getOptions()); final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(getOptions()); final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(getOptions()); final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(getOptions()); final ClassKind classKind = getClassKind(); for (String extendClassName : extendClasses) { final PsiClass extendClass = JavaPsiFacade.getInstance(context.getProject()).findClass(extendClassName, allScope); if (extendClass != null) { // add itself if (packageScope.contains(extendClass.getContainingFile().getVirtualFile())) { if (isClassAccepted( extendClass, classKind, instantiatable, concrete, notInterface, notEnum)) { ContainerUtil.addIfNotNull(createSubclassLookupValue(context, extendClass), lookups); } } for (final PsiClass clazz : ClassInheritorsSearch.search(extendClass, packageScope, true)) { if (isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) { ContainerUtil.addIfNotNull(createSubclassLookupValue(context, clazz), lookups); } } } } return lookups.toArray(); }
@NotNull public static VirtualFile getTargetDirectoryFor( @NotNull Project project, @NotNull VirtualFile sourceFile, @Nullable String targetFile, @Nullable String targetPackage, boolean returnRoot) { boolean hasPackage = StringUtil.isNotEmpty(targetPackage); ProjectRootManager rootManager = ProjectRootManager.getInstance(project); ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project); Collection<VirtualFile> files = targetFile == null ? Collections.<VirtualFile>emptyList() : FilenameIndex.getVirtualFilesByName( project, targetFile, ProjectScope.getAllScope(project)); VirtualFile existingFile = null; for (VirtualFile file : files) { String existingFilePackage = fileIndex.getPackageNameByDirectory(file.getParent()); if (!hasPackage || existingFilePackage == null || targetPackage.equals(existingFilePackage)) { existingFile = file; break; } } VirtualFile existingFileRoot = existingFile == null ? null : fileIndex.isInSourceContent(existingFile) ? fileIndex.getSourceRootForFile(existingFile) : fileIndex.isInContent(existingFile) ? fileIndex.getContentRootForFile(existingFile) : null; boolean preferGenRoot = sourceFile.getFileType() == BnfFileType.INSTANCE || sourceFile.getFileType() == JFlexFileType.INSTANCE; boolean preferSourceRoot = hasPackage && !preferGenRoot; VirtualFile[] sourceRoots = rootManager.getContentSourceRoots(); VirtualFile[] contentRoots = rootManager.getContentRoots(); final VirtualFile virtualRoot = existingFileRoot != null ? existingFileRoot : preferSourceRoot && fileIndex.isInSource(sourceFile) ? fileIndex.getSourceRootForFile(sourceFile) : fileIndex.isInContent(sourceFile) ? fileIndex.getContentRootForFile(sourceFile) : getFirstElement( preferSourceRoot && sourceRoots.length > 0 ? sourceRoots : contentRoots); if (virtualRoot == null) { fail(project, sourceFile, "Unable to guess target source root"); throw new ProcessCanceledException(); } try { String genDirName = Options.GEN_DIR.get(); boolean newGenRoot = !fileIndex.isInSourceContent(virtualRoot); final String relativePath = (hasPackage && newGenRoot ? genDirName + "/" + targetPackage : hasPackage ? targetPackage : newGenRoot ? genDirName : "") .replace('.', '/'); if (relativePath.isEmpty()) { return virtualRoot; } else { VirtualFile result = new WriteAction<VirtualFile>() { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { result.setResult(VfsUtil.createDirectoryIfMissing(virtualRoot, relativePath)); } }.execute().throwException().getResultObject(); VfsUtil.markDirtyAndRefresh(false, true, true, result); return returnRoot && newGenRoot ? ObjectUtils.assertNotNull(virtualRoot.findChild(genDirName)) : returnRoot ? virtualRoot : result; } } catch (ProcessCanceledException ex) { throw ex; } catch (Exception ex) { fail(project, sourceFile, ex.getMessage()); throw new ProcessCanceledException(); } }
public static List<VirtualFile> findFxmlsWithController( final Project project, @NotNull String className) { return findFxmlWithController( project, className, Function.ID, ProjectScope.getAllScope(project)); }