com.github.javaparser.ast.expr.MethodCallExpr Java Examples
The following examples show how to use
com.github.javaparser.ast.expr.MethodCallExpr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LazyTest.java From TestSmellDetector with GNU General Public License v3.0 | 7 votes |
/** * The purpose of this method is to identify the production class methods that are called from the test method * When the parser encounters a method call: * 1) the method is contained in the productionMethods list * or * 2) the code will check the 'scope' of the called method * A match is made if the scope is either: * equal to the name of the production class (as in the case of a static method) or * if the scope is a variable that has been declared to be of type of the production class (i.e. contained in the 'productionVariables' list). */ @Override public void visit(MethodCallExpr n, Void arg) { super.visit(n, arg); if (currentMethod != null) { if (productionMethods.stream().anyMatch(i -> i.getNameAsString().equals(n.getNameAsString()) && i.getParameters().size() == n.getArguments().size())) { calledProductionMethods.add(new MethodUsage(currentMethod.getNameAsString(), n.getNameAsString())); } else { if (n.getScope().isPresent()) { if (n.getScope().get() instanceof NameExpr) { //checks if the scope of the method being called is either of production class (e.g. static method) //or ///if the scope matches a variable which, in turn, is of type of the production class if (((NameExpr) n.getScope().get()).getNameAsString().equals(productionClassName) || productionVariables.contains(((NameExpr) n.getScope().get()).getNameAsString())) { calledProductionMethods.add(new MethodUsage(currentMethod.getNameAsString(), n.getNameAsString())); } } } } } }
Example #2
Source File: RemoveMethodParameter.java From Refactoring-Bot with MIT License | 6 votes |
/** * @param methodCall * @return true if given method call is related to target method, false * otherwise */ private boolean isTargetMethodCall(MethodCallExpr methodCall) { for (MethodDeclaration targetMethod : allRefactoringRelevantMethodDeclarations) { String qualifiedMethodSignatureOfResolvedMethodCall = null; String qualifiedMethodSignatureOfTargetMethod = null; try { qualifiedMethodSignatureOfResolvedMethodCall = methodCall.resolve().getQualifiedSignature(); qualifiedMethodSignatureOfTargetMethod = RefactoringHelper .getQualifiedMethodSignatureAsString(targetMethod); } catch (Exception e) { logger.error(e.getMessage()); // TODO could be the case that an external dependency could not be resolved. In // such case it is fine to return false. However, it is an issue if a method // call that needs to be refactored can not be resolved. // see also RefactoringHelper.getQualifiedMethodSignatureAsString return false; } if (qualifiedMethodSignatureOfTargetMethod.equals(qualifiedMethodSignatureOfResolvedMethodCall)) { return true; } } return false; }
Example #3
Source File: LambdaSubProcessNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
protected Expression dotNotationToSetExpression(String dotNotation, String value) { String[] elements = dotNotation.split("\\."); Expression scope = new NameExpr(elements[0]); if (elements.length == 1) { return new AssignExpr( scope, new NameExpr(value), AssignExpr.Operator.ASSIGN); } for (int i = 1; i < elements.length - 1; i++) { scope = new MethodCallExpr() .setScope(scope) .setName("get" + StringUtils.capitalize(elements[i])); } return new MethodCallExpr() .setScope(scope) .setName("set" + StringUtils.capitalize(elements[elements.length - 1])) .addArgument(value); }
Example #4
Source File: LambdaSubProcessNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
protected Expression dotNotationToGetExpression(String dotNotation) { String[] elements = dotNotation.split("\\."); Expression scope = new NameExpr(elements[0]); if (elements.length == 1) { return scope; } for (int i = 1; i < elements.length; i++) { scope = new MethodCallExpr() .setScope(scope) .setName("get" + StringUtils.capitalize(elements[i])); } return scope; }
Example #5
Source File: TriggerMetaData.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static LambdaExpr buildLambdaExpr(Node node, ProcessMetaData metadata) { Map<String, Object> nodeMetaData = node.getMetaData(); TriggerMetaData triggerMetaData = new TriggerMetaData( (String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(MAPPING_VARIABLE), String.valueOf(node.getId())) .validate(); metadata.getTriggers().add(triggerMetaData); // and add trigger action BlockStmt actionBody = new BlockStmt(); CastExpr variable = new CastExpr( new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getVariable") .addArgument(new StringLiteralExpr(triggerMetaData.getModelRef()))); MethodCallExpr producerMethodCall = new MethodCallExpr(new NameExpr("producer_" + node.getId()), "produce").addArgument(new MethodCallExpr(new NameExpr("kcontext"), "getProcessInstance")).addArgument(variable); actionBody.addStatement(producerMethodCall); return new LambdaExpr( new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) -> actionBody ); }
Example #6
Source File: WorkItemNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private Expression getParameterExpr(String type, String value) { ParamType pType = ParamType.fromString(type); if (pType == null) { return new StringLiteralExpr(value); } switch (pType) { case BOOLEAN: return new BooleanLiteralExpr(Boolean.parseBoolean(value)); case FLOAT: return new MethodCallExpr() .setScope(new NameExpr(Float.class.getName())) .setName("parseFloat") .addArgument(new StringLiteralExpr(value)); case INTEGER: return new IntegerLiteralExpr(Integer.parseInt(value)); default: return new StringLiteralExpr(value); } }
Example #7
Source File: MigrateJCas.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * visitor for field access expressions * - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxx * @param n - * @param ignore - */ @Override public void visit(FieldAccessExpr n, Object ignore) { Expression e; Optional<Expression> oe; String nname = n.getNameAsString(); if (get_set_method != null) { if (nname.startsWith("casFeatCode_") && ((oe = n.getScope()).isPresent()) && ((e = getUnenclosedExpr(oe.get())) instanceof CastExpr) && ("jcasType".equals(getName(((CastExpr)e).getExpression())))) { String featureName = nname.substring("casFeatCode_".length()); // replaceInParent(n, new NameExpr("_FI_" + featureName)); // repl last in List<Expression> (args) MethodCallExpr getint = new MethodCallExpr(null, "wrapGetIntCatchException"); getint.addArgument(new NameExpr("_FH_" + featureName)); replaceInParent(n, getint); return; } else if (nname.startsWith("casFeatCode_")) { reportMigrateFailed("Found field casFeatCode_ ... without a previous cast expr using jcasType"); } } super.visit(n, ignore); }
Example #8
Source File: PrintStatement.java From TestSmellDetector with GNU General Public License v3.0 | 6 votes |
@Override public void visit(MethodCallExpr n, Void arg) { super.visit(n, arg); if (currentMethod != null) { // if the name of a method being called is 'print' or 'println' or 'printf' or 'write' if (n.getNameAsString().equals("print") || n.getNameAsString().equals("println") || n.getNameAsString().equals("printf") || n.getNameAsString().equals("write")) { //check the scope of the method & proceed only if the scope is "out" if ((n.getScope().isPresent() && n.getScope().get() instanceof FieldAccessExpr && (((FieldAccessExpr) n.getScope().get())).getNameAsString().equals("out"))) { FieldAccessExpr f1 = (((FieldAccessExpr) n.getScope().get())); //check the scope of the field & proceed only if the scope is "System" if ((f1.getScope() != null && f1.getScope() instanceof NameExpr && ((NameExpr) f1.getScope()).getNameAsString().equals("System"))) { //a print statement exists in the method body printCount++; } } } } }
Example #9
Source File: RuleUnitMetaModel.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public Statement injectCollection( String targetUnitVar, String sourceProcVar) { BlockStmt blockStmt = new BlockStmt(); RuleUnitVariable v = ruleUnitDescription.getVar(targetUnitVar); String appendMethod = appendMethodOf(v.getType()); blockStmt.addStatement(assignVar(v)); blockStmt.addStatement( iterate(new VariableDeclarator() .setType("Object").setName("it"), new NameExpr(sourceProcVar)) .setBody(new ExpressionStmt( new MethodCallExpr() .setScope(new NameExpr(localVarName(v))) .setName(appendMethod) .addArgument(new NameExpr("it"))))); return blockStmt; }
Example #10
Source File: RuleSetNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private MethodCallExpr handleRuleFlowGroup(RuleSetNode.RuleType ruleType) { // build supplier for rule runtime BlockStmt actionBody = new BlockStmt(); LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody); MethodCallExpr ruleRuntimeBuilder = new MethodCallExpr( new MethodCallExpr(new NameExpr("app"), "ruleUnits"), "ruleRuntimeBuilder"); MethodCallExpr ruleRuntimeSupplier = new MethodCallExpr( ruleRuntimeBuilder, "newKieSession", NodeList.nodeList(new StringLiteralExpr("defaultStatelessKieSession"), new NameExpr("app.config().rule()"))); actionBody.addStatement(new ReturnStmt(ruleRuntimeSupplier)); return new MethodCallExpr("ruleFlowGroup") .addArgument(new StringLiteralExpr(ruleType.getName())) .addArgument(lambda); }
Example #11
Source File: RuleSetNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private MethodCallExpr handleRuleUnit(VariableScope variableScope, ProcessMetaData metadata, RuleSetNode ruleSetNode, String nodeName, RuleSetNode.RuleType ruleType) { String unitName = ruleType.getName(); ProcessContextMetaModel processContext = new ProcessContextMetaModel(variableScope, contextClassLoader); RuleUnitDescription description; try { Class<?> unitClass = loadUnitClass(nodeName, unitName, metadata.getPackageName()); description = new ReflectiveRuleUnitDescription(null, (Class<? extends RuleUnitData>) unitClass); } catch (ClassNotFoundException e) { logger.warn("Rule task \"{}\": cannot load class {}. " + "The unit data object will be generated.", nodeName, unitName); GeneratedRuleUnitDescription d = generateRuleUnitDescription(unitName, processContext); RuleUnitComponentFactoryImpl impl = (RuleUnitComponentFactoryImpl) RuleUnitComponentFactory.get(); impl.registerRuleUnitDescription(d); description = d; } RuleUnitHandler handler = new RuleUnitHandler(description, processContext, ruleSetNode, assignableChecker); Expression ruleUnitFactory = handler.invoke(); return new MethodCallExpr("ruleUnit") .addArgument(new StringLiteralExpr(ruleType.getName())) .addArgument(ruleUnitFactory); }
Example #12
Source File: StateNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Override public Stream<MethodCallExpr> visitCustomFields(StateNode node, VariableScope variableScope) { if (node.getConstraints() == null) { return Stream.empty(); } return node.getConstraints() .entrySet() .stream() .map((e -> getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT, getOrNullExpr(e.getKey().getConnectionId()), new LongLiteralExpr(e.getKey().getNodeId()), new StringLiteralExpr(e.getKey().getToType()), new StringLiteralExpr(e.getValue().getDialect()), new StringLiteralExpr(StringEscapeUtils.escapeJava(e.getValue().getConstraint())), new IntegerLiteralExpr(e.getValue().getPriority())))); }
Example #13
Source File: DecisionContainerGenerator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Override public List<Statement> setupStatements() { return Collections.singletonList( new IfStmt( new BinaryExpr( new MethodCallExpr(new MethodCallExpr(null, "config"), "decision"), new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS ), new BlockStmt().addStatement(new ExpressionStmt(new MethodCallExpr( new NameExpr("decisionModels"), "init", NodeList.nodeList(new ThisExpr()) ))), null ) ); }
Example #14
Source File: RuleUnitInstanceGenerator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public ClassOrInterfaceDeclaration classDeclaration() { String canonicalName = ruleUnitDescription.getRuleUnitName(); ClassOrInterfaceDeclaration classDecl = new ClassOrInterfaceDeclaration() .setName(targetTypeName) .addModifier(Modifier.Keyword.PUBLIC); classDecl .addExtendedType( new ClassOrInterfaceType(null, AbstractRuleUnitInstance.class.getCanonicalName()) .setTypeArguments(new ClassOrInterfaceType(null, canonicalName))) .addConstructor(Modifier.Keyword.PUBLIC) .addParameter(RuleUnitGenerator.ruleUnitType(canonicalName), "unit") .addParameter(canonicalName, "value") .addParameter(KieSession.class.getCanonicalName(), "session") .setBody(new BlockStmt().addStatement(new MethodCallExpr( "super", new NameExpr("unit"), new NameExpr("value"), new NameExpr("session") ))); classDecl.addMember(bindMethod()); classDecl.getMembers().sort(new BodyDeclarationComparator()); return classDecl; }
Example #15
Source File: RuleSetNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private MethodCallExpr handleDecision(RuleSetNode.RuleType.Decision ruleType) { StringLiteralExpr namespace = new StringLiteralExpr(ruleType.getNamespace()); StringLiteralExpr model = new StringLiteralExpr(ruleType.getModel()); Expression decision = ruleType.getDecision() == null ? new NullLiteralExpr() : new StringLiteralExpr(ruleType.getDecision()); MethodCallExpr decisionModels = new MethodCallExpr(new NameExpr("app"), "decisionModels"); MethodCallExpr decisionModel = new MethodCallExpr(decisionModels, "getDecisionModel") .addArgument(namespace) .addArgument(model); BlockStmt actionBody = new BlockStmt(); LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody); actionBody.addStatement(new ReturnStmt(decisionModel)); return new MethodCallExpr(METHOD_DECISION) .addArgument(namespace) .addArgument(model) .addArgument(decision) .addArgument(lambda); }
Example #16
Source File: AbstractNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static Statement makeAssignment(String targetLocalVariable, Variable processVariable) { ClassOrInterfaceType type = parseClassOrInterfaceType(processVariable.getType().getStringType()); // `type` `name` = (`type`) `kcontext.getVariable AssignExpr assignExpr = new AssignExpr( new VariableDeclarationExpr(type, targetLocalVariable), new CastExpr( type, new MethodCallExpr( new NameExpr(KCONTEXT_VAR), "getVariable") .addArgument(new StringLiteralExpr(targetLocalVariable))), AssignExpr.Operator.ASSIGN); return new ExpressionStmt(assignExpr); }
Example #17
Source File: ModelMetaData.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public MethodCallExpr callSetter(String targetVar, String destField, Expression value) { String name = variableScope.getTypes().get(destField).getSanitizedName(); String type = variableScope.getType(destField); String setter = "set" + StringUtils.capitalize(name); // todo cache FieldDeclarations in compilationUnit() return new MethodCallExpr(new NameExpr(targetVar), setter).addArgument( new CastExpr( new ClassOrInterfaceType(null, type), new EnclosedExpr(value))); }
Example #18
Source File: JFinalRoutesParser.java From JApiDocs with Apache License 2.0 | 5 votes |
private void parse(MethodDeclaration mdConfigRoute, File inJavaFile){ mdConfigRoute.getBody() .ifPresent(blockStmt -> blockStmt.getStatements() .stream() .filter(statement -> statement instanceof ExpressionStmt) .forEach(statement -> { Expression expression = ((ExpressionStmt)statement).getExpression(); if(expression instanceof MethodCallExpr && ((MethodCallExpr)expression).getNameAsString().equals("add")){ NodeList<Expression> arguments = ((MethodCallExpr)expression).getArguments(); if(arguments.size() == 1 && arguments.get(0) instanceof ObjectCreationExpr){ String routeClassName = ((ObjectCreationExpr)((MethodCallExpr) expression).getArguments().get(0)).getType().getNameAsString(); File childRouteFile = ParseUtils.searchJavaFile(inJavaFile, routeClassName); LogUtils.info("found child routes in file : %s" , childRouteFile.getName()); ParseUtils.compilationUnit(childRouteFile) .getChildNodesByType(ClassOrInterfaceDeclaration.class) .stream() .filter(cd -> routeClassName.endsWith(cd.getNameAsString())) .findFirst() .ifPresent(cd ->{ LogUtils.info("found config() method, start to parse child routes in file : %s" , childRouteFile.getName()); cd.getMethodsByName("config").stream().findFirst().ifPresent(m ->{ parse(m, childRouteFile); }); }); }else{ String basicUrl = Utils.removeQuotations(arguments.get(0).toString()); String controllerClass = arguments.get(1).toString(); String controllerFilePath = getControllerFilePath(inJavaFile, controllerClass); routeNodeList.add(new RouteNode(basicUrl, controllerFilePath)); } } })); }
Example #19
Source File: EagerTest.java From TestSmellDetector with GNU General Public License v3.0 | 5 votes |
/** * This method is utilized to obtain the scope of a chained method statement */ private void getFinalScope(MethodCallExpr n) { if (n.getScope().isPresent()) { if ((n.getScope().get() instanceof MethodCallExpr)) { getFinalScope((MethodCallExpr) n.getScope().get()); } else if ((n.getScope().get() instanceof NameExpr)) { tempNameExpr = ((NameExpr) n.getScope().get()); } } }
Example #20
Source File: AbstractNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
protected AssignExpr getAssignedFactoryMethod(String factoryField, Class<?> typeClass, String variableName, String methodName, Expression... args) { ClassOrInterfaceType type = new ClassOrInterfaceType(null, typeClass.getCanonicalName()); MethodCallExpr variableMethod = new MethodCallExpr(new NameExpr(factoryField), methodName); for (Expression arg : args) { variableMethod.addArgument(arg); } return new AssignExpr( new VariableDeclarationExpr(type, variableName), variableMethod, AssignExpr.Operator.ASSIGN); }
Example #21
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
@Override public void visit(final MethodCallExpr n, final Void arg) { printJavaComment(n.getComment(), arg); if (n.getScope().isPresent()) { n.getScope().get().accept(this, arg); printer.print("."); } printTypeArgs(n, arg); n.getName().accept(this, arg); printArguments(n.getArguments(), arg); }
Example #22
Source File: DecisionContainerGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private MethodCallExpr getReadResourceMethod( ClassOrInterfaceType applicationClass, DMNResource resource ) { String source = resource.getDmnModel().getResource().getSourcePath(); Path sourcePath = Paths.get(source); if (resource.getPath().toString().endsWith( ".jar" )) { return new MethodCallExpr( new NameExpr( IoUtils.class.getCanonicalName() ), "readFileInJar" ) .addArgument(new StringLiteralExpr(resource.getPath().toString())) .addArgument(new StringLiteralExpr(source)); } Path relativizedPath = resource.getPath().relativize(sourcePath); String resourcePath = "/" + relativizedPath.toString().replace( File.separatorChar, '/'); return new MethodCallExpr(new FieldAccessExpr(applicationClass.getNameAsExpression(), "class"), "getResourceAsStream") .addArgument(new StringLiteralExpr(resourcePath)); }
Example #23
Source File: ConfigurableEagerTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method is utilized to obtain the scope of a chained method * statement */ private void getFinalScope(MethodCallExpr n) { if (n.getScope().isPresent()) { if ((n.getScope().get() instanceof MethodCallExpr)) { getFinalScope((MethodCallExpr) n.getScope().get()); } else if ((n.getScope().get() instanceof NameExpr)) { tempNameExpr = ((NameExpr) n.getScope().get()); } } }
Example #24
Source File: AppendRoutingVisitor.java From enkan with Eclipse Public License 1.0 | 5 votes |
public void visit(final BlockStmt n, final RoutingDefineContext arg) { if (arg.isInRoutingDefine()) { MethodCallExpr call = new MethodCallExpr( ASTHelper.createNameExpr(arg.getRoutingParameter().getId().getName()), "resource"); ReferenceType rt = ASTHelper.createReferenceType(controllerClassName, 0); ASTHelper.addArgument(call, new ClassExpr(rt.getType())); ASTHelper.addStmt(n, call); } else { super.visit(n, arg); } }
Example #25
Source File: RenameMethod.java From Refactoring-Bot with MIT License | 5 votes |
/** * @param classesAndInterfaces * @return true if given classes and interfaces contain at least one call * expression to the given target method, false otherwise */ private boolean containsTargetMethodCall(List<ClassOrInterfaceDeclaration> classesAndInterfaces) { for (ClassOrInterfaceDeclaration classOrInterface : classesAndInterfaces) { List<MethodCallExpr> methodCalls = classOrInterface.findAll(MethodCallExpr.class); for (MethodCallExpr methodCall : methodCalls) { if (isTargetMethodCall(methodCall)) { return true; } } } return false; }
Example #26
Source File: RuleSetNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public void visitNode(String factoryField, RuleSetNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { String nodeName = node.getName(); body.addStatement(getAssignedFactoryMethod(factoryField, RuleSetNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))) .addStatement(getNameMethod(node, "Rule")); RuleSetNode.RuleType ruleType = node.getRuleType(); if (ruleType.getName().isEmpty()) { throw new IllegalArgumentException( MessageFormat.format( "Rule task \"{0}\" is invalid: you did not set a unit name, a rule flow group or a decision model.", nodeName)); } addNodeMappings(node, body, getNodeId(node)); NameExpr methodScope = new NameExpr(getNodeId(node)); MethodCallExpr m; if (ruleType.isRuleFlowGroup()) { m = handleRuleFlowGroup(ruleType); } else if (ruleType.isRuleUnit()) { m = handleRuleUnit(variableScope, metadata, node, nodeName, ruleType); } else if (ruleType.isDecision()) { m = handleDecision((RuleSetNode.RuleType.Decision) ruleType); } else { throw new IllegalArgumentException("Rule task " + nodeName + "is invalid: unsupported rule language " + node.getLanguage()); } m.setScope(methodScope); body.addStatement(m); visitMetaData(node.getMetaData(), body, getNodeId(node)); body.addStatement(getDoneMethod(getNodeId(node))); }
Example #27
Source File: KieModuleModelMethod.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void sessionDefault() { if (kieSessionModel.isDefault()) { if (kieSessionModel.getType() == KieSessionModel.KieSessionType.STATELESS) { defaultKieStatelessSessionName = kieSessionModel.getName(); } else { defaultKieSessionName = kieSessionModel.getName(); } stmt.addStatement(new MethodCallExpr(nameExpr, "setDefault", nodeList(new BooleanLiteralExpr(true)))); } }
Example #28
Source File: LambdaSubProcessNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private BlockStmt unbind(VariableScope variableScope, SubProcessNode subProcessNode) { BlockStmt stmts = new BlockStmt(); for (Map.Entry<String, String> e : subProcessNode.getOutMappings().entrySet()) { // check if given mapping is an expression Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(e.getValue()); if (matcher.find()) { String expression = matcher.group(1); String topLevelVariable = expression.split("\\.")[0]; Map<String, String> dataOutputs = (Map<String, String>) subProcessNode.getMetaData("BPMN.OutputTypes"); Variable variable = new Variable(); variable.setName(topLevelVariable); variable.setType(new ObjectDataType(dataOutputs.get(e.getKey()))); stmts.addStatement(makeAssignment(variableScope.findVariable(topLevelVariable))); stmts.addStatement(makeAssignmentFromModel(variable, e.getKey())); stmts.addStatement(dotNotationToSetExpression(expression, e.getKey())); stmts.addStatement(new MethodCallExpr() .setScope(new NameExpr(KCONTEXT_VAR)) .setName("setVariable") .addArgument(new StringLiteralExpr(topLevelVariable)) .addArgument(topLevelVariable)); } else { stmts.addStatement(makeAssignmentFromModel(variableScope.findVariable(e.getValue()), e.getKey())); stmts.addStatement(new MethodCallExpr() .setScope(new NameExpr(KCONTEXT_VAR)) .setName("setVariable") .addArgument(new StringLiteralExpr(e.getValue())) .addArgument(e.getKey())); } } return stmts; }
Example #29
Source File: KieModuleModelMethod.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void setClockType() { NameExpr type = new NameExpr(kieSessionModel.getClockType().getClass().getCanonicalName()); MethodCallExpr clockTypeEnum = new MethodCallExpr(type, "get", nodeList(new StringLiteralExpr(kieSessionModel.getClockType().getClockType()))); stmt.addStatement(new MethodCallExpr(nameExpr, "setClockType", nodeList(clockTypeEnum))); confBlock.addStatement(new MethodCallExpr(confExpr, "setOption", nodeList(clockTypeEnum.clone()))); }
Example #30
Source File: DecisionConfigGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private MethodDeclaration generateExtractEventListenerConfigMethod() { BlockStmt body = new BlockStmt().addStatement(new ReturnStmt( new MethodCallExpr(new ThisExpr(), METHOD_MERGE_DECISION_EVENT_LISTENER_CONFIG, nodeList( annotator.getMultiInstance(VAR_DECISION_EVENT_LISTENER_CONFIG), annotator.getMultiInstance(VAR_DMN_RUNTIME_EVENT_LISTENERS) )) )); return method(Modifier.Keyword.PRIVATE, DecisionEventListenerConfig.class, METHOD_EXTRACT_DECISION_EVENT_LISTENER_CONFIG, body); }