diff options
-rw-r--r-- | src/Analysis/CompilerAPI.kt | 21 | ||||
-rw-r--r-- | src/Model/DocumentationModel.kt | 4 | ||||
-rw-r--r-- | src/Model/DocumentationResolver.kt | 15 | ||||
-rw-r--r-- | test/data/functions/genericFunctionWithConstraints.kt | 2 | ||||
-rw-r--r-- | test/src/model/FunctionTest.kt | 12 |
5 files changed, 36 insertions, 18 deletions
diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt index 039ad799..f6693ae0 100644 --- a/src/Analysis/CompilerAPI.kt +++ b/src/Analysis/CompilerAPI.kt @@ -18,6 +18,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.jet.lang.resolve.scopes.WritableScope import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler +import org.jetbrains.jet.lang.types.TypeUtils private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> { val annotationsPath = arrayListOf<File>() @@ -94,13 +95,12 @@ fun BindingContext.getResolutionScope(descriptor: DeclarationDescriptor): JetSco is PackageFragmentDescriptor -> return descriptor.getMemberScope() is PackageViewDescriptor -> return descriptor.getMemberScope() - is ClassDescriptor -> return descriptor.getUnsubstitutedInnerClassesScope() - is PropertyAccessorDescriptor -> return getResolutionScope(descriptor.getCorrespondingProperty()) - is FunctionDescriptor -> { - val container = getFunctionInnerScope(getResolutionScope(descriptor.getContainingDeclaration()), descriptor) - if (container is JetFunction) - return getFunctionBodyScope(container) + is ClassDescriptorWithResolutionScopes -> return descriptor.getScopeForMemberDeclarationResolution() + is ClassDescriptor -> { + val typeParameters: List<TypeParameterDescriptor> = descriptor.getTypeConstructor().getParameters() + return descriptor.getMemberScope(TypeUtils.getDefaultTypeProjections(typeParameters)) } + is FunctionDescriptor -> return getFunctionInnerScope(getResolutionScope(descriptor.getContainingDeclaration()), descriptor) } if (descriptor is DeclarationDescriptorNonRoot) @@ -108,12 +108,3 @@ fun BindingContext.getResolutionScope(descriptor: DeclarationDescriptor): JetSco throw IllegalArgumentException("Cannot find resolution scope for root $descriptor") } - -fun BindingContext.getFunctionBodyScope(element: JetFunction): JetScope { - val body = element.getBodyExpression() - val scope = get(BindingContext.RESOLUTION_SCOPE, body) - if (scope != null) - return scope - throw IllegalArgumentException("Cannot find resolution scope for function $element") -} - diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt index 61c3b28a..77bd8373 100644 --- a/src/Model/DocumentationModel.kt +++ b/src/Model/DocumentationModel.kt @@ -53,6 +53,10 @@ public open class DocumentationNode(val name: String, val doc: String, val kind: } public fun references(kind: DocumentationReferenceKind): List<DocumentationReference> = references.filter { it.kind == kind } + + public override fun toString() : String { + return "$kind $name" + } } public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model) { diff --git a/src/Model/DocumentationResolver.kt b/src/Model/DocumentationResolver.kt index 70ee4aae..1d470867 100644 --- a/src/Model/DocumentationResolver.kt +++ b/src/Model/DocumentationResolver.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka import org.jetbrains.jet.lang.resolve.scopes.* +import org.jetbrains.jet.lang.resolve.name.* +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor fun DocumentationNode.resolve(): DocumentationNode { @@ -8,5 +10,18 @@ fun DocumentationNode.resolve(): DocumentationNode { } fun DocumentationNode.resolve(scope: JetScope): DocumentationNode { + for (detail in details) { + val symbol = when (detail.kind) { + DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() + DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(detail.name)) + DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(detail.name)).single() + DocumentationNodeKind.Property -> scope.getProperties(Name.guess(detail.name)).single() + DocumentationNodeKind.TypeParameter -> scope.getClassifier(Name.guess(detail.name)) + else -> scope.getClassifier(Name.guess(detail.name)) + } + + if (symbol == null) + throw IllegalStateException("Cannot resolve node $this detail $detail") + } return this }
\ No newline at end of file diff --git a/test/data/functions/genericFunctionWithConstraints.kt b/test/data/functions/genericFunctionWithConstraints.kt index 11598ae7..dc7fa3bb 100644 --- a/test/data/functions/genericFunctionWithConstraints.kt +++ b/test/data/functions/genericFunctionWithConstraints.kt @@ -2,5 +2,5 @@ /** * generic function */ -fun <T : CharSequence> generic() { +fun <T : R, R> generic() { }
\ No newline at end of file diff --git a/test/src/model/FunctionTest.kt b/test/src/model/FunctionTest.kt index 217e97f4..aa22ee0f 100644 --- a/test/src/model/FunctionTest.kt +++ b/test/src/model/FunctionTest.kt @@ -66,12 +66,13 @@ public class FunctionTest { assertEquals(DocumentationNodeKind.Function, kind) assertEquals("generic function", doc) - with(details.single()) { + assertEquals(2, details.count()) + with(details.elementAt(0)) { assertEquals("T", name) assertEquals(DocumentationNodeKind.TypeParameter, kind) assertEquals("", doc) with(details.single()) { - assertEquals("CharSequence", name) + assertEquals("R", name) assertEquals(DocumentationNodeKind.UpperBound, kind) assertEquals("", doc) assertTrue(details.none()) @@ -81,6 +82,13 @@ public class FunctionTest { assertTrue(members.none()) assertTrue(links.none()) } + with(details.elementAt(1)) { + assertEquals("R", name) + assertEquals(DocumentationNodeKind.TypeParameter, kind) + assertEquals("", doc) + assertTrue(members.none()) + assertTrue(links.none()) + } assertTrue(members.none()) assertTrue(links.none()) |