Added JetDeclaration.getDocComment() + more correct implementation of it
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.psi.findDocComment
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.siblings
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.PsiComment
|
||||
|
||||
fun findDocComment(declaration: JetDeclaration): KDoc? {
|
||||
return declaration.getFirstChild().siblings()
|
||||
.dropWhile { it !is KDoc && (it is PsiWhiteSpace || it is PsiComment) }
|
||||
.first() as? KDoc
|
||||
}
|
||||
@@ -18,6 +18,8 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
|
||||
public interface JetDeclaration extends JetExpression, JetModifierListOwner {
|
||||
JetDeclaration[] EMPTY_ARRAY = new JetDeclaration[0];
|
||||
@@ -29,4 +31,7 @@ public interface JetDeclaration extends JetExpression, JetModifierListOwner {
|
||||
return count == 0 ? EMPTY_ARRAY : new JetDeclaration[count];
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
public KDoc getDocComment();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lang.psi.addRemoveModifier.AddRemoveModifierPackage;
|
||||
import org.jetbrains.jet.lang.psi.findDocComment.FindDocCommentPackage;
|
||||
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
@@ -69,4 +71,10 @@ abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclar
|
||||
if (modifierList == null) return Collections.emptyList();
|
||||
return modifierList.getAnnotations();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KDoc getDocComment() {
|
||||
return FindDocCommentPackage.findDocComment(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,8 @@ import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lang.psi.findDocComment.FindDocCommentPackage;
|
||||
|
||||
abstract class JetDeclarationStub<T extends StubElement> extends JetModifierListOwnerStub<T> implements JetDeclaration {
|
||||
public JetDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||
@@ -35,4 +32,10 @@ abstract class JetDeclarationStub<T extends StubElement> extends JetModifierList
|
||||
public JetDeclarationStub(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KDoc getDocComment() {
|
||||
return FindDocCommentPackage.findDocComment(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.KotlinLightMethod;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetPackageDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class JetQuickDocumentationProvider extends AbstractDocumentationProvider
|
||||
renderedDecl = "<pre>" + DescriptorRenderer.HTML_NAMES_WITH_SHORT_TYPES.render(declarationDescriptor) + "</pre>";
|
||||
}
|
||||
|
||||
KDoc comment = findElementKDoc(declaration);
|
||||
KDoc comment = declaration.getDocComment();
|
||||
if (comment != null) {
|
||||
renderedDecl = renderedDecl + "<br/>" + kDocToHtml(comment);
|
||||
}
|
||||
@@ -140,11 +140,6 @@ public class JetQuickDocumentationProvider extends AbstractDocumentationProvider
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static KDoc findElementKDoc(@NotNull JetElement element) {
|
||||
return (KDoc) JetPsiUtil.findChildByType(element, JetTokens.DOC_COMMENT);
|
||||
}
|
||||
|
||||
private static String kDocToHtml(@NotNull KDoc comment) {
|
||||
// TODO: Parse and show markdown comments as html
|
||||
String content = getKDocContent(comment);
|
||||
|
||||
Reference in New Issue
Block a user