/** * Check that function or property with the given qualified name can be resolved in given scope * and called on given receiver * * @param callableFQN * @param project * @param scope * @return */ public static List<CallableDescriptor> canFindSuitableCall( @NotNull FqName callableFQN, @NotNull Project project, @NotNull JetExpression receiverExpression, @NotNull JetType receiverType, @NotNull JetScope scope) { JetImportDirective importDirective = JetPsiFactory.createImportDirective(project, callableFQN.getFqName()); Collection<? extends DeclarationDescriptor> declarationDescriptors = ImportsResolver.analyseImportReference(importDirective, scope, new BindingTraceContext()); List<CallableDescriptor> callableExtensionDescriptors = new ArrayList<CallableDescriptor>(); ReceiverDescriptor receiverDescriptor = new ExpressionReceiver(receiverExpression, receiverType); for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) { if (declarationDescriptor instanceof CallableDescriptor) { CallableDescriptor callableDescriptor = (CallableDescriptor) declarationDescriptor; if (checkIsExtensionCallable(receiverDescriptor, callableDescriptor)) { callableExtensionDescriptors.add(callableDescriptor); } } } return callableExtensionDescriptors; }
public PsiClass findClass(@NotNull FqName qualifiedName) { for (final VirtualFile classRoot : roots) { PsiClass answer = CoreJavaFileManager.findClassInClasspathRoot( qualifiedName.getFqName(), classRoot, psiManager); if (answer != null) return answer; } return null; }
private static boolean compileBunchOfSources( K2JVMCompileEnvironmentConfiguration configuration, String jar, String outputDir, boolean includeRuntime) { FqName mainClass = null; for (JetFile file : configuration.getEnvironment().getSourceFiles()) { if (JetMainDetector.hasMain(file.getDeclarations())) { FqName fqName = JetPsiUtil.getFQName(file); mainClass = fqName.child(JvmAbi.PACKAGE_CLASS); break; } } GenerationState generationState = analyzeAndGenerate(configuration); if (generationState == null) { return false; } try { ClassFileFactory factory = generationState.getFactory(); if (jar != null) { try { CompileEnvironmentUtil.writeToJar( factory, new FileOutputStream(jar), mainClass, includeRuntime); } catch (FileNotFoundException e) { throw new CompileEnvironmentException("Invalid jar path " + jar, e); } } else if (outputDir != null) { CompileEnvironmentUtil.writeToOutputDirectory(factory, outputDir); } else { throw new CompileEnvironmentException( "Output directory or jar file is not specified - no files will be saved to the disk"); } return true; } finally { generationState.destroy(); } }
@NotNull private static FqName getQualifiedName(@NotNull FqName packageFQN, @NotNull String name) { return packageFQN.child(name); }