use of org.drools.javaparser.ast.expr.ArrayAccessExpr in project drools by kiegroup.
the class DrlxParseUtil method getExpressionType.
public static Class<?> getExpressionType(RuleContext context, TypeResolver typeResolver, Expression expr, Collection<String> usedDeclarations) {
if (expr instanceof LiteralExpr) {
return getLiteralExpressionType((LiteralExpr) expr);
}
if (expr instanceof ArrayAccessExpr) {
return getClassFromContext(typeResolver, ((ArrayCreationExpr) ((ArrayAccessExpr) expr).getName()).getElementType().asString());
}
if (expr instanceof ArrayCreationExpr) {
return getClassFromContext(typeResolver, ((ArrayCreationExpr) expr).getElementType().asString());
}
if (expr instanceof NameExpr) {
String name = ((NameExpr) expr).getNameAsString();
if (usedDeclarations != null) {
usedDeclarations.add(name);
}
return context.getDeclarationById(name).map(DeclarationSpec::getDeclarationClass).get();
}
if (expr instanceof MethodCallExpr) {
MethodCallExpr methodCallExpr = (MethodCallExpr) expr;
Class<?> scopeType = getExpressionType(context, typeResolver, methodCallExpr.getScope().get(), usedDeclarations);
return returnTypeOfMethodCallExpr(context, typeResolver, methodCallExpr, scopeType, usedDeclarations);
}
if (expr instanceof ObjectCreationExpr) {
final ClassOrInterfaceType type = ((ObjectCreationExpr) expr).getType();
return getClassFromContext(typeResolver, type.asString());
}
if (expr.isCastExpr()) {
String typeName = expr.asCastExpr().getType().toString();
try {
return typeResolver.resolveType(expr.asCastExpr().getType().toString());
} catch (ClassNotFoundException e) {
context.addCompilationError(new InvalidExpressionErrorResult("Unknown type in cast expression: " + typeName));
throw new RuntimeException("Unknown type in cast expression: " + typeName);
}
}
throw new RuntimeException("Unknown expression type: " + expr);
}
Aggregations