code review
This commit is contained in:
@@ -35,11 +35,11 @@ public interface KDocTokens {
|
||||
ILazyParseableElementType KDOC = new ILazyParseableElementType("KDoc", JetLanguage.INSTANCE) {
|
||||
@Override
|
||||
public ASTNode parseContents(ASTNode chameleon) {
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new KDocLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocParser();
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new KDocLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocParser();
|
||||
|
||||
return parser.parse(this, builder).getFirstChildNode();
|
||||
}
|
||||
@@ -67,11 +67,11 @@ public interface KDocTokens {
|
||||
ILazyParseableElementType MARKDOWN_LINK = new ILazyParseableElementType("KDOC_MARKDOWN_LINK", JetLanguage.INSTANCE) {
|
||||
@Override
|
||||
public ASTNode parseContents(ASTNode chameleon) {
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new JetLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocLinkParser();
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new JetLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocLinkParser();
|
||||
|
||||
return parser.parse(this, builder).getFirstChildNode();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
||||
*/
|
||||
class KDocLinkParser(): PsiParser {
|
||||
override fun parse(root: IElementType, builder: PsiBuilder): ASTNode {
|
||||
builder.setDebugMode(true)
|
||||
val rootMarker = builder.mark()
|
||||
if (builder.getTokenType() == JetTokens.LBRACKET) {
|
||||
builder.advanceLexer()
|
||||
|
||||
@@ -17,11 +17,15 @@
|
||||
package org.jetbrains.kotlin.kdoc.psi.api;
|
||||
|
||||
import com.intellij.psi.PsiComment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
|
||||
// Don't implement JetElement (or it will be treated as statement)
|
||||
public interface KDoc extends PsiComment {
|
||||
@Nullable
|
||||
JetDeclaration getOwner();
|
||||
@NotNull
|
||||
KDocSection getDefaultSection();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class KDocImpl(buffer: CharSequence?) : LazyParseablePsiElement(KDocToken
|
||||
|
||||
override fun getTokenType(): IElementType = JetTokens.DOC_COMMENT
|
||||
|
||||
override fun getOwner(): JetDeclaration = getParentOfType<JetDeclaration>(true)!!
|
||||
override fun getOwner(): JetDeclaration? = getParentOfType<JetDeclaration>(true)
|
||||
|
||||
override fun getDefaultSection(): KDocSection = getChildOfType<KDocSection>()!!
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class KDocLink(node: ASTNode) : JetElementImpl(node) {
|
||||
public fun getLinkTextRange(): TextRange {
|
||||
val text = getText()
|
||||
if (text.startsWith('[') && text.endsWith(']')) {
|
||||
return TextRange(1, text.length()-1)
|
||||
return TextRange(1, text.length() - 1)
|
||||
}
|
||||
return TextRange(0, text.length())
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ public class KDocName(node: ASTNode): JetElementImpl(node) {
|
||||
|
||||
public fun getQualifier(): KDocName? = getChildOfType()
|
||||
|
||||
/**
|
||||
* Returns the range within the element containing the name (in other words,
|
||||
* the range of the element excluding the qualifier and dot, if present).
|
||||
*/
|
||||
public fun getNameTextRange(): TextRange {
|
||||
val dot = getNode().findChildByType(JetTokens.DOT)
|
||||
val textRange = getTextRange()
|
||||
|
||||
@@ -54,9 +54,13 @@ public open class KDocTag(node: ASTNode) : KDocElementImpl(node) {
|
||||
return null
|
||||
}
|
||||
|
||||
public val knownTag: KDocKnownTag?
|
||||
get() {
|
||||
val name = getName()
|
||||
return if (name != null) KDocKnownTag.findByTagName(name) else null
|
||||
}
|
||||
|
||||
private fun hasSubject(contentChildren: List<ASTNode>): Boolean {
|
||||
val name = getName()
|
||||
val knownTag = if (name != null) KDocKnownTag.findByTagName(name) else null
|
||||
if (knownTag?.isReferenceRequired() ?: false) {
|
||||
return contentChildren.firstOrNull()?.getElementType() == KDocElementTypes.KDOC_LINK;
|
||||
}
|
||||
@@ -69,7 +73,7 @@ public open class KDocTag(node: ASTNode) : KDocElementImpl(node) {
|
||||
.dropWhile { it.getElementType() == TokenType.WHITE_SPACE }
|
||||
|
||||
/**
|
||||
* Returns the contents of this tag (all text following the tag name and the subject if present,
|
||||
* Returns the content of this tag (all text following the tag name and the subject if present,
|
||||
* with leading asterisks removed).
|
||||
*/
|
||||
public fun getContent(): String {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FunctionDescriptorUtil {
|
||||
public static JetScope getFunctionInnerScope(
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
RedeclarationHandler redeclarationHandler
|
||||
@NotNull RedeclarationHandler redeclarationHandler
|
||||
) {
|
||||
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Function inner scope");
|
||||
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class JetScopeUtils {
|
||||
public static JetScope getPropertyDeclarationInnerScope(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull JetScope outerScope,
|
||||
RedeclarationHandler redeclarationHandler
|
||||
@NotNull RedeclarationHandler redeclarationHandler
|
||||
) {
|
||||
return getPropertyDeclarationInnerScope(propertyDescriptor,
|
||||
outerScope,
|
||||
@@ -119,7 +119,7 @@ public final class JetScopeUtils {
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor receiver,
|
||||
RedeclarationHandler redeclarationHandler,
|
||||
@NotNull RedeclarationHandler redeclarationHandler,
|
||||
boolean addLabelForProperty
|
||||
) {
|
||||
WritableScopeImpl result = new WritableScopeImpl(
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* [A.B.C...]
|
||||
* [....]
|
||||
* [A..B..C]
|
||||
* [A.]
|
||||
*/
|
||||
@@ -0,0 +1,57 @@
|
||||
JetFile: MarkdownLinkWithError.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
KDOC_SECTION
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' ')
|
||||
KDOC_LINK
|
||||
KDOC_MARKDOWN_LINK
|
||||
PsiElement(LBRACKET)('[')
|
||||
KDOC_NAME
|
||||
KDOC_NAME
|
||||
KDOC_NAME
|
||||
PsiElement(IDENTIFIER)('A')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('B')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('C')
|
||||
PsiErrorElement:Closing bracket expected
|
||||
<empty list>
|
||||
PsiElement(RANGE)('..')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' [....]')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' ')
|
||||
KDOC_LINK
|
||||
KDOC_MARKDOWN_LINK
|
||||
PsiElement(LBRACKET)('[')
|
||||
KDOC_NAME
|
||||
PsiElement(IDENTIFIER)('A')
|
||||
PsiErrorElement:Closing bracket expected
|
||||
<empty list>
|
||||
PsiElement(RANGE)('..')
|
||||
PsiElement(IDENTIFIER)('B')
|
||||
PsiElement(RANGE)('..')
|
||||
PsiElement(IDENTIFIER)('C')
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' ')
|
||||
KDOC_LINK
|
||||
KDOC_MARKDOWN_LINK
|
||||
PsiElement(LBRACKET)('[')
|
||||
KDOC_NAME
|
||||
PsiElement(IDENTIFIER)('A')
|
||||
PsiElement(DOT)('.')
|
||||
PsiErrorElement:Identifier expected
|
||||
<empty list>
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1085,6 +1085,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MarkdownLinkWithError.kt")
|
||||
public void testMarkdownLinkWithError() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/kdoc/MarkdownLinkWithError.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MarkdownQualifiedName.kt")
|
||||
public void testMarkdownQualifiedName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/kdoc/MarkdownQualifiedName.kt");
|
||||
|
||||
Reference in New Issue
Block a user