Search in sources :

Example 31 with LighterASTNode

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

the class JavaFunctionalExpressionIndex method calcExprType.

@NotNull
private static String calcExprType(LighterASTNode funExpr, FileLocalResolver resolver) {
    LighterASTNode scope = skipExpressionsUp(resolver.getLightTree(), funExpr, TokenSet.create(LOCAL_VARIABLE, FIELD, TYPE_CAST_EXPRESSION, RETURN_STATEMENT, ASSIGNMENT_EXPRESSION));
    if (scope != null) {
        if (scope.getTokenType() == ASSIGNMENT_EXPRESSION) {
            LighterASTNode lValue = findExpressionChild(scope, resolver.getLightTree());
            scope = lValue == null ? null : resolver.resolveLocally(lValue).getTarget();
        } else if (scope.getTokenType() == RETURN_STATEMENT) {
            scope = LightTreeUtil.getParentOfType(resolver.getLightTree(), scope, TokenSet.create(METHOD), TokenSet.orSet(ElementType.MEMBER_BIT_SET, TokenSet.create(LAMBDA_EXPRESSION)));
        }
    }
    return StringUtil.notNullize(scope == null ? null : resolver.getShortClassTypeName(scope));
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with LighterASTNode

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

the class PropertyStubElementType method createStub.

@Override
public PropertyStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
    LighterASTNode keyNode = LightTreeUtil.firstChildOfType(tree, node, PropertiesTokenTypes.KEY_CHARACTERS);
    String key = intern(tree.getCharTable(), keyNode);
    return new PropertyStubImpl(parentStub, key);
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) PropertyStubImpl(com.intellij.lang.properties.psi.impl.PropertyStubImpl)

Example 33 with LighterASTNode

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

the class TypeInfo method create.

@NotNull
public static TypeInfo create(@NotNull LighterAST tree, @NotNull LighterASTNode element, StubElement parentStub) {
    String text;
    byte arrayCount = 0;
    boolean isEllipsis = false;
    if (element.getTokenType() == JavaElementType.ENUM_CONSTANT) {
        text = ((PsiClassStub) parentStub).getName();
    } else {
        LighterASTNode typeElement = null;
        for (final LighterASTNode child : tree.getChildren(element)) {
            IElementType type = child.getTokenType();
            if (type == JavaElementType.TYPE) {
                typeElement = child;
            } else if (type == JavaTokenType.LBRACKET) {
                // C-style array
                arrayCount++;
            }
        }
        if (typeElement == null && element.getTokenType() == JavaElementType.FIELD) {
            LighterASTNode parent = tree.getParent(element);
            assert parent != null : element;
            List<LighterASTNode> fields = LightTreeUtil.getChildrenOfType(tree, parent, JavaElementType.FIELD);
            int idx = fields.indexOf(element);
            for (int i = idx - 1; i >= 0 && typeElement == null; i--) {
                // int i, j
                typeElement = LightTreeUtil.firstChildOfType(tree, fields.get(i), JavaElementType.TYPE);
            }
        }
        assert typeElement != null : element + " in " + parentStub;
        isEllipsis = LightTreeUtil.firstChildOfType(tree, typeElement, JavaTokenType.ELLIPSIS) != null;
        while (true) {
            LighterASTNode nested = LightTreeUtil.firstChildOfType(tree, typeElement, JavaElementType.TYPE);
            if (nested == null)
                break;
            typeElement = nested;
            // Java-style array
            arrayCount++;
        }
        text = LightTreeUtil.toFilteredString(tree, typeElement, null);
    }
    return new TypeInfo(text, arrayCount, isEllipsis, PsiAnnotationStub.EMPTY_ARRAY);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with LighterASTNode

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

the class JavaClassElementType method createStub.

@Override
public PsiClassStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
    boolean isDeprecatedByComment = false;
    boolean isInterface = false;
    boolean isEnum = false;
    boolean isEnumConst = false;
    boolean isAnonymous = false;
    boolean isAnnotation = false;
    boolean isInQualifiedNew = false;
    boolean hasDeprecatedAnnotation = false;
    String qualifiedName = null;
    String name = null;
    String baseRef = null;
    if (node.getTokenType() == JavaElementType.ANONYMOUS_CLASS) {
        isAnonymous = true;
    } else if (node.getTokenType() == JavaElementType.ENUM_CONSTANT_INITIALIZER) {
        isAnonymous = isEnumConst = true;
        baseRef = ((PsiClassStub) parentStub.getParentStub()).getName();
    }
    for (final LighterASTNode child : tree.getChildren(node)) {
        final IElementType type = child.getTokenType();
        if (type == JavaDocElementType.DOC_COMMENT) {
            isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
        } else if (type == JavaElementType.MODIFIER_LIST) {
            hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
        } else if (type == JavaTokenType.AT) {
            isAnnotation = true;
        } else if (type == JavaTokenType.INTERFACE_KEYWORD) {
            isInterface = true;
        } else if (type == JavaTokenType.ENUM_KEYWORD) {
            isEnum = true;
        } else if (!isAnonymous && type == JavaTokenType.IDENTIFIER) {
            name = RecordUtil.intern(tree.getCharTable(), child);
        } else if (isAnonymous && !isEnumConst && type == JavaElementType.JAVA_CODE_REFERENCE) {
            baseRef = LightTreeUtil.toFilteredString(tree, child, null);
        }
    }
    if (name != null) {
        if (parentStub instanceof PsiJavaFileStub) {
            final String pkg = ((PsiJavaFileStub) parentStub).getPackageName();
            if (!pkg.isEmpty())
                qualifiedName = pkg + '.' + name;
            else
                qualifiedName = name;
        } else if (parentStub instanceof PsiClassStub) {
            final String parentFqn = ((PsiClassStub) parentStub).getQualifiedName();
            qualifiedName = parentFqn != null ? parentFqn + '.' + name : null;
        }
    }
    if (isAnonymous) {
        final LighterASTNode parent = tree.getParent(node);
        if (parent != null && parent.getTokenType() == JavaElementType.NEW_EXPRESSION) {
            isInQualifiedNew = (LightTreeUtil.firstChildOfType(tree, parent, JavaTokenType.DOT) != null);
        }
    }
    final byte flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation, isInQualifiedNew, hasDeprecatedAnnotation);
    final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
    return new PsiClassStubImpl(type, parentStub, qualifiedName, name, baseRef, flags);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiClassStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl) LighterASTNode(com.intellij.lang.LighterASTNode)

Example 35 with LighterASTNode

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

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