add support for value parameters to kdoc
This commit is contained in:
@@ -21,6 +21,8 @@ import org.jetbrains.kotlin.model.KClass
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
|
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.model.KParameter
|
||||||
|
|
||||||
class KDoc(val outputDir: File) : KDocSupport() {
|
class KDoc(val outputDir: File) : KDocSupport() {
|
||||||
val model = KModel()
|
val model = KModel()
|
||||||
@@ -74,6 +76,7 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
if (name != null) {
|
if (name != null) {
|
||||||
val klass = pkg.getClass(name)
|
val klass = pkg.getClass(name)
|
||||||
klass.initialise {
|
klass.initialise {
|
||||||
|
klass.description = commentsFor(classElement)
|
||||||
val descriptors = classElement.getDefaultType().getMemberScope().getAllDescriptors()
|
val descriptors = classElement.getDefaultType().getMemberScope().getAllDescriptors()
|
||||||
for (descriptor in descriptors) {
|
for (descriptor in descriptors) {
|
||||||
if (descriptor is CallableDescriptor) {
|
if (descriptor is CallableDescriptor) {
|
||||||
@@ -93,15 +96,32 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
val returnType = getType(descriptor.getReturnType())
|
val returnType = getType(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val method = KMethod(descriptor.getName() ?: "null", returnType)
|
val method = KMethod(descriptor.getName() ?: "null", returnType)
|
||||||
|
method.description = commentsFor(descriptor)
|
||||||
val params = descriptor.getValueParameters()
|
val params = descriptor.getValueParameters()
|
||||||
for (param in params) {
|
for (param in params) {
|
||||||
|
if (param != null) {
|
||||||
|
val p = createParameter(param)
|
||||||
|
if (p != null) {
|
||||||
|
method.parameters.add(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return method
|
return method
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? {
|
||||||
|
val returnType = getType(descriptor.getReturnType())
|
||||||
|
if (returnType != null) {
|
||||||
|
val name = descriptor.getName()
|
||||||
|
val answer = KParameter(name, returnType)
|
||||||
|
answer.description = commentsFor(descriptor)
|
||||||
|
return answer
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
protected fun getType(aType: JetType?): KClass? {
|
protected fun getType(aType: JetType?): KClass? {
|
||||||
if (aType != null) {
|
if (aType != null) {
|
||||||
val classifierDescriptor = aType.constructor.declarationDescriptor
|
val classifierDescriptor = aType.constructor.declarationDescriptor
|
||||||
@@ -119,15 +139,18 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getDocCommentFor(psiElement: PsiElement): String? {
|
protected fun commentsFor(psiElement: DeclarationDescriptor): String {
|
||||||
// This method is a hack. Doc comments should be easily accessible, but they aren't for now.
|
if (psiElement is PsiElement) {
|
||||||
var node = psiElement.getNode()?.getTreePrev()
|
// This method is a hack. Doc comments should be easily accessible, but they aren't for now.
|
||||||
while (node != null && (node?.getElementType() == JetTokens.WHITE_SPACE || node?.getElementType() == JetTokens.BLOCK_COMMENT)) {
|
var node = psiElement.getNode()?.getTreePrev()
|
||||||
node = node?.getTreePrev();
|
while (node != null && (node?.getElementType() == JetTokens.WHITE_SPACE || node?.getElementType() == JetTokens.BLOCK_COMMENT)) {
|
||||||
|
node = node?.getTreePrev();
|
||||||
|
}
|
||||||
|
if (node == null) return "";
|
||||||
|
if (node?.getElementType() != JetTokens.DOC_COMMENT) return "";
|
||||||
|
return node?.getText() ?: "";
|
||||||
}
|
}
|
||||||
if (node == null) return null;
|
return ""
|
||||||
if (node?.getElementType() != JetTokens.DOC_COMMENT) return null;
|
|
||||||
return node?.getText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user