[jboss-svn-commits] JBL Code SVN: r29193 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/asm.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Sep 5 06:21:42 EDT 2009
Author: nheron
Date: 2009-09-05 06:21:42 -0400 (Sat, 05 Sep 2009)
New Revision: 29193
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/asm/ClassFieldInspector.java
Log:
GUVNOR-263 : forgot to commit
Guided editor : How to check if a list contains an object
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/asm/ClassFieldInspector.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/asm/ClassFieldInspector.java 2009-09-05 09:17:40 UTC (rev 29192)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/asm/ClassFieldInspector.java 2009-09-05 10:21:42 UTC (rev 29193)
@@ -21,6 +21,7 @@
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -48,35 +49,38 @@
public class ClassFieldInspector {
private final Map<String, Integer> fieldNames = new HashMap<String, Integer>();
- private final Map<String, Class< ? >> fieldTypes = new HashMap<String, Class< ? >>();
+ private final Map<String, Class <?>> fieldTypes = new HashMap<String, Class <?>>();
+ private final Map<String, Field> fieldTypesField= new HashMap<String, Field>();
private final Map<String, Method> getterMethods = new HashMap<String, Method>();
private final Map<String, Method> setterMethods = new HashMap<String, Method>();
private final Set<String> nonGetters = new HashSet<String>();
+ private Class< ? > classUnderInspection = null;
/**
- * @param clazz The class sthat the fields to be shadowed are extracted for.
+ * @param classUnderInspection The class sthat the fields to be shadowed are extracted for.
* @throws IOException
*/
- public ClassFieldInspector(final Class< ? > clazz) throws IOException {
- this( clazz,
+ public ClassFieldInspector(final Class< ? > classUnderInspection) throws IOException {
+ this(classUnderInspection,
true );
}
- public ClassFieldInspector(final Class< ? > clazz,
+ public ClassFieldInspector(final Class< ? > classUnderInspection,
final boolean includeFinalMethods) throws IOException {
- final String name = getResourcePath( clazz );
- final InputStream stream = clazz.getResourceAsStream( name );
+ this.classUnderInspection = classUnderInspection;
+ final String name = getResourcePath(classUnderInspection);
+ final InputStream stream = classUnderInspection.getResourceAsStream( name );
if ( stream != null ) {
try {
- processClassWithByteCode( clazz,
+ processClassWithByteCode(classUnderInspection,
stream,
includeFinalMethods );
} finally {
stream.close();
}
} else {
- processClassWithoutByteCode( clazz,
+ processClassWithoutByteCode(classUnderInspection,
includeFinalMethods );
}
}
@@ -142,7 +146,7 @@
// want public methods that start with 'get' or 'is' and have no args, and return a value
final int fieldIndex = this.fieldNames.size();
addToMapping( methods[i],
- fieldIndex );
+ fieldIndex);
} else if ( ((methods[i].getModifiers() & mask) == Opcodes.ACC_PUBLIC) && (methods[i].getParameterTypes().length == 1) && (methods[i].getName().startsWith( "set" )) ) {
@@ -173,7 +177,14 @@
/**
* @return A mapping of field types (unboxed).
*/
- public Map<String, Class< ? >> getFieldTypes() {
+ public Map<String, Field> getFieldTypesField() {
+ return this.fieldTypesField;
+ }
+ /**
+ * @return A mapping of field types (unboxed).
+ */
+ public Map<String,Class <?>> getFieldTypes() {
+
return this.fieldTypes;
}
@@ -254,6 +265,12 @@
*/
private void storeGetterSetter(final Method method,
final String fieldName) {
+ Field f = null;
+ try {
+ f = classUnderInspection.getDeclaredField(fieldName);
+ } catch (NoSuchFieldException e) {
+ // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
if ( method.getName().startsWith( "set" ) ) {
this.setterMethods.put( fieldName,
method );
@@ -261,11 +278,17 @@
this.fieldTypes.put( fieldName,
method.getParameterTypes()[0] );
}
+ if ( !fieldTypesField.containsKey( fieldName ) ) {
+ this.fieldTypesField.put( fieldName,
+ f );
+ }
} else {
this.getterMethods.put( fieldName,
method );
this.fieldTypes.put( fieldName,
method.getReturnType() );
+ this.fieldTypesField.put( fieldName,
+ f );
}
}
More information about the jboss-svn-commits
mailing list