Title: [2052] trunk: Add ReflectionProvider.getFieldOrNull(Class, String) and implement it in all classes implementing the interface (XSTR-722).

Diff

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java (2051 => 2052)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java	2013-03-19 02:23:49 UTC (rev 2051)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java	2013-03-19 21:57:14 UTC (rev 2052)
@@ -181,6 +181,10 @@
         return fieldDictionary.field(definedIn, fieldName, null);
     }
 
+    public Field getFieldOrNull(Class definedIn, String fieldName) {
+        return fieldDictionary.fieldOrNull(definedIn, fieldName,  null);
+    }
+
     public void setFieldDictionary(FieldDictionary dictionary) {
         this.fieldDictionary = dictionary;
     }

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java (2051 => 2052)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java	2013-03-19 02:23:49 UTC (rev 2051)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java	2013-03-19 21:57:14 UTC (rev 2052)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2004, 2006 Joe Walnes.
- * Copyright (C) 2006, 2007 XStream Committers.
+ * Copyright (C) 2006, 2007, 2013 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -13,6 +13,7 @@
 
 import java.lang.reflect.Field;
 
+
 /**
  * Provides core reflection services.
  * 
@@ -20,12 +21,13 @@
  */
 public interface ReflectionProvider {
 
-	/**
-	 * Creates a new instance of the specified type. It is in the responsibility
-         * of the implementation how such an instance is created.
-	 * @param type	the type to instantiate
-	 * @return	a new instance of this type
-	 */
+    /**
+     * Creates a new instance of the specified type. It is in the responsibility of the
+     * implementation how such an instance is created.
+     * 
+     * @param type the type to instantiate
+     * @return a new instance of this type
+     */
     Object newInstance(Class type);
 
     void visitSerializableFields(Object object, Visitor visitor);
@@ -38,26 +40,37 @@
 
     /**
      * A visitor interface for serializable fields defined in a class.
-     *
      */
     interface Visitor {
 
-    	/**
-    	 * Callback for each visit
-    	 * @param name	field name
-    	 * @param type	field type
-    	 * @param definedIn	where the field was defined
-    	 * @param value	field value
-    	 */
+        /**
+         * Callback for each visit
+         * 
+         * @param name field name
+         * @param type field type
+         * @param definedIn where the field was defined
+         * @param value field value
+         */
         void visit(String name, Class type, Class definedIn, Object value);
     }
 
     /**
      * Returns a field defined in some class.
-     * @param definedIn	class where the field was defined
-     * @param fieldName	field name
-     * @return	the field itself
+     * 
+     * @param definedIn class where the field was defined
+     * @param fieldName field name
+     * @return the field itself
+     * @throws ObjectAccessException if field does not exist
      */
-	Field getField(Class definedIn, String fieldName);
+    Field getField(Class definedIn, String fieldName);
 
+    /**
+     * Returns a field defined in some class.
+     * 
+     * @param definedIn class where the field was defined
+     * @param fieldName field name
+     * @return the field itself or null
+     * @since upcoming
+     */
+    Field getFieldOrNull(Class definedIn, String fieldName);
 }

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java (2051 => 2052)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java	2013-03-19 02:23:49 UTC (rev 2051)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java	2013-03-19 21:57:14 UTC (rev 2052)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 XStream Committers.
+ * Copyright (C) 2006, 2007, 2013 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -34,6 +34,10 @@
         return this.wrapped.getField(definedIn, fieldName);
     }
 
+    public Field getFieldOrNull(Class definedIn, String fieldName) {
+        return this.wrapped.getFieldOrNull(definedIn, fieldName);
+    }
+
     public Class getFieldType(Object object, String fieldName, Class definedIn) {
         return this.wrapped.getFieldType(object, fieldName, definedIn);
     }

Modified: trunk/xstream-distribution/src/content/changes.html (2051 => 2052)


--- trunk/xstream-distribution/src/content/changes.html	2013-03-19 02:23:49 UTC (rev 2051)
+++ trunk/xstream-distribution/src/content/changes.html	2013-03-19 21:57:14 UTC (rev 2052)
@@ -69,6 +69,7 @@
     <h2>API changes</h2>
 
     <ul>
+    	<li>JIRA:XSTR-722: Add ReflectionProvider.getFieldOrNull(Class, String).</li>
     	<li>Deprecated constructor c.t.x.converters.extended.RegexPatternConverter(Converter)
     	in favor of c.t.x.converters.extended.RegexPatternConverter().</li>
     	<li>Deprecated constructor c.t.x.converters.extended.ThrowableConverter(Converter)

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to