use of org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr in project drools by kiegroup.
the class ExpressionTyper method toTypedExpressionRec.
private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
Class<?> typeCursor = patternType;
if (drlxExpr instanceof FullyQualifiedInlineCastExpr) {
return toTypedExpressionRec(transformFullyQualifiedInlineCastExpr(ruleContext.getTypeResolver(), (FullyQualifiedInlineCastExpr) drlxExpr));
}
if (drlxExpr instanceof EnclosedExpr) {
Expression inner = ((EnclosedExpr) drlxExpr).getInner();
Optional<TypedExpression> typedExpression = toTypedExpressionRec(inner);
return typedExpression.map(t -> t.cloneWithNewExpression(new EnclosedExpr(t.getExpression())));
}
if (drlxExpr instanceof MethodCallExpr) {
MethodCallExpr methodExpr = (MethodCallExpr) drlxExpr;
Expression expr = methodExpr;
if (isEval(methodExpr.getNameAsString(), methodExpr.getScope(), methodExpr.getArguments())) {
expr = methodExpr.getArgument(0);
}
drlxExpr = expr;
}
if (drlxExpr instanceof NullSafeMethodCallExpr) {
NullSafeMethodCallExpr methodExpr = (NullSafeMethodCallExpr) drlxExpr;
Expression expr = methodExpr;
if (isEval(methodExpr.getNameAsString(), methodExpr.getScope(), methodExpr.getArguments())) {
expr = methodExpr.getArgument(0);
}
drlxExpr = expr;
}
if (drlxExpr instanceof UnaryExpr) {
UnaryExpr unaryExpr = (UnaryExpr) drlxExpr;
Optional<TypedExpression> optTypedExpr = toTypedExpressionRec(unaryExpr.getExpression());
return optTypedExpr.map(typedExpr -> new TypedExpression(new UnaryExpr(typedExpr.getExpression(), unaryExpr.getOperator()), typedExpr.getType()));
}
if (drlxExpr instanceof BinaryExpr) {
BinaryExpr binaryExpr = (BinaryExpr) drlxExpr;
BinaryExpr.Operator operator = binaryExpr.getOperator();
Optional<TypedExpression> optLeft = toTypedExpressionRec(binaryExpr.getLeft());
Optional<TypedExpression> optRight = toTypedExpressionRec(binaryExpr.getRight());
return optLeft.flatMap(left -> optRight.flatMap(right -> {
final BinaryExpr combo = new BinaryExpr(left.getExpression(), right.getExpression(), operator);
return of(new TypedExpression(combo, left.getType()));
}));
}
if (drlxExpr instanceof HalfBinaryExpr) {
final Expression binaryExpr = trasformHalfBinaryToBinary(drlxExpr);
if (binaryExpr instanceof BinaryExpr && ((BinaryExpr) binaryExpr).getLeft() == drlxExpr) {
throw new CannotTypeExpressionException("left leaf is the same : drlxExpr = " + drlxExpr + ", originalExpression = " + context.getOriginalExpression());
}
return toTypedExpressionRec(binaryExpr);
}
if (drlxExpr instanceof LiteralExpr) {
drlxExpr = normalizeDigit(drlxExpr);
return of(new TypedExpression(drlxExpr, getLiteralExpressionType((LiteralExpr) drlxExpr)));
}
if (drlxExpr instanceof ThisExpr || (drlxExpr instanceof NameExpr && THIS_PLACEHOLDER.equals(printNode(drlxExpr)))) {
return of(new TypedExpression(new NameExpr(THIS_PLACEHOLDER), patternType));
}
if (drlxExpr instanceof CastExpr) {
CastExpr castExpr = (CastExpr) drlxExpr;
Optional<TypedExpression> optTypedExpr = toTypedExpressionRec(castExpr.getExpression());
return optTypedExpr.map(typedExpr -> new TypedExpression(new CastExpr(castExpr.getType(), typedExpr.getExpression()), getClassFromContext(ruleContext.getTypeResolver(), castExpr.getType().asString())));
}
if (drlxExpr instanceof NameExpr) {
return nameExpr(((NameExpr) drlxExpr).getNameAsString(), typeCursor);
}
if (drlxExpr instanceof FieldAccessExpr || drlxExpr instanceof MethodCallExpr || drlxExpr instanceof ObjectCreationExpr || drlxExpr instanceof NullSafeFieldAccessExpr || drlxExpr instanceof NullSafeMethodCallExpr || drlxExpr instanceof MapCreationLiteralExpression || drlxExpr instanceof ListCreationLiteralExpression) {
return toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
}
if (drlxExpr instanceof PointFreeExpr) {
final PointFreeExpr pointFreeExpr = (PointFreeExpr) drlxExpr;
Optional<TypedExpression> optLeft = toTypedExpressionRec(pointFreeExpr.getLeft());
Optional<TypedExpression> optRight = pointFreeExpr.getRight().size() == 1 ? toTypedExpressionRec(pointFreeExpr.getRight().get(0)) : Optional.empty();
OperatorSpec opSpec = getOperatorSpec(pointFreeExpr.getRight(), pointFreeExpr.getOperator());
return optLeft.map(left -> new TypedExpression(opSpec.getExpression(ruleContext, pointFreeExpr, left, this), left.getType()).setStatic(opSpec.isStatic()).setLeft(left).setRight(optRight.orElse(null)));
}
if (drlxExpr instanceof HalfPointFreeExpr) {
final HalfPointFreeExpr halfPointFreeExpr = (HalfPointFreeExpr) drlxExpr;
Expression parentLeft = findLeftLeafOfNameExprTraversingParent(halfPointFreeExpr);
if (parentLeft == halfPointFreeExpr) {
throw new CannotTypeExpressionException("left leaf is the same : halfPointFreeExpr = " + halfPointFreeExpr + ", originalExpression = " + context.getOriginalExpression());
}
Optional<TypedExpression> optLeft = toTypedExpressionRec(parentLeft);
OperatorSpec opSpec = getOperatorSpec(halfPointFreeExpr.getRight(), halfPointFreeExpr.getOperator());
final PointFreeExpr transformedToPointFree = new PointFreeExpr(halfPointFreeExpr.getTokenRange().orElseThrow(() -> new IllegalStateException("Token range is not present!")), parentLeft, halfPointFreeExpr.getRight(), halfPointFreeExpr.getOperator(), halfPointFreeExpr.isNegated(), halfPointFreeExpr.getArg1(), halfPointFreeExpr.getArg2(), halfPointFreeExpr.getArg3(), halfPointFreeExpr.getArg4());
return optLeft.map(left -> new TypedExpression(opSpec.getExpression(ruleContext, transformedToPointFree, left, this), left.getType()).setStatic(opSpec.isStatic()).setLeft(left));
}
if (drlxExpr instanceof ArrayAccessExpr) {
final ArrayAccessExpr arrayAccessExpr = (ArrayAccessExpr) drlxExpr;
if (Map.class.isAssignableFrom(typeCursor)) {
return createMapAccessExpression(arrayAccessExpr.getIndex(), arrayAccessExpr.getName() instanceof ThisExpr ? new NameExpr(THIS_PLACEHOLDER) : arrayAccessExpr.getName(), Map.class);
} else if (arrayAccessExpr.getName() instanceof FieldAccessExpr) {
Optional<TypedExpression> typedExpression = toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
typedExpression.ifPresent(te -> {
final Expression originalExpression = te.getExpression();
DrlxParseUtil.removeRootNode(originalExpression);
});
return typedExpression;
} else {
String name = printNode(drlxExpr.asArrayAccessExpr().getName());
final Optional<TypedExpression> nameExpr = nameExpr(name, typeCursor);
Expression indexExpr = toTypedExpressionFromMethodCallOrField(arrayAccessExpr.getIndex()).getTypedExpression().orElseThrow(() -> new NoSuchElementException("TypedExpressionResult doesn't contain TypedExpression!")).getExpression();
return nameExpr.flatMap(te -> transformToArrayOrMapExpressionWithType(indexExpr, te));
}
}
if (drlxExpr instanceof InstanceOfExpr) {
InstanceOfExpr instanceOfExpr = (InstanceOfExpr) drlxExpr;
ruleContext.addInlineCastType(printNode(instanceOfExpr.getExpression()), instanceOfExpr.getType());
return toTypedExpressionRec(instanceOfExpr.getExpression()).map(e -> new TypedExpression(new InstanceOfExpr(e.getExpression(), instanceOfExpr.getType()), boolean.class));
}
if (drlxExpr instanceof ClassExpr) {
return of(new TypedExpression(drlxExpr, Class.class));
}
if (drlxExpr instanceof InlineCastExpr) {
return toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
}
if (drlxExpr instanceof OOPathExpr) {
Class<?> type = patternType;
for (OOPathChunk chunk : ((OOPathExpr) drlxExpr).getChunks()) {
final String fieldName = chunk.getField().toString();
final TypedExpression callExpr = DrlxParseUtil.nameExprToMethodCallExpr(fieldName, type, null, ruleContext);
if (callExpr == null) {
return empty();
}
Class<?> fieldType = (chunk.getInlineCast() != null) ? DrlxParseUtil.getClassFromContext(ruleContext.getTypeResolver(), chunk.getInlineCast().toString()) : callExpr.getRawClass();
if (!chunk.isSingleValue() && Iterable.class.isAssignableFrom(fieldType) || isDataSource(fieldType)) {
type = extractGenericType(type, ((MethodCallExpr) callExpr.getExpression()).getName().toString());
} else {
type = fieldType;
}
}
return of(new TypedExpression(drlxExpr, type));
}
if (drlxExpr.isAssignExpr()) {
AssignExpr assignExpr = drlxExpr.asAssignExpr();
final Expression rightSide = assignExpr.getValue();
return toTypedExpressionRec(rightSide).map(e -> {
final AssignExpr newExpression = new AssignExpr(assignExpr.getTarget(), e.getExpression(), assignExpr.getOperator());
return new TypedExpression(newExpression, e.getType());
});
}
throw new UnsupportedOperationException();
}
use of org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisComplexOnNullSafeField.
@Test
public void testAndWithImplicitParameterAndParenthesisComplexOnNullSafeField() {
String expr = "value!.length ((> 1 && < 2) || (> 3 && < 4))";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.OR, comboExpr.getOperator());
BinaryExpr comboExprLeft = ((BinaryExpr) comboExpr.getLeft());
assertEquals(Operator.AND, comboExprLeft.getOperator());
BinaryExpr first = (BinaryExpr) comboExprLeft.getLeft();
assertTrue(first.getLeft() instanceof NullSafeFieldAccessExpr);
assertEquals("value!.length", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExprLeft.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
BinaryExpr comboExprRight = ((BinaryExpr) comboExpr.getRight());
assertEquals(Operator.AND, comboExprRight.getOperator());
BinaryExpr third = (BinaryExpr) comboExprRight.getLeft();
assertEquals("value!.length", toString(third.getLeft()));
assertEquals("3", toString(third.getRight()));
assertEquals(Operator.GREATER, third.getOperator());
HalfBinaryExpr forth = (HalfBinaryExpr) comboExprRight.getRight();
assertEquals("4", toString(forth.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, forth.getOperator());
}
use of org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr in project drools by kiegroup.
the class ExpressionTyper method processFirstNode.
private Optional<TypedExpressionCursor> processFirstNode(Expression drlxExpr, List<Node> childNodes, Node firstNode, boolean isInLineCast, java.lang.reflect.Type originalTypeCursor) {
Optional<TypedExpressionCursor> result;
if (isThisExpression(firstNode) || (firstNode instanceof DrlNameExpr && printNode(firstNode).equals(bindingId))) {
result = of(thisExpr(drlxExpr, childNodes, isInLineCast, originalTypeCursor));
} else if (firstNode instanceof DrlNameExpr) {
result = drlNameExpr(drlxExpr, (DrlNameExpr) firstNode, isInLineCast, originalTypeCursor);
} else if (firstNode instanceof NameExpr) {
result = drlNameExpr(drlxExpr, new DrlNameExpr(((NameExpr) firstNode).getName()), isInLineCast, originalTypeCursor);
} else if (firstNode instanceof FieldAccessExpr) {
if (((FieldAccessExpr) firstNode).getScope() instanceof ThisExpr) {
result = of(fieldAccessExpr(originalTypeCursor, ((FieldAccessExpr) firstNode).getName()));
} else {
try {
Class<?> resolvedType = ruleContext.getTypeResolver().resolveType(PrintUtil.printNode(firstNode));
result = of(new TypedExpressionCursor(new NameExpr(PrintUtil.printNode(firstNode)), resolvedType));
} catch (ClassNotFoundException e) {
result = empty();
}
}
} else if (firstNode instanceof NullSafeFieldAccessExpr && ((NullSafeFieldAccessExpr) firstNode).getScope() instanceof ThisExpr) {
result = of(fieldAccessExpr(originalTypeCursor, ((NullSafeFieldAccessExpr) firstNode).getName()));
} else if (firstNode instanceof MethodCallExpr) {
Optional<Expression> scopeExpr = ((MethodCallExpr) firstNode).getScope();
Optional<DeclarationSpec> scopeDecl = scopeExpr.flatMap(scope -> ruleContext.getDeclarationById(PrintUtil.printNode(scope)));
Expression scope;
java.lang.reflect.Type type;
if (scopeDecl.isPresent() && !scopeDecl.get().getBindingId().equals(bindingId)) {
type = scopeDecl.get().getDeclarationClass();
scope = new NameExpr(scopeDecl.get().getBindingId());
context.addUsedDeclarations(scopeDecl.get().getBindingId());
} else if (scopeExpr.isPresent()) {
TypedExpressionCursor parsedScope = processFirstNode(drlxExpr, childNodes, scopeExpr.get(), isInLineCast, originalTypeCursor).get();
type = parsedScope.typeCursor;
scope = parsedScope.expressionCursor;
} else {
type = originalTypeCursor;
scope = new NameExpr(THIS_PLACEHOLDER);
}
result = of(methodCallExpr((MethodCallExpr) firstNode, type, scope));
} else if (firstNode instanceof ObjectCreationExpr) {
result = of(objectCreationExpr((ObjectCreationExpr) firstNode));
} else if (firstNode instanceof StringLiteralExpr) {
result = of(stringLiteralExpr((StringLiteralExpr) firstNode));
} else if (firstNode instanceof EnclosedExpr) {
result = processFirstNode(drlxExpr, childNodes, ((EnclosedExpr) firstNode).getInner(), isInLineCast, originalTypeCursor);
} else if (firstNode instanceof CastExpr) {
result = castExpr((CastExpr) firstNode, drlxExpr, childNodes, isInLineCast, originalTypeCursor);
} else if (firstNode instanceof ArrayCreationExpr) {
result = of(arrayCreationExpr(((ArrayCreationExpr) firstNode)));
} else if (firstNode instanceof BinaryExpr) {
result = of(binaryExpr((BinaryExpr) firstNode));
} else if (firstNode instanceof ArrayAccessExpr) {
Optional<DeclarationSpec> scopeDecl = ruleContext.getDeclarationById(((ArrayAccessExpr) firstNode).getName().toString());
Expression scope;
java.lang.reflect.Type type;
if (scopeDecl.isPresent() && !scopeDecl.get().getBindingId().equals(bindingId)) {
type = scopeDecl.get().getDeclarationClass();
scope = new NameExpr(scopeDecl.get().getBindingId());
context.addUsedDeclarations(scopeDecl.get().getBindingId());
} else {
type = originalTypeCursor;
scope = new NameExpr(THIS_PLACEHOLDER);
}
result = arrayAccessExpr((ArrayAccessExpr) firstNode, type, scope);
} else if (firstNode instanceof MapCreationLiteralExpression) {
result = mapCreationLiteral((MapCreationLiteralExpression) firstNode, originalTypeCursor);
} else if (firstNode instanceof ListCreationLiteralExpression) {
result = listCreationLiteral((ListCreationLiteralExpression) firstNode, originalTypeCursor);
} else {
result = of(new TypedExpressionCursor((Expression) firstNode, getExpressionType(ruleContext, ruleContext.getTypeResolver(), (Expression) firstNode, context.getUsedDeclarations())));
}
if (result.isPresent()) {
processNullSafeDereferencing(drlxExpr);
}
return result.map(te -> {
if (isInLineCast) {
Expression exprWithInlineCast = addCastToExpression(toRawClass(te.typeCursor), te.expressionCursor, isInLineCast);
return new TypedExpressionCursor(exprWithInlineCast, te.typeCursor);
} else {
return te;
}
});
}
use of org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr in project drools by kiegroup.
the class ExpressionTyper method toTypedExpressionFromMethodCallOrField.
private TypedExpressionResult toTypedExpressionFromMethodCallOrField(Expression drlxExpr) {
if (drlxExpr instanceof FieldAccessExpr) {
// try to see if it's a constant
final Optional<TypedExpression> typedExpression = tryParseAsConstantField(ruleContext.getTypeResolver(), ((FieldAccessExpr) drlxExpr).getScope(), ((FieldAccessExpr) drlxExpr).getNameAsString());
if (typedExpression.isPresent()) {
return new TypedExpressionResult(typedExpression, context);
}
}
if (patternType == null && drlxExpr instanceof NullSafeFieldAccessExpr) {
// try to see if it's a constant
final Optional<TypedExpression> typedExpression = tryParseAsConstantField(ruleContext.getTypeResolver(), ((NullSafeFieldAccessExpr) drlxExpr).getScope(), ((NullSafeFieldAccessExpr) drlxExpr).getNameAsString());
if (typedExpression.isPresent()) {
return new TypedExpressionResult(typedExpression, context);
}
}
final List<Node> childrenNodes = flattenScope(ruleContext.getTypeResolver(), drlxExpr);
final Node firstChild = childrenNodes.get(0);
boolean isInLineCast = firstChild instanceof InlineCastExpr;
java.lang.reflect.Type originalTypeCursor;
final Node firstNode;
if (isInLineCast) {
InlineCastExpr inlineCast = (InlineCastExpr) firstChild;
originalTypeCursor = originalTypeCursorFromInlineCast(inlineCast);
firstNode = inlineCast.getExpression();
if (inlineCast.getExpression().isThisExpr()) {
context.setInlineCastExpression(Optional.of(new InstanceOfExpr(new NameExpr(THIS_PLACEHOLDER), (ReferenceType) inlineCast.getType())));
} else {
context.setInlineCastExpression(toTypedExpression(inlineCast.getExpression()).getTypedExpression().map(TypedExpression::getExpression).map(expr -> new InstanceOfExpr(expr, (ReferenceType) inlineCast.getType())));
}
} else {
originalTypeCursor = patternType;
firstNode = firstChild;
}
if (originalTypeCursor != null && originalTypeCursor.equals(Object.class)) {
// try infer type from the declarations
final Optional<DeclarationSpec> declarationById = ruleContext.getDeclarationById(printNode(firstChild));
originalTypeCursor = declarationById.map(d -> (java.lang.reflect.Type) d.getDeclarationClass()).orElse(originalTypeCursor);
}
final Optional<TypedExpressionCursor> teCursor = processFirstNode(drlxExpr, childrenNodes, firstNode, isInLineCast, originalTypeCursor);
if (firstNode instanceof MethodCallExpr) {
MethodCallExpr me = (MethodCallExpr) firstNode;
addReactOnProperty(me.getNameAsString(), me.getArguments());
}
if (firstNode instanceof NullSafeMethodCallExpr) {
NullSafeMethodCallExpr me = (NullSafeMethodCallExpr) firstNode;
addReactOnProperty(me.getNameAsString(), me.getArguments());
}
if (!teCursor.isPresent()) {
return new TypedExpressionResult(empty(), context);
}
Expression previous = teCursor.get().expressionCursor;
java.lang.reflect.Type typeCursor = teCursor.get().typeCursor;
List<Node> childrenWithoutFirst = childrenNodes.subList(1, childrenNodes.size());
for (Node part : childrenWithoutFirst) {
if (part instanceof SimpleName) {
String field = part.toString();
TypedExpression expression = nameExprToMethodCallExpr(field, typeCursor, previous, ruleContext);
if (expression == null) {
ruleContext.addCompilationError(new InvalidExpressionErrorResult("Unknown field " + field + " on " + typeCursor));
break;
}
typeCursor = expression.getType();
previous = expression.getExpression();
} else if (part instanceof MethodCallExpr) {
TypedExpressionCursor typedExpr = methodCallExpr((MethodCallExpr) part, typeCursor, previous);
typeCursor = typedExpr.typeCursor;
previous = typedExpr.expressionCursor;
} else if (part instanceof NullSafeMethodCallExpr) {
TypedExpressionCursor typedExpr = nullSafeMethodCallExpr((NullSafeMethodCallExpr) part, typeCursor, previous);
typeCursor = typedExpr.typeCursor;
previous = typedExpr.expressionCursor;
} else if (part instanceof InlineCastExpr && ((InlineCastExpr) part).getExpression() instanceof FieldAccessExpr) {
InlineCastExpr inlineCastExprPart = (InlineCastExpr) part;
final FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) inlineCastExprPart.getExpression();
final TypedExpression toMethodCallExpr = nameExprToMethodCallExpr(fieldAccessExpr.getNameAsString(), typeCursor, previous, ruleContext);
if (toMethodCallExpr == null) {
ruleContext.addCompilationError(new InvalidExpressionErrorResult("Unknown field " + fieldAccessExpr.getNameAsString() + " on " + typeCursor));
break;
}
final Class<?> castClass = getClassFromType(ruleContext.getTypeResolver(), inlineCastExprPart.getType());
previous = addCastToExpression(castClass, toMethodCallExpr.getExpression(), false);
typeCursor = castClass;
} else if (part instanceof ArrayAccessExpr) {
final ArrayAccessExpr inlineCastExprPart = (ArrayAccessExpr) part;
TypedExpressionCursor typedExpr = arrayAccessExpr(inlineCastExprPart, typeCursor, previous).orElseThrow(() -> new NoSuchElementException("ArrayAccessExpr doesn't contain TypedExpressionCursor!"));
typeCursor = typedExpr.typeCursor;
previous = typedExpr.expressionCursor;
} else {
throw new UnsupportedOperationException();
}
}
return new TypedExpressionResult(of(new TypedExpression(previous, typeCursor, accessorToFieldName(drlxExpr))), context);
}
use of org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr in project drools by kiegroup.
the class FlattenScope method flattenScope.
public static List<Node> flattenScope(TypeResolver typeResolver, Expression expressionWithScope) {
List<Node> res = new ArrayList<>();
if (expressionWithScope instanceof FullyQualifiedInlineCastExpr) {
res.addAll(flattenScope(typeResolver, transformFullyQualifiedInlineCastExpr(typeResolver, (FullyQualifiedInlineCastExpr) expressionWithScope)));
} else if (expressionWithScope instanceof FieldAccessExpr) {
FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) expressionWithScope;
res.addAll(flattenScope(typeResolver, fieldAccessExpr.getScope()));
res.add(fieldAccessExpr.getName());
} else if (expressionWithScope instanceof NullSafeFieldAccessExpr) {
NullSafeFieldAccessExpr fieldAccessExpr = (NullSafeFieldAccessExpr) expressionWithScope;
res.addAll(flattenScope(typeResolver, fieldAccessExpr.getScope()));
res.add(fieldAccessExpr.getName());
} else if (expressionWithScope instanceof MethodCallExpr) {
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionWithScope;
if (methodCallExpr.getScope().isPresent()) {
Expression scope = methodCallExpr.getScope().get();
if (isFullyQualifiedClassName(typeResolver, scope)) {
res.add(scope);
} else {
res.addAll(flattenScope(typeResolver, scope));
}
}
res.add(methodCallExpr);
} else if (expressionWithScope instanceof NullSafeMethodCallExpr) {
NullSafeMethodCallExpr methodCallExpr = (NullSafeMethodCallExpr) expressionWithScope;
if (methodCallExpr.getScope().isPresent()) {
res.addAll(flattenScope(typeResolver, methodCallExpr.getScope().orElseThrow(() -> new IllegalStateException("Scope expression is not present!"))));
}
res.add(methodCallExpr);
} else if (expressionWithScope instanceof InlineCastExpr && ((InlineCastExpr) expressionWithScope).getExpression() instanceof FieldAccessExpr) {
InlineCastExpr inlineCastExpr = (InlineCastExpr) expressionWithScope;
Expression internalScope = ((FieldAccessExpr) inlineCastExpr.getExpression()).getScope();
res.addAll(flattenScope(typeResolver, internalScope));
res.add(expressionWithScope);
} else if (expressionWithScope instanceof ArrayAccessExpr) {
ArrayAccessExpr arrayAccessExpr = (ArrayAccessExpr) expressionWithScope;
res.addAll(flattenScope(typeResolver, arrayAccessExpr.getName()));
res.add(arrayAccessExpr);
} else if (expressionWithScope instanceof EnclosedExpr) {
res.addAll(flattenScope(typeResolver, ((EnclosedExpr) expressionWithScope).getInner()));
} else {
res.add(expressionWithScope);
}
return res;
}
Aggregations