use of com.intellij.psi.impl.java.stubs.PsiFieldStub in project intellij-community by JetBrains.
the class PsiFieldImpl method getDocComment.
@Override
public PsiDocComment getDocComment() {
final PsiFieldStub stub = getGreenStub();
if (stub != null && !stub.hasDocComment())
return null;
CompositeElement treeElement = getNode();
if (getTypeElement() != null) {
PsiElement element = treeElement.findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
return element instanceof PsiDocComment ? (PsiDocComment) element : null;
} else {
ASTNode prevField = treeElement.getTreePrev();
while (prevField.getElementType() != JavaElementType.FIELD) {
prevField = prevField.getTreePrev();
}
return ((PsiField) SourceTreeToPsiMap.treeElementToPsi(prevField)).getDocComment();
}
}
use of com.intellij.psi.impl.java.stubs.PsiFieldStub in project intellij-community by JetBrains.
the class PsiFieldImpl method getDetachedInitializer.
// avoids stub-to-AST switch if possible,
// returns the light generated initializer literal expression if stored in stubs, the regular initializer if wasn't
public PsiExpression getDetachedInitializer() {
final PsiFieldStub stub = getGreenStub();
PsiExpression initializer;
if (stub == null) {
initializer = getInitializer();
} else {
String initializerText = stub.getInitializerText();
if (StringUtil.isEmpty(initializerText) || PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText) || PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) {
initializer = getInitializer();
} else {
PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
initializer = parserFacade.createExpressionFromText(initializerText, this);
((LightVirtualFile) initializer.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false);
}
}
return initializer;
}
use of com.intellij.psi.impl.java.stubs.PsiFieldStub in project intellij-community by JetBrains.
the class PsiFieldImpl method getType.
@Override
@NotNull
@SuppressWarnings("Duplicates")
public PsiType getType() {
PsiFieldStub stub = getStub();
if (stub != null) {
PsiType type = SoftReference.dereference(myCachedType);
if (type == null) {
String typeText = TypeInfo.createTypeText(stub.getType(false));
assert typeText != null : stub;
type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this);
type = JavaSharedImplUtil.applyAnnotations(type, getModifierList());
myCachedType = new SoftReference<>(type);
}
return type;
}
myCachedType = null;
PsiTypeElement typeElement = getTypeElement();
assert typeElement != null : Arrays.toString(getChildren());
return JavaSharedImplUtil.getType(typeElement, getNameIdentifier());
}
use of com.intellij.psi.impl.java.stubs.PsiFieldStub in project intellij-community by JetBrains.
the class PsiFieldImpl method findFirstFieldInDeclaration.
private PsiField findFirstFieldInDeclaration() {
if (getSelfModifierList() != null)
return this;
final PsiFieldStub stub = getGreenStub();
if (stub != null) {
final List siblings = stub.getParentStub().getChildrenStubs();
final int idx = siblings.indexOf(stub);
assert idx >= 0;
for (int i = idx - 1; i >= 0; i--) {
if (!(siblings.get(i) instanceof PsiFieldStub))
break;
PsiFieldStub prevField = (PsiFieldStub) siblings.get(i);
final PsiFieldImpl prevFieldPsi = (PsiFieldImpl) prevField.getPsi();
if (prevFieldPsi.getSelfModifierList() != null)
return prevFieldPsi;
}
}
return findFirstFieldByTree();
}
Aggregations