Author: shane.bryzak(a)jboss.com
Date: 2010-06-23 21:25:21 -0400 (Wed, 23 Jun 2010)
New Revision: 6575
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
Log:
fix query logic, exclude duplicate properties from result
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-21
12:43:30 UTC (rev 6574)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-24
01:25:21 UTC (rev 6575)
@@ -43,36 +43,52 @@
{
List<Property<V>> results = new ArrayList<Property<V>>();
- Class<?> cls = targetClass;
+ // First check public methods (we ignore private methods)
+ for (Method method : targetClass.getMethods())
+ {
+ boolean match = true;
+ for (PropertyCriteria c : criteria)
+ {
+ if (!c.methodMatches(method))
+ {
+ match = false;
+ }
+ }
+ if (match) results.add(Properties.<V>createProperty(method));
+ }
+
+ Class<?> cls = targetClass;
while (!cls.equals(Object.class))
{
- // First check declared fields
+ // Now check declared fields
for (Field field : cls.getDeclaredFields())
{
+ boolean match = true;
for (PropertyCriteria c : criteria)
{
- if (c.fieldMatches(field))
+ if (!c.fieldMatches(field))
{
- results.add(Properties.<V>createProperty(field));
+ match = false;
}
}
+ Property<V> prop = Properties.<V>createProperty(field);
+
+ if (match && !resultsContainsProperty(results, prop.getName()))
results.add(prop);
}
cls = cls.getSuperclass();
}
-
- // Then check public methods (we ignore private methods)
- for (Method method : targetClass.getMethods())
- {
- for (PropertyCriteria c : criteria)
- {
- if (c.methodMatches(method))
- {
- results.add(Properties.<V>createProperty(method));
- }
- }
- }
+
return results;
}
+
+ private boolean resultsContainsProperty(List<Property<V>> results, String
propertyName)
+ {
+ for (Property<V> p : results)
+ {
+ if (propertyName.equals(p.getName())) return true;
+ }
+ return false;
+ }
}
Show replies by date