Skip to content

Commit

Permalink
Update bundled kotlin compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
semoro committed Feb 21, 2018
1 parent 9530cb3 commit 3eb2321
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 22 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ allprojects {

def repo = {
artifactPattern("https://teamcity.jetbrains.com/guestAuth/repository/download/Kotlin_dev_CompilerAllPlugins/[revision]/internal/[module](.[ext])")
artifactPattern("https://teamcity.jetbrains.com/guestAuth/repository/download/IntelliJMarkdownParser_Build/[revision]/([module]_[ext]/)[module](.[ext])")
}

buildscript {
Expand Down Expand Up @@ -70,6 +71,7 @@ task wrapper(type: Wrapper) {
def versions = DependenciesVersionGetter.getVersions(project, bundled_kotlin_compiler_version)

ext.ideaVersion = versions["idea.build.id"]
ext.markdownVersion = versions["markdown.build.id"].replace("%20", " ")

configurations {
ideaIC
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-script-runtime:$bundled_kotlin_compiler_version"

compile "teamcity:kotlin-ide-common:$bundled_kotlin_compiler_version"
compile "teamcity:markdown:$bundled_kotlin_compiler_version"
compile "teamcity:markdown:$markdownVersion"

compile intellijCoreAnalysis()

Expand Down
53 changes: 49 additions & 4 deletions core/src/main/kotlin/Analysis/AnalysisEnvironment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.dokka

import com.google.common.collect.ImmutableMap
import com.intellij.core.CoreApplicationEnvironment
import com.intellij.core.CoreModuleManager
import com.intellij.mock.MockComponentManager
Expand All @@ -17,6 +18,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.io.URLUtil
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
Expand All @@ -34,16 +36,19 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.JvmBuiltIns
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.CompilerEnvironment
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
import java.io.File

/**
Expand Down Expand Up @@ -158,7 +163,11 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable {
val resolverForModule = resolverForProject.resolverForModule(module)
val moduleDescriptor = resolverForProject.descriptorForModule(module)
builtIns.initialize(moduleDescriptor, true)
return DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule)
val created = DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule)
val projectComponentManager = environment.project as MockComponentManager
projectComponentManager.registerService(KotlinCacheService::class.java, CoreKotlinCacheService(created))

return created
}

fun loadLanguageVersionSettings(languageVersionString: String?, apiVersionString: String?) {
Expand Down Expand Up @@ -247,6 +256,42 @@ class DokkaResolutionFacade(override val project: Project,
val resolveSession: ResolveSession get() = getFrontendService(ResolveSession::class.java)

override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext {
if (element is KtDeclaration) {
val descriptor = resolveToDescriptor(element)
return object : BindingContext {
override fun <K : Any?, V : Any?> getKeys(p0: WritableSlice<K, V>?): Collection<K> {
throw UnsupportedOperationException()
}

override fun getType(p0: KtExpression): KotlinType? {
throw UnsupportedOperationException()
}

override fun <K : Any?, V : Any?> get(slice: ReadOnlySlice<K, V>?, key: K): V? {
if (key != element) {
throw UnsupportedOperationException()
}
return when {
slice == BindingContext.DECLARATION_TO_DESCRIPTOR -> descriptor as V
slice == BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER && (element as KtParameter).hasValOrVar() -> descriptor as V
else -> null
}
}

override fun getDiagnostics(): Diagnostics {
throw UnsupportedOperationException()
}

override fun addOwnDataTo(p0: BindingTrace, p1: Boolean) {
throw UnsupportedOperationException()
}

override fun <K : Any?, V : Any?> getSliceContents(p0: ReadOnlySlice<K, V>): ImmutableMap<K, V> {
throw UnsupportedOperationException()
}

}
}
throw UnsupportedOperationException()
}

Expand Down
30 changes: 30 additions & 0 deletions core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jetbrains.dokka

import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache


class CoreKotlinCacheService(private val resolutionFacade: DokkaResolutionFacade) : KotlinCacheService {
override fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade {
return resolutionFacade
}

override fun getResolutionFacadeByFile(file: PsiFile, platform: TargetPlatform): ResolutionFacade {
return resolutionFacade
}

override fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? {
return resolutionFacade
}

override fun getSuppressionCache(): KotlinSuppressCache {
throw UnsupportedOperationException()
}

}

30 changes: 16 additions & 14 deletions core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,26 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
}

private val moduleSourceOrderEntry = object : ModuleSourceOrderEntry {
override fun getFiles(p0: OrderRootType?): Array<out VirtualFile> {
override fun getFiles(p0: OrderRootType): Array<VirtualFile> {
throw UnsupportedOperationException()
}

override fun getPresentableName(): String {
override fun getUrls(p0: OrderRootType): Array<String> {
throw UnsupportedOperationException()
}

override fun getUrls(p0: OrderRootType?): Array<out String> {
override fun <R : Any?> accept(p0: RootPolicy<R>, p1: R?): R {
throw UnsupportedOperationException()
}

override fun getOwnerModule(): Module = module

override fun <R : Any?> accept(p0: RootPolicy<R>?, p1: R?): R {
override fun getPresentableName(): String {
throw UnsupportedOperationException()
}

override fun getOwnerModule(): Module = module


override fun isValid(): Boolean {
throw UnsupportedOperationException()
}
Expand All @@ -262,29 +264,29 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
}

private val sdkOrderEntry = object : JdkOrderEntry {
override fun getJdkName(): String? {
override fun getFiles(p0: OrderRootType): Array<VirtualFile> {
throw UnsupportedOperationException()
}

override fun getJdk(): Sdk = sdk

override fun getFiles(p0: OrderRootType?): Array<out VirtualFile> {
override fun getUrls(p0: OrderRootType): Array<String> {
throw UnsupportedOperationException()
}

override fun getPresentableName(): String {
override fun <R : Any?> accept(p0: RootPolicy<R>, p1: R?): R {
throw UnsupportedOperationException()
}

override fun getUrls(p0: OrderRootType?): Array<out String> {
override fun getJdkName(): String? {
throw UnsupportedOperationException()
}

override fun getOwnerModule(): Module {
override fun getJdk(): Sdk = sdk

override fun getPresentableName(): String {
throw UnsupportedOperationException()
}

override fun <R : Any?> accept(p0: RootPolicy<R>?, p1: R?): R {
override fun getOwnerModule(): Module {
throw UnsupportedOperationException()
}

Expand Down Expand Up @@ -358,7 +360,7 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
override fun getRootModel(p0: Module): ModuleRootModel = this@MyModuleRootManager
})

override fun <T : Any?> getModuleExtension(p0: Class<T>?): T {
override fun <T : Any?> getModuleExtension(p0: Class<T>): T {
throw UnsupportedOperationException()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DescriptorDocumentationParser
val suppressAnnotation = annotations.findAnnotation(FqName(Suppress::class.qualifiedName!!))
return if (suppressAnnotation != null) {
@Suppress("UNCHECKED_CAST")
(suppressAnnotation.argumentValue("names") as List<StringValue>).any { it.value == "NOT_DOCUMENTED" }
(suppressAnnotation.argumentValue("names")?.value as List<StringValue>).any { it.value == "NOT_DOCUMENTED" }
} else containingDeclaration?.isSuppressWarning() ?: false
}

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtModifierListOwner
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.resolve.DescriptorUtils
Expand Down Expand Up @@ -779,6 +781,14 @@ class DocumentationBuilder
"\"" + StringUtil.escapeStringCharacters(value) + "\""
is EnumEntrySyntheticClassDescriptor ->
value.containingDeclaration.name.asString() + "." + value.name.asString()
is Pair<*, *> -> {
val (classId, name) = value
if (classId is ClassId && name is Name) {
classId.shortClassName.asString() + "." + name.asString()
} else {
value.toString()
}
}
else -> value.toString()
}.let { valueString ->
DocumentationNode(valueString, Content.Empty, NodeKind.Value)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dokka_version=0.9.16
dokka_publication_channel=dokka

#Kotlin compiler and plugin
bundled_kotlin_compiler_version=1.2.20-dev-419
kotlin_version=1.2.0
bundled_kotlin_compiler_version=1.2.40-dev-529
kotlin_version=1.2.21
kotlin_for_gradle_runtime_version=1.1.60

ant_version=1.9.6
Expand Down

0 comments on commit 3eb2321

Please sign in to comment.