[jboss-svn-commits] JBL Code SVN: r31269 - in labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src: main/java/org/drools/guvnor/server/rules and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 27 16:24:14 EST 2010
Author: baunax
Date: 2010-01-27 16:24:14 -0500 (Wed, 27 Jan 2010)
New Revision: 31269
Added:
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/ClassToGenericClassConverter.java
Modified:
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/util/ClassMethodInspectorTest.java
Log:
added method info to generic type
Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java 2010-01-27 21:23:31 UTC (rev 31268)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java 2010-01-27 21:24:14 UTC (rev 31269)
@@ -16,6 +16,7 @@
private List<String> params;
private String returnClassType;
private String parametricReturnType;
+ private String genericType;
public MethodInfo() {
}
@@ -29,11 +30,12 @@
* @param returnType
* method's return type
*/
- public MethodInfo(String name, List<String> params, Class<?> returnType, String parametricReturnType) {
+ public MethodInfo(String name, List<String> params, Class<?> returnType, String parametricReturnType, String genericType) {
this.name = name;
this.params = params;
this.returnClassType = returnType.getName();
this.parametricReturnType = parametricReturnType;
+ this.genericType = genericType;
}
public String getNameWithParameters() {
@@ -65,6 +67,10 @@
return parametricReturnType;
}
+ public String getGenericType() {
+ return genericType;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
Added: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/ClassToGenericClassConverter.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/ClassToGenericClassConverter.java (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/ClassToGenericClassConverter.java 2010-01-27 21:24:14 UTC (rev 31269)
@@ -0,0 +1,13 @@
+package org.drools.guvnor.server.rules;
+
+public interface ClassToGenericClassConverter {
+
+ /**
+ * @param inspector
+ * @param fields
+ * @param i
+ * @return
+ */
+ String translateClassToGenericType(final Class<?> type);
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/ClassToGenericClassConverter.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java 2010-01-27 21:23:31 UTC (rev 31268)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java 2010-01-27 21:24:14 UTC (rev 31269)
@@ -57,7 +57,7 @@
*
* @author Michael Neale
*/
-public class SuggestionCompletionLoader {
+public class SuggestionCompletionLoader implements ClassToGenericClassConverter {
private final SuggestionCompletionEngineBuilder builder = new SuggestionCompletionEngineBuilder();
@@ -328,7 +328,7 @@
} else {
try {
Class clz = resolver.resolveType(fieldClass);
- this.builder.addFieldType(declaredType + "." + fieldName, getFieldType(clz),clz);
+ this.builder.addFieldType(declaredType + "." + fieldName, translateClassToGenericType(clz),clz);
} catch (ClassNotFoundException e) {
this.errors.add("Class of field not found: " + fieldClass);
}
@@ -373,7 +373,7 @@
this.errors.add("Fact template field type not found: " + fieldType);
}
this.builder.addFieldType(factType + "." + fieldDescr.getName(),
- getFieldType(fieldTypeClass),fieldTypeClass);
+ translateClassToGenericType(fieldTypeClass),fieldTypeClass);
}
Arrays.sort(fields);
@@ -442,13 +442,13 @@
for (String field : fieldSet) {
final Class<?> type = inspector.getFieldTypes().get(field);
- final String fieldType = getFieldType(type);
+ final String fieldType = translateClassToGenericType(type);
this.builder.addFieldType(shortTypeName + "." + field, fieldType,type);
Field f = inspector.getFieldTypesField().get(field);
this.builder.addFieldTypeField(shortTypeName + "." + field,f);
}
- ClassMethodInspector methodInspector = new ClassMethodInspector(clazz);
+ ClassMethodInspector methodInspector = new ClassMethodInspector(clazz, this);
List<MethodInfo> methodInfos = methodInspector.getMethodInfos();
for (MethodInfo mi : methodInfos) {
@@ -504,13 +504,11 @@
}
}
- /**
- * @param inspector
- * @param fields
- * @param i
- * @return
- */
- private String getFieldType(final Class type) {
+ /* (non-Javadoc)
+ * @see org.drools.guvnor.server.rules.ClassToGenericClassConverter#translateClassToGenericType(java.lang.Class)
+ */
+ //XXX {bauna} field type
+ public String translateClassToGenericType(final Class<?>type) {
String fieldType = null; // if null, will use standard operators
if (type != null) {
if (type.isPrimitive() && (type != boolean.class)) {
Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java 2010-01-27 21:23:31 UTC (rev 31268)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java 2010-01-27 21:24:14 UTC (rev 31269)
@@ -11,6 +11,7 @@
import java.util.Set;
import org.drools.guvnor.client.modeldriven.MethodInfo;
+import org.drools.guvnor.server.rules.ClassToGenericClassConverter;
/**
*
@@ -24,7 +25,7 @@
private final Set<MethodInfo> methods = new HashSet<MethodInfo>();
- public ClassMethodInspector(final Class< ? > clazz) throws IOException {
+ public ClassMethodInspector(final Class< ? > clazz, ClassToGenericClassConverter converter) throws IOException {
Method[] methods = clazz.getDeclaredMethods();
for ( int i = 0; i < methods.length; i++ ) {
@@ -37,11 +38,11 @@
Class<?>[] listParam = aMethod.getParameterTypes();
-
MethodInfo info = new MethodInfo(methodName,
solveParams(listParam), aMethod.getReturnType(),
SuggestionCompletionEngineBuilder
- .obtainGenericType(aMethod.getGenericReturnType()));
+ .obtainGenericType(aMethod.getGenericReturnType()),
+ converter.translateClassToGenericType(clazz));
this.methods.add(info);
}
}
Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/util/ClassMethodInspectorTest.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/util/ClassMethodInspectorTest.java 2010-01-27 21:23:31 UTC (rev 31268)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/util/ClassMethodInspectorTest.java 2010-01-27 21:24:14 UTC (rev 31269)
@@ -22,6 +22,8 @@
import java.util.Map;
import java.util.Set;
+import org.drools.guvnor.server.rules.ClassToGenericClassConverter;
+
import junit.framework.TestCase;
/**
@@ -32,7 +34,7 @@
public class ClassMethodInspectorTest extends TestCase {
public void testSimpleMethods() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( SimpleMethods.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( SimpleMethods.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -41,7 +43,7 @@
}
public void testMoreThanOneMethodWithTheSameName() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( MoreThanOneMethodWithTheSameName.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( MoreThanOneMethodWithTheSameName.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -51,7 +53,7 @@
}
public void testCollection() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( Collection.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( Collection.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -60,7 +62,7 @@
}
public void testArrayList() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( ArrayList.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( ArrayList.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -69,7 +71,7 @@
}
public void testList() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( List.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( List.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -78,7 +80,7 @@
}
public void testSet() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( Set.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( Set.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -87,7 +89,7 @@
}
public void testMap() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( Map.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( Map.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -96,7 +98,7 @@
}
public void testMyMap() throws Exception {
- final ClassMethodInspector ext = new ClassMethodInspector( MyMap.class );
+ final ClassMethodInspector ext = new ClassMethodInspector( MyMap.class, new Converter() );
for ( String s : ext.getMethodNames() ) {
assertFalse( "Method " + s + " is not allowed.",
@@ -206,4 +208,12 @@
}
}
+
+ private static class Converter implements ClassToGenericClassConverter {
+
+ public String translateClassToGenericType(Class<?> type) {
+ return null;
+ }
+
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list