private void setUpEnvironment( boolean generateAssertions, boolean generateParamAssertions, File... extraClassPath) { CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests( ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions); configuration.put( JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions); myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration); }
private CompilerConfiguration createConfiguration( @Nullable String stdlib, @Nullable String[] classpath, @Nullable String[] externalAnnotationsPath, @NotNull String[] sourceRoots, boolean enableInline, boolean enableOptimization) { KotlinPaths paths = getKotlinPathsForAntTask(); CompilerConfiguration configuration = new CompilerConfiguration(); configuration.addAll(CLASSPATH_KEY, PathUtil.getJdkClassesRoots()); if ((stdlib != null) && (stdlib.trim().length() > 0)) { configuration.add(CLASSPATH_KEY, new File(stdlib)); } else { File path = paths.getRuntimePath(); if (path.exists()) { configuration.add(CLASSPATH_KEY, path); } } if ((classpath != null) && (classpath.length > 0)) { for (String path : classpath) { configuration.add(CLASSPATH_KEY, new File(path)); } } if ((externalAnnotationsPath != null) && (externalAnnotationsPath.length > 0)) { for (String path : externalAnnotationsPath) { configuration.add(ANNOTATIONS_PATH_KEY, new File(path)); } } File jdkAnnotationsPath = paths.getJdkAnnotationsPath(); if (jdkAnnotationsPath.exists()) { configuration.add(ANNOTATIONS_PATH_KEY, jdkAnnotationsPath); } configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourceRoots)); for (String sourceRoot : sourceRoots) { File file = new File(sourceRoot); if (!file.isFile() || !"kt".equals(FileUtilRt.getExtension(file.getName()))) { configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file); } } configuration.put( CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); configuration.put(ENABLE_INLINE, enableInline); configuration.put(ENABLE_OPTIMIZATION, enableOptimization); // lets register any compiler plugins configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins()); return configuration; }
public void doTest(String path) throws Exception { File dir = new File(path); CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests( ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, new File(dir, "java")); configuration.put( CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(new File(dir, "kotlin").getAbsolutePath())); JetCoreEnvironment environment = new JetCoreEnvironment(getTestRootDisposable(), configuration); ModuleDescriptor moduleDescriptor = new ModuleDescriptor(Name.special("<test module>")); // we need the same binding trace for resolve from Java and Kotlin BindingTrace trace = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).getTrace(); InjectorForJavaDescriptorResolver injectorForJava = new InjectorForJavaDescriptorResolver(environment.getProject(), trace, moduleDescriptor); InjectorForTopDownAnalyzerForJvm injectorForAnalyzer = new InjectorForTopDownAnalyzerForJvm( environment.getProject(), new TopDownAnalysisParameters( Predicates.<PsiFile>alwaysFalse(), false, false, Collections.<AnalyzerScriptParameter>emptyList()), trace, moduleDescriptor); injectorForAnalyzer .getTopDownAnalyzer() .analyzeFiles( environment.getSourceFiles(), Collections.<AnalyzerScriptParameter>emptyList()); JavaDescriptorResolver javaDescriptorResolver = injectorForJava.getJavaDescriptorResolver(); NamespaceDescriptor namespaceDescriptor = javaDescriptorResolver.resolveNamespace( LoadDescriptorUtil.TEST_PACKAGE_FQNAME, DescriptorSearchRule.INCLUDE_KOTLIN); assert namespaceDescriptor != null; compareNamespaceWithFile( namespaceDescriptor, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, new File(dir, "expected.txt")); ExpectedLoadErrorsUtil.checkForLoadErrors(namespaceDescriptor, trace.getBindingContext()); }