diff options
-rw-r--r-- | src/Analysis/AnalysisEnvironment.kt | 2 | ||||
-rw-r--r-- | src/Analysis/CompilerAPI.kt | 14 | ||||
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 144 | ||||
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 12 | ||||
-rw-r--r-- | src/Locations/LocationService.kt | 2 | ||||
-rw-r--r-- | src/Utilities/Path.kt | 5 |
6 files changed, 85 insertions, 94 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt index 39a05604..a2836592 100644 --- a/src/Analysis/AnalysisEnvironment.kt +++ b/src/Analysis/AnalysisEnvironment.kt @@ -50,7 +50,7 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A val projectComponentManager = environment.project as MockComponentManager val moduleManager = CoreModuleManager(environment.project, this) - CoreApplicationEnvironment.registerComponentInstance(projectComponentManager.getPicoContainer(), + CoreApplicationEnvironment.registerComponentInstance(projectComponentManager.picoContainer, javaClass<ModuleManager>(), moduleManager) projectComponentManager.registerService(javaClass<ProjectFileIndex>(), diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt index 8b877204..5ab2037b 100644 --- a/src/Analysis/CompilerAPI.kt +++ b/src/Analysis/CompilerAPI.kt @@ -1,17 +1,13 @@ package org.jetbrains.dokka -import org.jetbrains.kotlin.cli.common.arguments.* -import org.jetbrains.kotlin.cli.jvm.compiler.* -import org.jetbrains.kotlin.utils.* -import java.io.* -import org.jetbrains.kotlin.resolve.jvm.* -import org.jetbrains.kotlin.analyzer.* -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.resolve.scopes.* -import org.jetbrains.kotlin.context.GlobalContext import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.analyzer.ModuleContent +import org.jetbrains.kotlin.analyzer.ModuleInfo +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.context.ProjectContext import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade +import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters import org.jetbrains.kotlin.resolve.lazy.ResolveSession fun KotlinCoreEnvironment.analyze(): ResolveSession { diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index aae82c18..9717c1a6 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -11,11 +11,11 @@ import org.jsoup.nodes.TextNode public class JavaDocumentationBuilder(private val options: DocumentationOptions, private val refGraph: NodeReferenceGraph) { fun appendFile(file: PsiJavaFile, module: DocumentationModule) { - if (file.getClasses().all { skipElement(it) }) { + if (file.classes.all { skipElement(it) }) { return } - val packageNode = module.findOrCreatePackageNode(file.getPackageName(), emptyMap()) - packageNode.appendChildren(file.getClasses()) { build() } + val packageNode = module.findOrCreatePackageNode(file.packageName, emptyMap()) + packageNode.appendChildren(file.classes) { build() } } data class JavadocParseResult(val content: Content, val deprecatedContent: Content?) @@ -26,9 +26,9 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, var deprecatedContent: Content? = null val para = ContentParagraph() result.append(para) - para.convertJavadocElements(docComment.getDescriptionElements().dropWhile { it.getText().trim().isEmpty() }) - docComment.getTags().forEach { tag -> - when(tag.getName()) { + para.convertJavadocElements(docComment.descriptionElements.dropWhile { it.text.trim().isEmpty() }) + docComment.tags.forEach { tag -> + when(tag.name) { "see" -> result.convertSeeTag(tag) "deprecated" -> { deprecatedContent = Content() @@ -36,7 +36,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } else -> { val subjectName = tag.getSubjectName() - val section = result.addSection(javadocSectionDisplayName(tag.getName()), subjectName) + val section = result.addSection(javadocSectionDisplayName(tag.name), subjectName) section.convertJavadocElements(tag.contentElements()) } @@ -46,10 +46,10 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } private fun PsiDocTag.contentElements(): Iterable<PsiElement> { - val tagValueElements = getChildren() - .dropWhile { it.getNode().getElementType() == JavaDocTokenType.DOC_TAG_NAME } + val tagValueElements = children + .dropWhile { it.node.elementType == JavaDocTokenType.DOC_TAG_NAME } .dropWhile { it is PsiWhiteSpace } - .filterNot { it.getNode().getElementType() == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS } + .filterNot { it.node.elementType == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS } return if (getSubjectName() != null) tagValueElements.dropWhile { it is PsiDocTagValue } else tagValueElements } @@ -59,7 +59,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, if (it is PsiInlineDocTag) { htmlBuilder.append(convertInlineDocTag(it)) } else { - htmlBuilder.append(it.getText()) + htmlBuilder.append(it.text) } } val doc = Jsoup.parse(htmlBuilder.toString().trimStart()) @@ -114,9 +114,9 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } val seeSection = findSectionByTag(ContentTags.SeeAlso) ?: addSection(ContentTags.SeeAlso, null) val linkSignature = resolveLink(linkElement) - val text = ContentText(linkElement.getText()) + val text = ContentText(linkElement.text) if (linkSignature != null) { - val linkNode = ContentNodeLazyLink(tag.getValueElement()!!.getText(), { -> refGraph.lookup(linkSignature)}) + val linkNode = ContentNodeLazyLink(tag.valueElement!!.text, { -> refGraph.lookup(linkSignature)}) linkNode.append(text) seeSection.append(linkNode) } else { @@ -124,35 +124,35 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } } - private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.getName()) { + private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.name) { "link", "linkplain" -> { val valueElement = tag.linkElement() val linkSignature = resolveLink(valueElement) if (linkSignature != null) { - val labelText = tag.getDataElements().firstOrNull { it is PsiDocToken }?.getText() ?: valueElement!!.getText() + val labelText = tag.dataElements.firstOrNull { it is PsiDocToken }?.text ?: valueElement!!.text val link = "<a docref=\"$linkSignature\">${labelText.htmlEscape()}</a>" - if (tag.getName() == "link") "<code>$link</code>" else link + if (tag.name == "link") "<code>$link</code>" else link } else if (valueElement != null) { - valueElement.getText() + valueElement.text } else { "" } } "code", "literal" -> { val text = StringBuilder() - tag.getDataElements().forEach { text.append(it.getText()) } + tag.dataElements.forEach { text.append(it.text) } val escaped = text.toString().trimStart().htmlEscape() - if (tag.getName() == "code") "<code>$escaped</code>" else escaped + if (tag.name == "code") "<code>$escaped</code>" else escaped } - else -> tag.getText() + else -> tag.text } private fun PsiDocTag.linkElement(): PsiElement? = - getValueElement() ?: getDataElements().firstOrNull { it !is PsiWhiteSpace } + valueElement ?: dataElements.firstOrNull { it !is PsiWhiteSpace } private fun resolveLink(valueElement: PsiElement?): String? { - val target = valueElement?.getReference()?.resolve() + val target = valueElement?.reference?.resolve() if (target != null) { return getSignature(target) } @@ -160,8 +160,8 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } fun PsiDocTag.getSubjectName(): String? { - if (getName() == "param" || getName() == "throws" || getName() == "exception") { - return getValueElement()?.getText() + if (name == "param" || name == "throws" || name == "exception") { + return valueElement?.text } return null } @@ -188,32 +188,32 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } private fun getSignature(element: PsiElement?) = when(element) { - is PsiClass -> element.getQualifiedName() - is PsiField -> element.getContainingClass()!!.getQualifiedName() + "#" + element.getName() + is PsiClass -> element.qualifiedName + is PsiField -> element.containingClass!!.qualifiedName + "#" + element.name is PsiMethod -> - element.getContainingClass()!!.getQualifiedName() + "#" + element.getName() + "(" + - element.getParameterList().getParameters().map { it.getType().typeSignature() }.join(",") + ")" + element.containingClass!!.qualifiedName + "#" + element.name + "(" + + element.parameterList.parameters.map { it.type.typeSignature() }.join(",") + ")" else -> null } private fun PsiType.typeSignature(): String = when(this) { - is PsiArrayType -> "Array<${getComponentType().typeSignature()}>" + is PsiArrayType -> "Array<${componentType.typeSignature()}>" else -> mapTypeName(this) } fun DocumentationNode(element: PsiNamedElement, kind: Kind, - name: String = element.getName() ?: "<anonymous>"): DocumentationNode { - val (docComment, deprecatedContent) = parseDocumentation((element as? PsiDocCommentOwner)?.getDocComment()) + name: String = element.name ?: "<anonymous>"): DocumentationNode { + val (docComment, deprecatedContent) = parseDocumentation((element as? PsiDocCommentOwner)?.docComment) val node = DocumentationNode(name, docComment, kind) if (element is PsiModifierListOwner) { node.appendModifiers(element) - val modifierList = element.getModifierList() + val modifierList = element.modifierList if (modifierList != null) { - modifierList.getAnnotations().filter { !ignoreAnnotation(it) }.forEach { + modifierList.annotations.filter { !ignoreAnnotation(it) }.forEach { val annotation = it.build() node.append(annotation, - if (it.getQualifiedName() == "java.lang.Deprecated") DocumentationReference.Kind.Deprecation else DocumentationReference.Kind.Annotation) + if (it.qualifiedName == "java.lang.Deprecated") DocumentationReference.Kind.Deprecation else DocumentationReference.Kind.Annotation) } } } @@ -224,7 +224,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, return node } - fun ignoreAnnotation(annotation: PsiAnnotation) = when(annotation.getQualifiedName()) { + fun ignoreAnnotation(annotation: PsiAnnotation) = when(annotation.qualifiedName) { "java.lang.SuppressWarnings" -> true else -> false } @@ -246,7 +246,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, (element.hasModifierProperty(PsiModifier.PRIVATE) || element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) private fun hasSuppressTag(element: Any) = - element is PsiDocCommentOwner && element.getDocComment()?.let { it.findTagByName("suppress") != null } ?: false + element is PsiDocCommentOwner && element.docComment?.let { it.findTagByName("suppress") != null } ?: false fun DocumentationNode.appendMembers<T>(elements: Array<T>, buildFn: T.() -> DocumentationNode) = appendChildren(elements, DocumentationReference.Kind.Member, buildFn) @@ -256,23 +256,23 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun PsiClass.build(): DocumentationNode { val kind = when { - isInterface() -> DocumentationNode.Kind.Interface - isEnum() -> DocumentationNode.Kind.Enum - isAnnotationType() -> DocumentationNode.Kind.AnnotationClass + isInterface -> DocumentationNode.Kind.Interface + isEnum -> DocumentationNode.Kind.Enum + isAnnotationType -> DocumentationNode.Kind.AnnotationClass else -> DocumentationNode.Kind.Class } val node = DocumentationNode(this, kind) - getSuperTypes().filter { !ignoreSupertype(it) }.forEach { + superTypes.filter { !ignoreSupertype(it) }.forEach { node.appendType(it, Kind.Supertype) val superClass = it.resolve() if (superClass != null) { link(superClass, node, DocumentationReference.Kind.Inheritor) } } - node.appendDetails(getTypeParameters()) { build() } - node.appendMembers(getMethods()) { build() } - node.appendMembers(getFields()) { build() } - node.appendMembers(getInnerClasses()) { build() } + node.appendDetails(typeParameters) { build() } + node.appendMembers(methods) { build() } + node.appendMembers(fields) { build() } + node.appendMembers(innerClasses) { build() } register(this, node) return node } @@ -282,9 +282,9 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun PsiClassType.isClass(qName: String): Boolean { val shortName = qName.substringAfterLast('.') - if (getClassName() == shortName) { + if (className == shortName) { val psiClass = resolve() - return psiClass?.getQualifiedName() == qName + return psiClass?.qualifiedName == qName } return false } @@ -294,7 +294,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, if (!hasModifierProperty(PsiModifier.FINAL)) { node.appendTextNode("var", Kind.Modifier) } - node.appendType(getType()) + node.appendType(type) register(this, node) return node } @@ -307,27 +307,27 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun PsiMethod.build(): DocumentationNode { val node = DocumentationNode(this, nodeKind(), - if (isConstructor()) "<init>" else getName()) + if (isConstructor) "<init>" else name) - if (!isConstructor()) { - node.appendType(getReturnType()) + if (!isConstructor) { + node.appendType(returnType) } - node.appendDetails(getParameterList().getParameters()) { build() } - node.appendDetails(getTypeParameters()) { build() } + node.appendDetails(parameterList.parameters) { build() } + node.appendDetails(typeParameters) { build() } register(this, node) return node } private fun PsiMethod.nodeKind(): Kind = when { - isConstructor() -> Kind.Constructor + isConstructor -> Kind.Constructor hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectFunction else -> Kind.Function } fun PsiParameter.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Parameter) - node.appendType(getType()) - if (getType() is PsiEllipsisType) { + node.appendType(type) + if (type is PsiEllipsisType) { node.appendTextNode("vararg", Kind.Annotation, DocumentationReference.Kind.Annotation) } return node @@ -335,22 +335,20 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun PsiTypeParameter.build(): DocumentationNode { val node = DocumentationNode(this, Kind.TypeParameter) - getExtendsListTypes().forEach { node.appendType(it, Kind.UpperBound) } - getImplementsListTypes().forEach { node.appendType(it, Kind.UpperBound) } + extendsListTypes.forEach { node.appendType(it, Kind.UpperBound) } + implementsListTypes.forEach { node.appendType(it, Kind.UpperBound) } return node } fun DocumentationNode.appendModifiers(element: PsiModifierListOwner) { - val modifierList = element.getModifierList() - if (modifierList == null) { - return - } + val modifierList = element.modifierList ?: return + PsiModifier.MODIFIERS.forEach { if (it != "static" && modifierList.hasExplicitModifier(it)) { appendTextNode(it, Kind.Modifier) } } - if ((element is PsiClass || (element is PsiMethod && !element.isConstructor())) && + if ((element is PsiClass || (element is PsiMethod && !element.isConstructor)) && !element.hasModifierProperty(PsiModifier.FINAL)) { appendTextNode("open", Kind.Modifier) } @@ -367,34 +365,34 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, val name = mapTypeName(this) val node = DocumentationNode(name, Content.Empty, kind) if (this is PsiClassType) { - node.appendDetails(getParameters()) { build(Kind.Type) } + node.appendDetails(parameters) { build(Kind.Type) } link(node, resolve()) } if (this is PsiArrayType && this !is PsiEllipsisType) { - node.append(getComponentType().build(Kind.Type), DocumentationReference.Kind.Detail) + node.append(componentType.build(Kind.Type), DocumentationReference.Kind.Detail) } return node } private fun mapTypeName(psiType: PsiType): String = when (psiType) { PsiType.VOID -> "Unit" - is PsiPrimitiveType -> psiType.getCanonicalText().capitalize() + is PsiPrimitiveType -> psiType.canonicalText.capitalize() is PsiClassType -> { val psiClass = psiType.resolve() - if (psiClass?.getQualifiedName() == "java.lang.Object") "Any" else psiType.getClassName() + if (psiClass?.qualifiedName == "java.lang.Object") "Any" else psiType.className } - is PsiEllipsisType -> mapTypeName(psiType.getComponentType()) + is PsiEllipsisType -> mapTypeName(psiType.componentType) is PsiArrayType -> "Array" - else -> psiType.getCanonicalText() + else -> psiType.canonicalText } fun PsiAnnotation.build(): DocumentationNode { - val node = DocumentationNode(getNameReferenceElement()?.getText() ?: "<?>", Content.Empty, DocumentationNode.Kind.Annotation) - getParameterList().getAttributes().forEach { - val parameter = DocumentationNode(it.getName() ?: "value", Content.Empty, DocumentationNode.Kind.Parameter) - val value = it.getValue() + val node = DocumentationNode(nameReferenceElement?.text ?: "<?>", Content.Empty, DocumentationNode.Kind.Annotation) + parameterList.attributes.forEach { + val parameter = DocumentationNode(it.name ?: "value", Content.Empty, DocumentationNode.Kind.Parameter) + val value = it.value if (value != null) { - val valueText = (value as? PsiLiteralExpression)?.getValue() as? String ?: value.getText() + val valueText = (value as? PsiLiteralExpression)?.value as? String ?: value.text val valueNode = DocumentationNode(valueText, Content.Empty, DocumentationNode.Kind.Value) parameter.append(valueNode, DocumentationReference.Kind.Detail) } diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 34018217..9ce81cee 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -136,13 +136,13 @@ fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functio val text = when (psiElement) { is JetDeclarationWithBody -> ContentBlockCode().let() { - val bodyExpression = psiElement.getBodyExpression() + val bodyExpression = psiElement.bodyExpression when (bodyExpression) { - is JetBlockExpression -> bodyExpression.getText().removeSurrounding("{", "}") - else -> bodyExpression!!.getText() + is JetBlockExpression -> bodyExpression.text.removeSurrounding("{", "}") + else -> bodyExpression!!.text } } - else -> psiElement.getText() + else -> psiElement.text } val lines = text.trimEnd().split("\n".toRegex()).toTypedArray().filterNot { it.length() == 0 } @@ -160,14 +160,14 @@ private fun DocumentationBuilder.resolveInScope(functionName: String, scope: Jet for (part in parts) { // short name val symbolName = Name.guess(part) - val partSymbol = currentScope.getAllDescriptors().filter { it.getName() == symbolName }.firstOrNull() + val partSymbol = currentScope.getAllDescriptors().filter { it.name == symbolName }.firstOrNull() if (partSymbol == null) { symbol = null break } currentScope = if (partSymbol is ClassDescriptor) - partSymbol.getDefaultType().getMemberScope() + partSymbol.defaultType.memberScope else getResolutionScope(resolutionFacade, partSymbol) symbol = partSymbol diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 000b2c5e..4f587361 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -26,7 +26,7 @@ public data class FileLocation(val file: File): Location { if (file.path.substringBeforeLast(".") == other.file.path.substringBeforeLast(".") && anchor == null) { return "." } - val ownerFolder = file.getParentFile()!! + val ownerFolder = file.parentFile!! val relativePath = ownerFolder.getRelativePath(other.file).path return if (anchor == null) relativePath else relativePath + "#" + anchor } diff --git a/src/Utilities/Path.kt b/src/Utilities/Path.kt index 24420ec7..fea22250 100644 --- a/src/Utilities/Path.kt +++ b/src/Utilities/Path.kt @@ -3,10 +3,7 @@ package org.jetbrains.dokka import java.io.* fun File.getRelativePath(name: File): File { - val parent = getParentFile() - - if (parent == null) - throw IOException("No common directory"); + val parent = parentFile ?: throw IOException("No common directory") val basePath = getCanonicalPath() + File.separator; val targetPath = name.getCanonicalPath(); |