use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaNullMethodArgumentIndex method findCallsWithNulls.
@NotNull
private static Set<LighterASTNode> findCallsWithNulls(LighterAST lighterAst, int[] nullOffsets) {
Set<LighterASTNode> calls = new HashSet<>();
for (int offset : nullOffsets) {
LighterASTNode leaf = LightTreeUtil.findLeafElementAt(lighterAst, offset);
LighterASTNode literal = leaf == null ? null : lighterAst.getParent(leaf);
if (isNullLiteral(lighterAst, literal)) {
LighterASTNode exprList = lighterAst.getParent(literal);
if (exprList != null && exprList.getTokenType() == EXPRESSION_LIST) {
ContainerUtil.addIfNotNull(calls, LightTreeUtil.getParentOfType(lighterAst, exprList, CALL_TYPES, ElementType.MEMBER_BIT_SET));
}
}
}
return calls;
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaFunctionalExpressionIndex method getCalledMethodName.
@Nullable
private static String getCalledMethodName(LighterAST tree, LighterASTNode call) {
if (call.getTokenType() == NEW_EXPRESSION) {
LighterASTNode anonClass = LightTreeUtil.firstChildOfType(tree, call, ANONYMOUS_CLASS);
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, anonClass != null ? anonClass : call, JAVA_CODE_REFERENCE);
return ref == null ? null : JavaLightTreeUtil.getNameIdentifierText(tree, ref);
}
LighterASTNode methodExpr = tree.getChildren(call).get(0);
if (LightTreeUtil.firstChildOfType(tree, methodExpr, JavaTokenType.SUPER_KEYWORD) != null) {
return getSuperClassName(tree, call);
}
if (LightTreeUtil.firstChildOfType(tree, methodExpr, JavaTokenType.THIS_KEYWORD) != null) {
return JavaLightTreeUtil.getNameIdentifierText(tree, findClass(tree, call));
}
return JavaLightTreeUtil.getNameIdentifierText(tree, methodExpr);
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaFunctionalExpressionIndex method createCallChain.
@NotNull
private static List<ReferenceChainLink> createCallChain(FileLocalResolver resolver, @Nullable LighterASTNode expr) {
List<ReferenceChainLink> chain = new ArrayList<>();
while (true) {
if (expr == null)
return reversedChain(chain);
if (expr.getTokenType() == PARENTH_EXPRESSION) {
expr = LightTreeUtil.firstChildOfType(resolver.getLightTree(), expr, ElementType.EXPRESSION_BIT_SET);
continue;
}
if (expr.getTokenType() == TYPE_CAST_EXPRESSION) {
String typeName = resolver.getShortClassTypeName(expr);
ContainerUtil.addIfNotNull(chain, typeName != null ? new ReferenceChainLink(typeName, false, -1) : null);
return reversedChain(chain);
}
boolean isCall = expr.getTokenType() == METHOD_CALL_EXPRESSION || expr.getTokenType() == NEW_EXPRESSION;
String referenceName = getReferencedMemberName(resolver.getLightTree(), expr, isCall);
if (referenceName == null)
return reversedChain(chain);
LighterASTNode qualifier = getQualifier(resolver.getLightTree(), expr, isCall);
if (qualifier == null) {
ContainerUtil.addIfNotNull(chain, createChainStart(resolver, expr, isCall, referenceName));
return reversedChain(chain);
}
chain.add(new ReferenceChainLink(referenceName, isCall, getArgCount(resolver.getLightTree(), expr)));
expr = qualifier;
}
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaFunctionalExpressionIndex method calcReturnType.
private static FunctionalExpressionKey.CoarseType calcReturnType(final LighterAST tree, LighterASTNode funExpr) {
if (funExpr.getTokenType() == METHOD_REF_EXPRESSION)
return FunctionalExpressionKey.CoarseType.UNKNOWN;
LighterASTNode block = LightTreeUtil.firstChildOfType(tree, funExpr, CODE_BLOCK);
if (block == null) {
LighterASTNode expr = findExpressionChild(funExpr, tree);
return isBooleanExpression(tree, expr) ? FunctionalExpressionKey.CoarseType.BOOLEAN : FunctionalExpressionKey.CoarseType.UNKNOWN;
}
final Ref<Boolean> returnsSomething = Ref.create(null);
final AtomicBoolean isBoolean = new AtomicBoolean();
final AtomicBoolean hasStatements = new AtomicBoolean();
new RecursiveLighterASTNodeWalkingVisitor(tree) {
@Override
public void visitNode(@NotNull LighterASTNode element) {
IElementType type = element.getTokenType();
if (type == LAMBDA_EXPRESSION || ElementType.MEMBER_BIT_SET.contains(type)) {
return;
}
if (type == RETURN_STATEMENT) {
LighterASTNode expr = findExpressionChild(element, tree);
returnsSomething.set(expr != null);
if (isBooleanExpression(tree, expr)) {
isBoolean.set(true);
}
return;
}
if (type == EXPRESSION_STATEMENT) {
hasStatements.set(true);
}
super.visitNode(element);
}
}.visitNode(block);
if (isBoolean.get()) {
return FunctionalExpressionKey.CoarseType.BOOLEAN;
}
if (returnsSomething.isNull()) {
return hasStatements.get() ? FunctionalExpressionKey.CoarseType.VOID : FunctionalExpressionKey.CoarseType.UNKNOWN;
}
return returnsSomething.get() ? FunctionalExpressionKey.CoarseType.NON_VOID : FunctionalExpressionKey.CoarseType.VOID;
}
use of com.intellij.lang.LighterASTNode in project Perl5-IDEA by Camelcade.
the class TemplateToolkitParserUtil method parseTryCatchBlock.
public static boolean parseTryCatchBlock(PsiBuilder b, int l, PsiBuilder.Marker branchMarker, IElementType branchTokenType) {
while (!b.eof()) {
PsiBuilder.Marker currentMarker = b.mark();
if (TemplateToolkitParser.element(b, l)) {
LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
if (latestDoneMarker != null) {
if (latestDoneMarker.getTokenType() == END_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
currentMarker.drop();
branchMarker = null;
break;
} else if (latestDoneMarker.getTokenType() == CATCH_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = CATCH_BRANCH;
} else if (latestDoneMarker.getTokenType() == FINAL_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = FINAL_BRANCH;
} else {
currentMarker.error(PerlBundle.message("ttk2.catch.final.end.expected"));
}
currentMarker.drop();
}
} else {
b.advanceLexer();
currentMarker.error(PerlBundle.message("ttk2.unexpected.token"));
}
}
if (branchMarker != null) {
branchMarker.done(branchTokenType);
branchMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.block.directive"));
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
}
return true;
}
Aggregations