Search in sources :

Example 36 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.

the class JavaImportStatementElementType method createStub.

@Override
public PsiImportStatementStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
    boolean isOnDemand = false;
    String refText = null;
    for (LighterASTNode child : tree.getChildren(node)) {
        IElementType type = child.getTokenType();
        if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) {
            refText = JavaSourceUtil.getReferenceText(tree, child);
        } else if (type == JavaTokenType.ASTERISK) {
            isOnDemand = true;
        }
    }
    byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT);
    return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode) PsiImportStatementStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl)

Example 37 with LighterASTNode

use of com.intellij.lang.LighterASTNode 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)

Example 38 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.

the class JavaNameValuePairType method createStub.

@Override
public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
    String name = null;
    String value = null;
    List<LighterASTNode> children = tree.getChildren(node);
    for (LighterASTNode child : children) {
        if (child.getTokenType() == JavaTokenType.IDENTIFIER) {
            name = RecordUtil.intern(tree.getCharTable(), child);
        } else if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getTokenType())) {
            value = LightTreeUtil.toFilteredString(tree, child, null);
        }
    }
    return new PsiNameValuePairStubImpl(parentStub, name, value);
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) PsiNameValuePairStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiNameValuePairStubImpl)

Example 39 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.

the class JavaProvidesStatementElementType method createStub.

@Override
public PsiProvidesStatementStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
    LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
    String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
    return new PsiProvidesStatementStubImpl(parentStub, refText);
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) PsiProvidesStatementStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiProvidesStatementStubImpl)

Example 40 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.

the class JavaTypeParameterElementType method createStub.

@Override
public PsiTypeParameterStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
    final LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
    final String name = RecordUtil.intern(tree.getCharTable(), id);
    return new PsiTypeParameterStubImpl(parentStub, StringRef.fromString(name));
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) PsiTypeParameterStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterStubImpl)

Aggregations

LighterASTNode (com.intellij.lang.LighterASTNode)48 IElementType (com.intellij.psi.tree.IElementType)14 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)11 PsiBuilder (com.intellij.lang.PsiBuilder)6 LighterAST (com.intellij.lang.LighterAST)4 ValueConstraint (com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint)3 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)3 SmartList (com.intellij.util.SmartList)3 JavaTokenType (com.intellij.psi.JavaTokenType)2 JavaLightTreeUtil (com.intellij.psi.impl.source.JavaLightTreeUtil)2 JavaLightTreeUtil.findExpressionChild (com.intellij.psi.impl.source.JavaLightTreeUtil.findExpressionChild)2 JavaLightTreeUtil.getExpressionChildren (com.intellij.psi.impl.source.JavaLightTreeUtil.getExpressionChildren)2 ElementType (com.intellij.psi.impl.source.tree.ElementType)2 JavaElementType (com.intellij.psi.impl.source.tree.JavaElementType)2 LightTreeUtil.firstChildOfType (com.intellij.psi.impl.source.tree.LightTreeUtil.firstChildOfType)2 LightTreeUtil.getChildrenOfType (com.intellij.psi.impl.source.tree.LightTreeUtil.getChildrenOfType)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1