aboutsummaryrefslogtreecommitdiff
path: root/src/CompilerAPI.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:28:02 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:28:02 +0400
commitbdbdbd8986c0b16da69a4beced3cfd274dfd9086 (patch)
tree67d840925df998309ccd83e1a3252269ab57077b /src/CompilerAPI.kt
parent7f6961a9de7d4b42e07b3f1fbd71e3bfb2200f9a (diff)
downloaddokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.tar.gz
dokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.tar.bz2
dokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.zip
Primitive API for analysing JetFile in BindingContext.
Diffstat (limited to 'src/CompilerAPI.kt')
-rw-r--r--src/CompilerAPI.kt58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/CompilerAPI.kt b/src/CompilerAPI.kt
new file mode 100644
index 00000000..b68c0354
--- /dev/null
+++ b/src/CompilerAPI.kt
@@ -0,0 +1,58 @@
+package com.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.*
+
+private fun getClasspath(paths: KotlinPaths): MutableList<File> {
+ val classpath = arrayListOf<File>()
+ classpath.addAll(PathUtil.getJdkClassesRoots())
+ classpath.add(paths.getRuntimePath())
+ return classpath
+}
+
+private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> {
+ val annotationsPath = arrayListOf<File>()
+ annotationsPath.add(paths.getJdkAnnotationsPath())
+ val annotationPaths = arguments.annotations
+ if (annotationPaths != null) {
+ for (element in annotationPaths.split(File.pathSeparatorChar)) {
+ annotationsPath.add(File(element))
+ }
+ }
+ return annotationsPath
+}
+
+private 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<PsiFile>(),
+ 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<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files) \ No newline at end of file