Search in sources :

Example 6 with TypeInfo

use of com.intellij.psi.impl.cache.TypeInfo in project intellij-community by JetBrains.

the class JavaFieldStubElementType method createStub.

@Override
public PsiFieldStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
    final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
    boolean isDeprecatedByComment = false;
    boolean hasDeprecatedAnnotation = false;
    boolean hasDocComment = false;
    String name = null;
    String initializer = null;
    boolean expectingInit = false;
    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) {
            hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
        } else if (type == JavaTokenType.IDENTIFIER) {
            name = RecordUtil.intern(tree.getCharTable(), child);
        } else if (type == JavaTokenType.EQ) {
            expectingInit = true;
        } else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
            initializer = encodeInitializer(tree, child);
            break;
        }
    }
    final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT;
    final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
    return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode) PsiFieldStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiFieldStubImpl) TypeInfo(com.intellij.psi.impl.cache.TypeInfo)

Example 7 with TypeInfo

use of com.intellij.psi.impl.cache.TypeInfo in project intellij-community by JetBrains.

the class JavaMethodElementType method indexStub.

@Override
public void indexStub(@NotNull final PsiMethodStub stub, @NotNull final IndexSink sink) {
    final String name = stub.getName();
    if (name != null) {
        sink.occurrence(JavaStubIndexKeys.METHODS, name);
        if (RecordUtil.isStaticNonPrivateMember(stub)) {
            sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
            sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getReturnTypeText(false).getShortTypeText());
        }
    }
    Set<String> methodTypeParams = getVisibleTypeParameters(stub);
    for (StubElement stubElement : stub.getChildrenStubs()) {
        if (stubElement instanceof PsiParameterListStub) {
            for (StubElement paramStub : ((PsiParameterListStub) stubElement).getChildrenStubs()) {
                if (paramStub instanceof PsiParameterStub) {
                    TypeInfo type = ((PsiParameterStub) paramStub).getType(false);
                    String typeName = PsiNameHelper.getShortClassName(type.text);
                    if (TypeConversionUtil.isPrimitive(typeName) || TypeConversionUtil.isPrimitiveWrapper(typeName))
                        continue;
                    sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, typeName);
                    if (typeName.equals(type.text) && (type.arrayCount == 0 || type.arrayCount == 1 && type.isEllipsis) && methodTypeParams.contains(typeName)) {
                        sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, TYPE_PARAMETER_PSEUDO_NAME);
                    }
                }
            }
            break;
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) TypeInfo(com.intellij.psi.impl.cache.TypeInfo)

Example 8 with TypeInfo

use of com.intellij.psi.impl.cache.TypeInfo in project intellij-community by JetBrains.

the class JavaMethodElementType method deserialize.

@NotNull
@Override
public PsiMethodStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
    StringRef name = dataStream.readName();
    final TypeInfo type = TypeInfo.readTYPE(dataStream);
    byte flags = dataStream.readByte();
    final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null;
    return new PsiMethodStubImpl(parentStub, StringRef.toString(name), type, flags, StringRef.toString(defaultMethodValue));
}
Also used : PsiMethodStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl) StringRef(com.intellij.util.io.StringRef) TypeInfo(com.intellij.psi.impl.cache.TypeInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with TypeInfo

use of com.intellij.psi.impl.cache.TypeInfo in project intellij-community by JetBrains.

the class JavaMethodElementType method createStub.

@Override
public PsiMethodStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
    String name = null;
    boolean isConstructor = true;
    boolean isVarArgs = false;
    boolean isDeprecatedByComment = false;
    boolean hasDeprecatedAnnotation = false;
    boolean hasDocComment = false;
    String defValueText = null;
    boolean expectingDef = false;
    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) {
            hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
        } else if (type == JavaElementType.TYPE) {
            isConstructor = false;
        } else if (type == JavaTokenType.IDENTIFIER) {
            name = RecordUtil.intern(tree.getCharTable(), child);
        } else if (type == JavaElementType.PARAMETER_LIST) {
            final List<LighterASTNode> params = LightTreeUtil.getChildrenOfType(tree, child, JavaElementType.PARAMETER);
            if (!params.isEmpty()) {
                final LighterASTNode pType = LightTreeUtil.firstChildOfType(tree, params.get(params.size() - 1), JavaElementType.TYPE);
                if (pType != null) {
                    isVarArgs = (LightTreeUtil.firstChildOfType(tree, pType, JavaTokenType.ELLIPSIS) != null);
                }
            }
        } else if (type == JavaTokenType.DEFAULT_KEYWORD) {
            expectingDef = true;
        } else if (expectingDef && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON && type != JavaElementType.CODE_BLOCK) {
            defValueText = LightTreeUtil.toFilteredString(tree, child, null);
            break;
        }
    }
    TypeInfo typeInfo = isConstructor ? TypeInfo.createConstructorType() : TypeInfo.create(tree, node, parentStub);
    boolean isAnno = (node.getTokenType() == JavaElementType.ANNOTATION_METHOD);
    byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
    return new PsiMethodStubImpl(parentStub, name, typeInfo, flags, defValueText);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode) PsiMethodStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl) TypeInfo(com.intellij.psi.impl.cache.TypeInfo)

Aggregations

TypeInfo (com.intellij.psi.impl.cache.TypeInfo)9 LighterASTNode (com.intellij.lang.LighterASTNode)3 StringRef (com.intellij.util.io.StringRef)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiFieldStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiFieldStubImpl)2 PsiMethodStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl)2 PsiParameterStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl)2 IElementType (com.intellij.psi.tree.IElementType)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)1 StubElement (com.intellij.psi.stubs.StubElement)1 ClsFormatException (com.intellij.util.cls.ClsFormatException)1 IOException (java.io.IOException)1