Skip to content

Commit

Permalink
BZ-1044973 - Guided rule editor does not let the user to set objects…
Browse files Browse the repository at this point in the history
… as a parameters for method calls that have objects super type as a parameter

(cherry picked from commit 02ffd6a)

Conflicts:
	drools-workbench-models/drools-workbench-models-commons/src/test/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceUnmarshallingTest.java
  • Loading branch information
Rikkola committed Mar 18, 2014
1 parent 11f2104 commit db9ab92
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
Expand Up @@ -116,21 +116,55 @@ private String getDataType( String param,
}

private MethodInfo getMethodInfo() {
String variableType = boundParams.get( variable );
if ( variableType != null ) {
List<MethodInfo> methods = getMethodInfosForType( model,
dmo,
variableType );
if ( methods != null ) {
for ( MethodInfo method : methods ) {
if ( method.getName().equals( methodName ) ) {
return method;
String variableType = boundParams.get(variable);
if (variableType != null) {
List<MethodInfo> methods = getMethodInfosForType(model,
dmo,
variableType);
if (methods != null) {

ArrayList<MethodInfo> methodInfos = getMethodInfos(methodName, methods);

if (methodInfos.size() > 1) {
// Now if there were more than one method with the same name
// we need to start figuring out what is the correct one.
for (MethodInfo methodInfo : methodInfos) {
if (compareParameters(methodInfo.getParams())) {
return methodInfo;
}
}
} else if (!methodInfos.isEmpty()){
// Not perfect, but works on most cases.
// There is no check if the parameter types match.
return methodInfos.get(0);
}
}
}

return null;
}

private ArrayList<MethodInfo> getMethodInfos(String methodName, List<MethodInfo> methods) {
ArrayList<MethodInfo> result = new ArrayList<MethodInfo>();
for (MethodInfo method : methods) {
if (method.getName().equals(methodName)) {
result.add(method);
}
}
return result;
}

private boolean compareParameters(List<String> methodParams) {
if (methodParams.size() != parameters.length) {
return false;
} else {
for (int index = 0; index < methodParams.size(); index++) {
if (!methodParams.get(index).equals(boundParams.get(parameters[index]))) {
return false;
}
}
return true;
}
}

}
Expand Up @@ -3271,7 +3271,6 @@ public void testDSLExpansionRHS() {
}

@Test
@Ignore("Still does not know the difference between indexOf(int) and indexOf(String) ")
public void testFunctionCalls() {
String drl =
"package org.mortgages\n" +
Expand All @@ -3287,21 +3286,19 @@ public void testFunctionCalls() {
+ "end\n";

Map<String, List<MethodInfo>> methodInformation = new HashMap<String, List<MethodInfo>>();
List<MethodInfo> mapMethodInformation1 = new ArrayList<MethodInfo>();
mapMethodInformation1.add( new MethodInfo( "indexOf",
List<MethodInfo> mapMethodInformation = new ArrayList<MethodInfo>();
mapMethodInformation.add( new MethodInfo( "indexOf",
Arrays.asList( new String[]{ "String" } ),
"int",
null,
"String" ) );
List<MethodInfo> mapMethodInformation2 = new ArrayList<MethodInfo>();
mapMethodInformation2.add( new MethodInfo( "indexOf",
mapMethodInformation.add( new MethodInfo( "indexOf",
Arrays.asList( new String[]{ "Integer" } ),
"int",
null,
"String" ) );

methodInformation.put( "java.lang.String", mapMethodInformation2 );
methodInformation.put( "java.lang.String", mapMethodInformation1 );
methodInformation.put( "java.lang.String", mapMethodInformation );

when( dmo.getProjectMethodInformation() ).thenReturn( methodInformation );

Expand Down

0 comments on commit db9ab92

Please sign in to comment.