add @sample known tag; handle @constructor tag in findKDoc()
This commit is contained in:
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
|||||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||||
|
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||||
|
|
||||||
fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
|
fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
|
||||||
if (declaration is DeclarationDescriptorWithSource) {
|
if (declaration is DeclarationDescriptorWithSource) {
|
||||||
@@ -29,6 +31,13 @@ fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
|
|||||||
if (psiDeclaration is JetDeclaration) {
|
if (psiDeclaration is JetDeclaration) {
|
||||||
val kdoc = psiDeclaration.getDocComment()
|
val kdoc = psiDeclaration.getDocComment()
|
||||||
if (kdoc != null) {
|
if (kdoc != null) {
|
||||||
|
if (declaration is ConstructorDescriptor) {
|
||||||
|
// ConstructorDescriptor resolves to the same JetDeclaration
|
||||||
|
val constructorSection = kdoc.findSectionByTag(KDocKnownTag.CONSTRUCTOR)
|
||||||
|
if (constructorSection != null) {
|
||||||
|
return constructorSection
|
||||||
|
}
|
||||||
|
}
|
||||||
return kdoc.getDefaultSection()
|
return kdoc.getDefaultSection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ public enum KDocKnownTag {
|
|||||||
SEE(true, false),
|
SEE(true, false),
|
||||||
SINCE(false, false),
|
SINCE(false, false),
|
||||||
CONSTRUCTOR(false, true),
|
CONSTRUCTOR(false, true),
|
||||||
PROPERTY(true, true);
|
PROPERTY(true, true),
|
||||||
|
SAMPLE(true, false);
|
||||||
|
|
||||||
private final boolean takesReference;
|
private final boolean takesReference;
|
||||||
private final boolean startsSection;
|
private final boolean startsSection;
|
||||||
|
|||||||
+10
-11
@@ -14,18 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.kdoc.psi.api;
|
package org.jetbrains.kotlin.kdoc.psi.api
|
||||||
|
|
||||||
import com.intellij.psi.PsiComment;
|
import com.intellij.psi.PsiComment
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection;
|
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
|
||||||
|
|
||||||
// Don't implement JetElement (or it will be treated as statement)
|
// Don't implement JetElement (or it will be treated as statement)
|
||||||
public interface KDoc extends PsiComment {
|
public trait KDoc : PsiComment {
|
||||||
@Nullable
|
public fun getOwner(): JetDeclaration?
|
||||||
JetDeclaration getOwner();
|
public fun getDefaultSection(): KDocSection
|
||||||
@NotNull
|
public fun findSectionByName(name: String): KDocSection?
|
||||||
KDocSection getDefaultSection();
|
public fun findSectionByTag(tag: KDocKnownTag): KDocSection?
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,8 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
|||||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||||
|
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||||
|
|
||||||
public class KDocImpl(buffer: CharSequence?) : LazyParseablePsiElement(KDocTokens.KDOC, buffer), KDoc {
|
public class KDocImpl(buffer: CharSequence?) : LazyParseablePsiElement(KDocTokens.KDOC, buffer), KDoc {
|
||||||
|
|
||||||
@@ -38,4 +40,10 @@ public class KDocImpl(buffer: CharSequence?) : LazyParseablePsiElement(KDocToken
|
|||||||
override fun getOwner(): JetDeclaration? = getParentOfType<JetDeclaration>(true)
|
override fun getOwner(): JetDeclaration? = getParentOfType<JetDeclaration>(true)
|
||||||
|
|
||||||
override fun getDefaultSection(): KDocSection = getChildOfType<KDocSection>()!!
|
override fun getDefaultSection(): KDocSection = getChildOfType<KDocSection>()!!
|
||||||
|
|
||||||
|
override fun findSectionByName(name: String): KDocSection? =
|
||||||
|
getChildrenOfType<KDocSection>().firstOrNull { it.getName() == name }
|
||||||
|
|
||||||
|
override fun findSectionByTag(tag: KDocKnownTag): KDocSection? =
|
||||||
|
findSectionByName(tag.name().toLowerCase())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user