Search in sources :

Example 26 with LighterASTNode

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

the class ContractInferenceInterpreter method resolveParameter.

private int resolveParameter(@Nullable LighterASTNode expr) {
    if (expr != null && expr.getTokenType() == REFERENCE_EXPRESSION && findExpressionChild(myTree, expr) == null) {
        String name = JavaLightTreeUtil.getNameIdentifierText(myTree, expr);
        if (name == null)
            return -1;
        List<LighterASTNode> parameters = getParameters();
        for (int i = 0; i < parameters.size(); i++) {
            if (name.equals(JavaLightTreeUtil.getNameIdentifierText(myTree, parameters.get(i)))) {
                return i;
            }
        }
    }
    return -1;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) ValueConstraint(com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint)

Example 27 with LighterASTNode

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

the class JavaNullMethodArgumentIndex method getNullParameterIndices.

@Nullable
private static IntArrayList getNullParameterIndices(LighterAST lighterAst, @NotNull LighterASTNode methodCall) {
    final LighterASTNode node = LightTreeUtil.firstChildOfType(lighterAst, methodCall, EXPRESSION_LIST);
    if (node == null)
        return null;
    final List<LighterASTNode> parameters = JavaLightTreeUtil.getExpressionChildren(lighterAst, node);
    IntArrayList indices = new IntArrayList(1);
    for (int idx = 0; idx < parameters.size(); idx++) {
        if (isNullLiteral(lighterAst, parameters.get(idx))) {
            indices.add(idx);
        }
    }
    return indices;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) IntArrayList(com.intellij.util.containers.IntArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with LighterASTNode

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

the class JavaFunctionalExpressionIndex method createChainStart.

@Nullable
private static ReferenceChainLink createChainStart(FileLocalResolver resolver, LighterASTNode expr, boolean isCall, String referenceName) {
    if (!isCall) {
        FileLocalResolver.LightResolveResult result = resolver.resolveLocally(expr);
        if (result == FileLocalResolver.LightResolveResult.UNKNOWN)
            return null;
        LighterASTNode target = result.getTarget();
        if (target != null) {
            String typeName = resolver.getShortClassTypeName(target);
            return typeName != null ? new ReferenceChainLink(typeName, false, -1) : null;
        }
    }
    return new ReferenceChainLink(referenceName, isCall, getArgCount(resolver.getLightTree(), expr));
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) FileLocalResolver(com.intellij.psi.impl.source.FileLocalResolver) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with LighterASTNode

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

the class JavaFunctionalExpressionIndex method getQualifier.

@Nullable
private static LighterASTNode getQualifier(LighterAST tree, LighterASTNode expr, boolean isCall) {
    LighterASTNode qualifier = tree.getChildren(expr).get(0);
    if (isCall) {
        List<LighterASTNode> children = tree.getChildren(qualifier);
        qualifier = children.isEmpty() ? null : children.get(0);
    }
    return qualifier != null && ElementType.EXPRESSION_BIT_SET.contains(qualifier.getTokenType()) ? qualifier : null;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with LighterASTNode

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

the class JavaFunctionalExpressionIndex method createOccurrence.

@NotNull
private static FunExprOccurrence createOccurrence(@NotNull LighterASTNode funExpr, FileLocalResolver resolver) {
    LighterAST tree = resolver.getLightTree();
    LighterASTNode containingCall = getContainingCall(tree, funExpr);
    List<LighterASTNode> args = JavaLightTreeUtil.getArgList(tree, containingCall);
    int argIndex = args == null ? -1 : getArgIndex(args, funExpr);
    LighterASTNode chainExpr = containingCall;
    if (chainExpr == null) {
        LighterASTNode assignment = skipExpressionsUp(tree, funExpr, TokenSet.create(ASSIGNMENT_EXPRESSION));
        if (assignment != null) {
            chainExpr = findExpressionChild(assignment, tree);
        }
    }
    return new FunExprOccurrence(funExpr.getStartOffset(), argIndex, createCallChain(resolver, chainExpr));
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) LighterAST(com.intellij.lang.LighterAST) NotNull(org.jetbrains.annotations.NotNull)

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