diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 01:49:53 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 01:49:53 +0400 |
commit | 992bf22a5e2209e8305ce86255518c4dd918894d (patch) | |
tree | 5bd47f7c1d465bd83aa8e5e68df31dbb804ac540 /src | |
parent | a5999ec90d77e6fe1f8ce292e0b570588eba9f73 (diff) | |
download | dokka-992bf22a5e2209e8305ce86255518c4dd918894d.tar.gz dokka-992bf22a5e2209e8305ce86255518c4dd918894d.tar.bz2 dokka-992bf22a5e2209e8305ce86255518c4dd918894d.zip |
Resolve all the referenced node, except owners.
Diffstat (limited to 'src')
-rw-r--r-- | src/Analysis/CompilerAPI.kt | 60 | ||||
-rw-r--r-- | src/Model/DocumentationModel.kt | 3 | ||||
-rw-r--r-- | src/Model/DocumentationResolver.kt | 33 |
3 files changed, 73 insertions, 23 deletions
diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt index f6693ae0..9562e763 100644 --- a/src/Analysis/CompilerAPI.kt +++ b/src/Analysis/CompilerAPI.kt @@ -13,12 +13,7 @@ import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.lang.psi.* import org.jetbrains.jet.analyzer.* import org.jetbrains.jet.lang.descriptors.* -import org.jetbrains.jet.lang.resolve.scopes.JetScope -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 +import org.jetbrains.jet.lang.resolve.scopes.* private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> { val annotationsPath = arrayListOf<File>() @@ -67,6 +62,25 @@ fun DeclarationDescriptor.isUserCode() = else -> true } +public fun getClassInnerScope(outerScope: JetScope, descriptor: ClassDescriptor): JetScope { + val redeclarationHandler = object : RedeclarationHandler { + override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) { + // TODO: check if we can ignore redeclarations + } + } + + val parameterScope = WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Function KDoc scope") + for (typeParameter in descriptor.getTypeConstructor().getParameters()) { + parameterScope.addTypeParameterDescriptor(typeParameter) + } + for (constructor in descriptor.getConstructors()) { + parameterScope.addFunctionDescriptor(constructor) + } + parameterScope.addLabeledDeclaration(descriptor) + parameterScope.changeLockLevel(WritableScope.LockLevel.READING) + return parameterScope +} + public fun getFunctionInnerScope(outerScope: JetScope, descriptor: FunctionDescriptor): JetScope { val redeclarationHandler = object : RedeclarationHandler { override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) { @@ -90,17 +104,39 @@ public fun getFunctionInnerScope(outerScope: JetScope, descriptor: FunctionDescr return parameterScope } +public fun getPropertyInnerScope(outerScope: JetScope, descriptor: PropertyDescriptor): JetScope { + val redeclarationHandler = object : RedeclarationHandler { + override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) { + // TODO: check if we can ignore redeclarations + } + } + + val parameterScope = WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Function KDoc scope") + val receiver = descriptor.getReceiverParameter() + if (receiver != null) { + parameterScope.setImplicitReceiver(receiver) + } + for (typeParameter in descriptor.getTypeParameters()) { + parameterScope.addTypeParameterDescriptor(typeParameter) + } + for (valueParameterDescriptor in descriptor.getValueParameters()) { + parameterScope.addVariableDescriptor(valueParameterDescriptor) + } + for (accessor in descriptor.getAccessors()) { + parameterScope.addFunctionDescriptor(accessor) + } + parameterScope.addLabeledDeclaration(descriptor) + parameterScope.changeLockLevel(WritableScope.LockLevel.READING) + return parameterScope +} + fun BindingContext.getResolutionScope(descriptor: DeclarationDescriptor): JetScope { when (descriptor) { is PackageFragmentDescriptor -> return descriptor.getMemberScope() is PackageViewDescriptor -> return descriptor.getMemberScope() - - is ClassDescriptorWithResolutionScopes -> return descriptor.getScopeForMemberDeclarationResolution() - is ClassDescriptor -> { - val typeParameters: List<TypeParameterDescriptor> = descriptor.getTypeConstructor().getParameters() - return descriptor.getMemberScope(TypeUtils.getDefaultTypeProjections(typeParameters)) - } + is ClassDescriptor -> return getClassInnerScope(descriptor.getDefaultType().getMemberScope(), descriptor) is FunctionDescriptor -> return getFunctionInnerScope(getResolutionScope(descriptor.getContainingDeclaration()), descriptor) + is PropertyDescriptor -> return getPropertyInnerScope(getResolutionScope(descriptor.getContainingDeclaration()), descriptor) } if (descriptor is DeclarationDescriptorNonRoot) diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt index 90fe40e4..c5dd6603 100644 --- a/src/Model/DocumentationModel.kt +++ b/src/Model/DocumentationModel.kt @@ -59,6 +59,7 @@ public open class DocumentationNode(val name: String, } public fun references(kind: DocumentationReferenceKind): List<DocumentationReference> = references.filter { it.kind == kind } + public fun allReferences(): List<DocumentationReference> = references public override fun toString(): String { return "$kind $name" @@ -87,5 +88,7 @@ fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel { val visitor = DocumentationNodeBuilder(this) packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model) + model.resolveAll() + return model } diff --git a/src/Model/DocumentationResolver.kt b/src/Model/DocumentationResolver.kt index dee68f49..40968f4f 100644 --- a/src/Model/DocumentationResolver.kt +++ b/src/Model/DocumentationResolver.kt @@ -1,23 +1,34 @@ package org.jetbrains.dokka -import org.jetbrains.jet.lang.resolve.scopes.* import org.jetbrains.jet.lang.resolve.name.* import org.jetbrains.jet.lang.descriptors.* -fun DocumentationNode.resolve(): DocumentationNode { - for (detail in details) { - val symbol: DeclarationDescriptor? = when (detail.kind) { +fun DocumentationNode.resolve() { + for (item in details + members) { + val symbolName = item.name + val symbol: DeclarationDescriptor? = when (item.kind) { DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() - DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(detail.name)) - DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(detail.name)).firstOrNull() - DocumentationNodeKind.Property -> scope.getProperties(Name.guess(detail.name)).firstOrNull() - DocumentationNodeKind.TypeParameter -> scope.getClassifier(Name.guess(detail.name)) - else -> scope.getClassifier(Name.guess(detail.name)) + DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(symbolName)) + DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Property -> scope.getProperties(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Constructor -> scope.getFunctions(Name.guess(symbolName)).firstOrNull() + + DocumentationNodeKind.Package -> { + // TODO: do not resolve constructors and packages for now + item.scope.getContainingDeclaration() + } + else -> scope.getClassifier(Name.guess(symbolName)) } if (symbol == null) - throw IllegalStateException("Cannot resolve node $this detail $detail") + throw IllegalStateException("Cannot resolve $item in $this") + } + + for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) { + reference.to.resolve() } - return this } +fun DocumentationModel.resolveAll() { + resolve() +}
\ No newline at end of file |