From 044308ba60a0d4462ccb7388f16ad17a31d7450d Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 11 Jul 2014 20:49:04 +0400 Subject: Complete package migration and move files into folders. --- src/Analysis/CompilerAPI.kt | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Analysis/CompilerAPI.kt (limited to 'src/Analysis/CompilerAPI.kt') diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt new file mode 100644 index 00000000..bf77a7d4 --- /dev/null +++ b/src/Analysis/CompilerAPI.kt @@ -0,0 +1,62 @@ +package org.jetbrains.dokka + +import org.jetbrains.jet.cli.common.arguments.* +import org.jetbrains.jet.cli.common.messages.* +import org.jetbrains.jet.cli.jvm.* +import org.jetbrains.jet.cli.jvm.compiler.* +import org.jetbrains.jet.utils.* +import java.io.* +import org.jetbrains.jet.lang.resolve.java.* +import com.google.common.base.* +import com.intellij.psi.* +import org.jetbrains.jet.lang.resolve.* +import org.jetbrains.jet.lang.psi.* +import org.jetbrains.jet.analyzer.* +import org.jetbrains.jet.lang.descriptors.* + +private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList { + val annotationsPath = arrayListOf() + annotationsPath.add(paths.getJdkAnnotationsPath()) + val annotationPaths = arguments.annotations + if (annotationPaths != null) { + for (element in annotationPaths.split(File.pathSeparatorChar)) { + annotationsPath.add(File(element)) + } + } + return annotationsPath +} + +fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): BindingContext { + val project = getProject() + val sourceFiles = getSourceFiles() + + val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector) + analyzerWithCompilerReport.analyzeAndReport(sourceFiles) { + val support = CliLightClassGenerationSupport.getInstanceForCli(project)!! + val sharedTrace = support.getTrace() + val sharedModule = support.getModule() + val compilerConfiguration = getConfiguration()!! + AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, sourceFiles, sharedTrace, + Predicates.alwaysTrue(), + sharedModule, + compilerConfiguration.get(JVMConfigurationKeys.MODULE_IDS), + compilerConfiguration.get(JVMConfigurationKeys.INCREMENTAL_CACHE_BASE_DIR)) + } + + val exhaust = analyzerWithCompilerReport.getAnalyzeExhaust() + assert(exhaust != null) { "AnalyzeExhaust should be non-null, compiling: " + sourceFiles } + + return exhaust!!.getBindingContext() +} + +fun AnalyzerWithCompilerReport.analyzeAndReport(files: List, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files) + +fun BindingContext.getPackageFragment(file: JetFile) = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file) + +fun DeclarationDescriptor.isUserCode() = + when (this) { + is PackageFragmentDescriptor -> false + is PropertyAccessorDescriptor -> !isDefault() + is CallableMemberDescriptor -> getKind() == CallableMemberDescriptor.Kind.DECLARATION + else -> true + } -- cgit