PsiClass.getDocComment: don't load AST when there's no doc comment

This commit is contained in:
peter
2018-11-08 08:36:48 +01:00
parent 2075f6d017
commit 5c7c18c460
6 changed files with 21 additions and 5 deletions
@@ -99,7 +99,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
boolean isEnum = isSet(flags, Opcodes.ACC_ENUM);
boolean isAnnotationType = isSet(flags, Opcodes.ACC_ANNOTATION);
short stubFlags = PsiClassStubImpl.packFlags(isDeprecated, isInterface, isEnum, false, false,
isAnnotationType, false, false, myAnonymousInner, myLocalClassInner);
isAnnotationType, false, false, myAnonymousInner, myLocalClassInner, false);
myResult = new PsiClassStubImpl(JavaStubElementTypes.CLASS, myParent, fqn, shortName, null, stubFlags);
myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags));
@@ -77,6 +77,7 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
boolean isAnnotation = false;
boolean isInQualifiedNew = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String qualifiedName = null;
String name = null;
@@ -93,6 +94,7 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
for (final LighterASTNode child : tree.getChildren(node)) {
final IElementType type = child.getTokenType();
if (type == JavaDocElementType.DOC_COMMENT) {
hasDocComment = true;
isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
}
else if (type == JavaElementType.MODIFIER_LIST) {
@@ -134,7 +136,7 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
}
final short flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation,
isInQualifiedNew, hasDeprecatedAnnotation, false, false);
isInQualifiedNew, hasDeprecatedAnnotation, false, false, hasDocComment);
final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
return new PsiClassStubImpl(type, parentStub, qualifiedName, name, baseRef, flags);
}
@@ -44,6 +44,10 @@ public interface PsiClassStub<T extends PsiClass> extends PsiMemberStub<T> {
boolean isAnnotationType();
default boolean hasDocComment() {
return true;
}
@Nullable
String getSourceFileName();
@@ -42,6 +42,7 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
private static final int DEPRECATED_ANNOTATION = 0x80;
private static final int ANONYMOUS_INNER = 0x100;
private static final int LOCAL_CLASS_INNER = 0x200;
private static final int HAS_DOC_COMMENT = 0x400;
private final String myQualifiedName;
private final String myName;
@@ -124,6 +125,11 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
return BitUtil.isSet(myFlags, ANON_TYPE);
}
@Override
public boolean hasDocComment() {
return BitUtil.isSet(myFlags, HAS_DOC_COMMENT);
}
@Override
public LanguageLevel getLanguageLevel() {
StubElement parent = getParentStub();
@@ -163,7 +169,8 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
boolean isInQualifiedNew,
boolean hasDeprecatedAnnotation,
boolean anonymousInner,
boolean localClassInner
boolean localClassInner,
boolean hasDocComment
) {
short flags = 0;
if (isDeprecated) flags |= DEPRECATED;
@@ -176,6 +183,7 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
if (hasDeprecatedAnnotation) flags |= DEPRECATED_ANNOTATION;
if (anonymousInner) flags |= ANONYMOUS_INNER;
if (localClassInner) flags |= LOCAL_CLASS_INNER;
if (hasDocComment) flags |= HAS_DOC_COMMENT;
return flags;
}
@@ -29,7 +29,6 @@ import com.intellij.psi.impl.source.tree.java.JavaFileElement;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.ILightStubFileElementType;
import com.intellij.util.diff.FlyweightCapableTreeStructure;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -38,7 +37,7 @@ import java.io.IOException;
* @author max
*/
public class JavaFileElementType extends ILightStubFileElementType<PsiJavaFileStub> {
public static final int STUB_VERSION = 41;
public static final int STUB_VERSION = 42;
public JavaFileElementType() {
super("java.FILE", JavaLanguage.INSTANCE);
@@ -419,6 +419,9 @@ public class PsiClassImpl extends JavaStubPsiElement<PsiClassStub<?>> implements
@Override
public PsiDocComment getDocComment(){
PsiClassStub<?> stub = getGreenStub();
if (stub != null && !stub.hasDocComment()) return null;
return (PsiDocComment)getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
}