Search in sources :

Example 1 with PsiFieldStub

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();
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiFieldStub(com.intellij.psi.impl.java.stubs.PsiFieldStub) ASTNode(com.intellij.lang.ASTNode)

Example 2 with PsiFieldStub

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;
}
Also used : PsiFieldStub(com.intellij.psi.impl.java.stubs.PsiFieldStub) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 3 with PsiFieldStub

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());
}
Also used : PsiFieldStub(com.intellij.psi.impl.java.stubs.PsiFieldStub) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiFieldStub

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();
}
Also used : PsiFieldStub(com.intellij.psi.impl.java.stubs.PsiFieldStub)

Aggregations

PsiFieldStub (com.intellij.psi.impl.java.stubs.PsiFieldStub)4 ASTNode (com.intellij.lang.ASTNode)1 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1