diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 14:38:18 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 14:38:18 +0400 |
commit | 06fe0f45b99cb1aef4ab0be2712bb589ed62e7e9 (patch) | |
tree | b319997ee8908424f6c725dadaa258d30c28b05b | |
download | dokka-06fe0f45b99cb1aef4ab0be2712bb589ed62e7e9.tar.gz dokka-06fe0f45b99cb1aef4ab0be2712bb589ed62e7e9.tar.bz2 dokka-06fe0f45b99cb1aef4ab0be2712bb589ed62e7e9.zip |
Initial commit, setup compiler-as-a-service to analyse files.
-rw-r--r-- | .idea/.name | 1 | ||||
-rw-r--r-- | .idea/compiler.xml | 23 | ||||
-rw-r--r-- | .idea/encodings.xml | 5 | ||||
-rw-r--r-- | .idea/libraries/kotlin.xml | 11 | ||||
-rw-r--r-- | .idea/libraries/kotlin_compiler.xml | 76 | ||||
-rw-r--r-- | .idea/misc.xml | 10 | ||||
-rw-r--r-- | .idea/modules.xml | 9 | ||||
-rw-r--r-- | .idea/scopes/scope_settings.xml | 5 | ||||
-rw-r--r-- | .idea/vcs.xml | 7 | ||||
-rw-r--r-- | dokka.iml | 14 | ||||
-rw-r--r-- | src/main.kt | 89 |
11 files changed, 250 insertions, 0 deletions
diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..c8bb43f2 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +dokka
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..217af471 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <option name="DEFAULT_COMPILER" value="Javac" /> + <resourceExtensions /> + <wildcardResourcePatterns> + <entry name="!?*.java" /> + <entry name="!?*.form" /> + <entry name="!?*.class" /> + <entry name="!?*.groovy" /> + <entry name="!?*.scala" /> + <entry name="!?*.flex" /> + <entry name="!?*.kt" /> + <entry name="!?*.clj" /> + </wildcardResourcePatterns> + <annotationProcessing> + <profile default="true" name="Default" enabled="false"> + <processorPath useClasspath="true" /> + </profile> + </annotationProcessing> + </component> +</project> + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..e206d70d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> +</project> + diff --git a/.idea/libraries/kotlin.xml b/.idea/libraries/kotlin.xml new file mode 100644 index 00000000..a24e595c --- /dev/null +++ b/.idea/libraries/kotlin.xml @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="kotlin"> + <CLASSES> + <root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-runtime.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-runtime-sources.jar!/" /> + </SOURCES> + </library> +</component>
\ No newline at end of file diff --git a/.idea/libraries/kotlin_compiler.xml b/.idea/libraries/kotlin_compiler.xml new file mode 100644 index 00000000..f0b20ad9 --- /dev/null +++ b/.idea/libraries/kotlin_compiler.xml @@ -0,0 +1,76 @@ +<component name="libraryTable"> + <library name="kotlin-compiler"> + <CLASSES> + <root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-compiler.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="file://$PROJECT_DIR$/../kotlin/js/js.tests/test" /> + <root url="file://$PROJECT_DIR$/../kotlin/js/js.dart-ast/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/js/js.translator/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/j2k/tests/test" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/descriptors/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/runtime.jvm/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/util.runtime/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/serialization/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/serialization.java/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/core/descriptor.loader.java/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/docs/exPuzzlers/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/idea/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/idea/tests" /> + <root url="file://$PROJECT_DIR$/../kotlin/eval4j/test" /> + <root url="file://$PROJECT_DIR$/../kotlin/grammar/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/cli/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/cli/cli-common/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/util/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/tests" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/backend/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/frontend/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/preloader/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/preloader/instrumentation/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/android-tests/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/android-tests/tests" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/android-tests/android-module/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/frontend.java/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/backend-common/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/jet.as.java.psi/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/compiler/integration-tests/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/runtime/target/copied-sources" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kdoc-maven-plugin/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kdoc-maven-plugin/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/src/main/kotlin" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/AndroidProject/Lib/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/AndroidProject/Android/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinJavaProject/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/target/test-classes/testProject/AndroidProject/Lib/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/target/test-classes/testProject/AndroidProject/Android/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin/target/test-classes/testProject/kotlinJavaProject/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-js-tests-junit/src/test/kotlin" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/src/it/test-classpath/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/src/it/test-helloworld/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/target/it/test-classpath/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/target/it/test-helloworld/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-maven-plugin-test/target/it/test-inlineDisabled/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/simpleProject/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/additionalJavaSrc/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/additionalJavaSrc/generated" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/target/test-classes/testProject/simpleProject/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/target/test-classes/testProject/additionalJavaSrc/src/main/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/tools/kotlin-gradle-plugin-core/target/test-classes/testProject/additionalJavaSrc/generated" /> + <root url="file://$PROJECT_DIR$/../kotlin/libraries/examples/kotlin-java-example/src/test/java" /> + <root url="file://$PROJECT_DIR$/../kotlin/generators/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/generators/tests" /> + <root url="file://$PROJECT_DIR$/../kotlin/jps-plugin/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/jps-plugin/test" /> + <root url="file://$PROJECT_DIR$/../kotlin/jps-plugin/kannotator-jps-plugin-test/test" /> + <root url="file://$PROJECT_DIR$/../kotlin/build-tools/ant/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/build-tools/core/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/dependencies/download/asm-src" /> + <root url="file://$PROJECT_DIR$/../kotlin/injector-generator/src" /> + <root url="file://$PROJECT_DIR$/../kotlin/ide-compiler-runner/src" /> + </SOURCES> + </library> +</component>
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..0cae957f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="EntryPointsManager"> + <entry_points version="2.0" /> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..142d525a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/dokka.iml" filepath="$PROJECT_DIR$/dokka.iml" /> + </modules> + </component> +</project> + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 00000000..922003b8 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ +<component name="DependencyValidationManager"> + <state> + <option name="SKIP_IMPORT_STATEMENTS" value="false" /> + </state> +</component>
\ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..275077f8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> + diff --git a/dokka.iml b/dokka.iml new file mode 100644 index 00000000..2fe62815 --- /dev/null +++ b/dokka.iml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="jetbrains.dokka" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="kotlin" level="project" /> + <orderEntry type="library" name="kotlin-compiler" level="project" /> + </component> +</module> + diff --git a/src/main.kt b/src/main.kt new file mode 100644 index 00000000..7edaf43d --- /dev/null +++ b/src/main.kt @@ -0,0 +1,89 @@ +package com.jetbrains.dokka + +import org.jetbrains.jet.cli.common.arguments.* +import com.sampullara.cli.* +import com.intellij.openapi.util.* +import org.jetbrains.jet.cli.common.messages.* +import org.jetbrains.jet.cli.jvm.* +import org.jetbrains.jet.config.* +import org.jetbrains.jet.cli.jvm.compiler.* +import org.jetbrains.jet.cli.common.* +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.* + +public fun main(args: Array<String>) { + + val arguments = K2JVMCompilerArguments() + arguments.freeArgs = Args.parse(arguments, args) + + val rootDisposable = Disposer.newDisposable() + + val messageCollector = MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR + val configuration = CompilerConfiguration() + + val paths = PathUtil.getKotlinPathsForCompiler() + + configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments)) + configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs ?: listOf()) + configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) + + val environment = JetCoreEnvironment.createForProduction(rootDisposable, configuration) + val context = environment.analyze(messageCollector) + rootDisposable.dispose() +} + +private fun getClasspath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> { + val classpath = arrayListOf<File>() + classpath.addAll(PathUtil.getJdkClassesRoots()) + classpath.add(paths.getRuntimePath()) + val classPath = arguments.classpath + if (classPath != null) { + for (element in classPath.split(File.pathSeparatorChar)) { + classpath.add(File(element)) + } + } + 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 |