use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools-wb by kiegroup.
the class ActionCallMethodWidget method setMethodInfos.
private void setMethodInfos(List<MethodInfo> methodInfos, String factType) {
this.fieldCompletionTexts = new String[methodInfos.size()];
this.fieldCompletionValues = new String[methodInfos.size()];
int i = 0;
for (MethodInfo methodInfo : methodInfos) {
this.fieldCompletionTexts[i] = methodInfo.getName();
this.fieldCompletionValues[i] = methodInfo.getNameWithParameters();
i++;
}
this.variableClass = factType;
}
use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.
the class ActionCallMethodBuilder method getDataType.
private String getDataType(String param) {
String dataType;
MethodInfo methodInfo = getMethodInfo();
if (methodInfo != null) {
dataType = methodInfo.getParams().get(index++);
} else {
dataType = boundParams.get(param);
}
if (dataType == null) {
dataType = inferDataTypeFromActionValue(param, boundParams, isJavaDialect);
}
return dataType;
}
use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testLHSNumberExpressionWithThisPrefix.
@Test
public void testLHSNumberExpressionWithThisPrefix() throws Exception {
String drl = "package org.mortgages;\n" + "import java.lang.Number\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + " Number( this.intValue() > 5 )\n" + " then\n" + "end";
final HashMap<String, List<MethodInfo>> map = new HashMap<>();
final ArrayList<MethodInfo> methodInfos = new ArrayList<>();
methodInfos.add(new MethodInfo("intValue", Collections.emptyList(), "int", null, DataType.TYPE_NUMERIC_INTEGER));
map.put("java.lang.Number", methodInfos);
when(dmo.getModuleMethodInformation()).thenReturn(map);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(1, m.lhs.length);
assertTrue(m.lhs[0] instanceof FactPattern);
final FactPattern fp = (FactPattern) m.lhs[0];
assertEquals("Number", fp.getFactType());
assertEquals(1, fp.getNumberOfConstraints());
assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fp.getConstraint(0);
assertEquals("int", exp.getFieldType());
assertEquals(">", exp.getOperator());
assertEquals("5", exp.getValue());
assertEquals(3, exp.getExpressionLeftSide().getParts().size());
assertTrue(exp.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
final ExpressionUnboundFact expPart0 = (ExpressionUnboundFact) exp.getExpressionLeftSide().getParts().get(0);
assertEquals("Number", expPart0.getFactType());
assertTrue(exp.getExpressionLeftSide().getParts().get(1) instanceof ExpressionField);
final ExpressionField expPart1 = (ExpressionField) exp.getExpressionLeftSide().getParts().get(1);
assertEquals("this", expPart1.getName());
assertTrue(exp.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
final ExpressionMethod expPart2 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(2);
assertEquals("intValue", expPart2.getName());
}
use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testLHSNumberExpressionWithoutThisPrefix.
@Test
public void testLHSNumberExpressionWithoutThisPrefix() throws Exception {
String drl = "package org.mortgages;\n" + "import java.lang.Number\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + " Number( intValue() > 5 )\n" + " then\n" + "end";
final HashMap<String, List<MethodInfo>> map = new HashMap<>();
final ArrayList<MethodInfo> methodInfos = new ArrayList<>();
methodInfos.add(new MethodInfo("intValue", Collections.emptyList(), "int", null, DataType.TYPE_NUMERIC_INTEGER));
map.put("java.lang.Number", methodInfos);
when(dmo.getModuleMethodInformation()).thenReturn(map);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(1, m.lhs.length);
assertTrue(m.lhs[0] instanceof FactPattern);
final FactPattern fp = (FactPattern) m.lhs[0];
assertEquals("Number", fp.getFactType());
assertEquals(1, fp.getNumberOfConstraints());
assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fp.getConstraint(0);
assertEquals("int", exp.getFieldType());
assertEquals(">", exp.getOperator());
assertEquals("5", exp.getValue());
assertEquals(2, exp.getExpressionLeftSide().getParts().size());
assertTrue(exp.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
final ExpressionUnboundFact expPart0 = (ExpressionUnboundFact) exp.getExpressionLeftSide().getParts().get(0);
assertEquals("Number", expPart0.getFactType());
assertTrue(exp.getExpressionLeftSide().getParts().get(1) instanceof ExpressionMethod);
final ExpressionMethod expPart1 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(1);
assertEquals("intValue", expPart1.getName());
}
use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testFunctionsWithVariableParameters.
@Test
public void testFunctionsWithVariableParameters() throws Exception {
String drl = "package org.mortgages;\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + " Calculator( s : summer)\n" + " Applicant( $age : age)\n" + " then\n" + " s.sum( $age, $age );\n" + "end";
addModelField("Calculator", "summer", "Summer", "Summer");
addModelField("Applicant", "age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
HashMap<String, List<MethodInfo>> map = new HashMap<>();
ArrayList<MethodInfo> methodInfos = new ArrayList<>();
ArrayList<String> params = new ArrayList<>();
params.add("Integer");
params.add("Integer");
methodInfos.add(new MethodInfo("sum", params, "java.lang.Integer", null, "Summer"));
map.put("Calculator", methodInfos);
when(dmo.getModuleMethodInformation()).thenReturn(map);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(2, m.lhs.length);
assertEquals(1, m.rhs.length);
ActionCallMethod actionCallMethod = (ActionCallMethod) m.rhs[0];
assertEquals("sum", actionCallMethod.getMethodName());
assertEquals("s", actionCallMethod.getVariable());
assertEquals(2, actionCallMethod.getFieldValues().length);
assertEquals("sum", actionCallMethod.getFieldValue(0).getField());
assertEquals("$age", actionCallMethod.getFieldValue(0).getValue());
assertEquals(2, actionCallMethod.getFieldValue(0).getNature());
assertEquals("java.lang.Integer", actionCallMethod.getFieldValue(0).getType());
assertEquals("sum", actionCallMethod.getFieldValue(1).getField());
assertEquals("$age", actionCallMethod.getFieldValue(1).getValue());
assertEquals(2, actionCallMethod.getFieldValue(1).getNature());
assertEquals("java.lang.Integer", actionCallMethod.getFieldValue(1).getType());
assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Aggregations