@Override public void enterVirtdataFlow(VirtDataParser.VirtdataFlowContext ctx) { logger.trace("parsing virtdata flow..."); flowContexts.push(ctx); flows.push(new VirtDataFlow()); calls.clear(); if (ctx.COMPOSE()!=null) { logger.warn("The 'compose' keyword is no longer needed in lambda construction. It will be deprecated in the future."); } }
@Override public void enterExpression(VirtDataParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); }
@Override public void exitVirtdataCall(VirtDataParser.VirtdataCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
Optional.ofNullable(flow.getLastExpression().getCall().getOutputType()) .map(ValueType::valueOfClassName).map(ValueType::getValueClass); finalValueTypeOption.ifPresent(t -> nextFunctionInputTypes.get(0).add(t)); for (int i = flow.getExpressions().size() - 1; i >= 0; i--) { FunctionCall call = flow.getExpressions().get(i).getCall(); List<ResolvedFunction> nodeFunctions = new LinkedList<>(); List<ResolvedFunction> flattenedFuncs = optimizePath(funcs, ValueType.classOfType(flow.getLastExpression().getCall().getOutputType()));
String specifiedInputClassName = flow.getFirstExpression().getCall().getInputType(); Class<?> specifiedInputClass = ValueType.classOfType(specifiedInputClassName); if (specifiedInputClass!=null) { flow.getFirstExpression().getCall().setInputType(requiredInputType.getCanonicalName()); String specifiedOutputClassName = flow.getLastExpression().getCall().getOutputType(); Class<?> specifiedOutputClass = ValueType.classOfType(specifiedOutputClassName); if (specifiedOutputClass != null) { flow.getLastExpression().getCall().setOutputType(requiredOutputType.getCanonicalName());
default List<ResolvedFunction> resolveFunctions(String spec) { List<ResolvedFunction> resolvedFunctions = new ArrayList<>(); VirtDataDSL.ParseResult parseResult = VirtDataDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } List<Expression> expressions = parseResult.flow.getExpressions(); if (expressions.size() > 1) { throw new RuntimeException("Unable to promote a lambda flow to a data mapper here."); } FunctionCall call = expressions.get(0).getCall(); List<ResolvedFunction> found = resolveFunctions( Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null), Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null), call.getFunctionName(), call.getArguments()); resolvedFunctions.addAll(found); return resolvedFunctions; }
@Override public void exitVirtdataCall(VirtDataParser.VirtdataCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void enterExpression(VirtDataParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); }
@Override public void enterVirtdataFlow(VirtDataParser.VirtdataFlowContext ctx) { logger.trace("parsing virtdata flow..."); flowContexts.push(ctx); flows.push(new VirtDataFlow()); calls.clear(); if (ctx.COMPOSE()!=null) { logger.warn("The 'compose' keyword is no longer needed in lambda construction. It will be deprecated in the future."); } }
@Override public void exitLvalue(VirtDataParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
@Override public void exitLvalue(VirtDataParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
String outputType = flow.getLastExpression().getCall().getOutputType(); flow.getLastExpression().getCall().setOutputType(clazz.getCanonicalName());