This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch TAP5-2770
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/TAP5-2770 by this push:
new 7875dfa94 TAP5-2770: fixing JavaDoc errors
7875dfa94 is described below
commit 7875dfa945124e24238664e6e0fca73b0c143778
Author: Thiago H. de Paula Figueiredo <[email protected]>
AuthorDate: Wed Dec 20 21:42:51 2023 -0300
TAP5-2770: fixing JavaDoc errors
---
.../tapestry5/plastic/FieldValueProvider.java | 2 +-
.../org/apache/tapestry5/plastic/PlasticUtils.java | 29 ++++++++++++++++-----
.../tapestry5/plastic/PropertyValueProvider.java | 8 +++---
.../apache/tapestry5/plastic/PlasticUtilsTest.java | 30 ++++++++++++++--------
4 files changed, 46 insertions(+), 23 deletions(-)
diff --git
a/plastic/src/main/java/org/apache/tapestry5/plastic/FieldValueProvider.java
b/plastic/src/main/java/org/apache/tapestry5/plastic/FieldValueProvider.java
index 79087e8b8..c964530f5 100644
--- a/plastic/src/main/java/org/apache/tapestry5/plastic/FieldValueProvider.java
+++ b/plastic/src/main/java/org/apache/tapestry5/plastic/FieldValueProvider.java
@@ -19,7 +19,7 @@ package org.apache.tapestry5.plastic;
* Interface that can be implemented to provide access to field values based
on their name.
* Usually implemented with {@linkplain
PlasticUtils#implementFieldValueProvider(PlasticClass, java.util.Set)},
* which doesn't use reflection.
- * <p/>
+ * </p>
* <p>
* The name of its abstract method is intended to avoid clashes with other
existing methods
* in the class.
diff --git
a/plastic/src/main/java/org/apache/tapestry5/plastic/PlasticUtils.java
b/plastic/src/main/java/org/apache/tapestry5/plastic/PlasticUtils.java
index 9c35d3428..e9d469c3b 100644
--- a/plastic/src/main/java/org/apache/tapestry5/plastic/PlasticUtils.java
+++ b/plastic/src/main/java/org/apache/tapestry5/plastic/PlasticUtils.java
@@ -39,10 +39,13 @@ public class PlasticUtils
private static final MethodDescription
PROPERTY_VALUE_PROVIDER_METHOD_DESCRIPTION;
+ private static final MethodDescription
FIELD_VALUE_PROVIDER_METHOD_DESCRIPTION;
+
static
{
try {
PROPERTY_VALUE_PROVIDER_METHOD_DESCRIPTION = new
MethodDescription(PropertyValueProvider.class.getMethod("__propertyValueProvider__get",
String.class));
+ FIELD_VALUE_PROVIDER_METHOD_DESCRIPTION = new
MethodDescription(FieldValueProvider.class.getMethod("__fieldValueProvider__get",
String.class));
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
@@ -185,10 +188,10 @@ public class PlasticUtils
* an {@linkplain IllegalAccessError}.
*
* @param plasticClass a {@linkplain PlasticClass} instance.
- * @param fieldNames a {@linkplain Set} of {@linkplain String}s containing
the field names.
+ * @param fieldInfos a {@linkplain Set} of {@linkplain String}s containing
the field names.
* @since 5.8.4
*/
- public static void implementFieldValueProvider(PlasticClass plasticClass,
Set<FieldInfo> fields)
+ public static void implementFieldValueProvider(PlasticClass plasticClass,
Set<FieldInfo> fieldInfos)
{
final Set<PlasticMethod> methods =
plasticClass.introduceInterface(FieldValueProvider.class);
@@ -199,7 +202,7 @@ public class PlasticUtils
method.changeImplementation((builder) -> {
- for (FieldInfo field : fields)
+ for (FieldInfo field : fieldInfos)
{
builder.loadArgument(0);
builder.loadConstant(field.name);
@@ -212,6 +215,18 @@ public class PlasticUtils
});
}
+ builder.loadThis();
+ builder.instanceOf(FieldValueProvider.class);
+
+ builder.when(Condition.NON_ZERO, ifBuilder -> {
+ builder.loadThis();
+ builder.loadArgument(0);
+ ifBuilder.invokeSpecial(
+ plasticClass.getSuperClassName(),
+ FIELD_VALUE_PROVIDER_METHOD_DESCRIPTION);
+ ifBuilder.returnResult();
+ });
+
builder.throwException(RuntimeException.class, "Field not
found or not supported");
});
@@ -227,17 +242,17 @@ public class PlasticUtils
* of direct fields access.
*
* @param plasticClass a {@linkplain PlasticClass} instance.
- * @param fieldNames a {@linkplain Set} of {@linkplain String}s containing
the filed (i.e. property) names.
+ * @param fieldInfos a {@linkplain Set} of {@linkplain String}s containing
the filed (i.e. property) names.
* @since 5.8.4
*/
- public static void implementPropertyValueProvider(PlasticClass
plasticClass, Set<FieldInfo> fields)
+ public static void implementPropertyValueProvider(PlasticClass
plasticClass, Set<FieldInfo> fieldInfos)
{
final Set<PlasticMethod> methods =
plasticClass.introduceInterface(PropertyValueProvider.class);
final InstructionBuilderCallback callback = (builder) -> {
- for (FieldInfo field : fields)
+ for (FieldInfo field : fieldInfos)
{
builder.loadArgument(0);
builder.loadConstant(field.name);
@@ -266,7 +281,7 @@ public class PlasticUtils
builder.loadArgument(0);
ifBuilder.invokeSpecial(
plasticClass.getSuperClassName(),
- PROPERTY_VALUE_PROVIDER_METHOD_DESCRIPTION);
+ FIELD_VALUE_PROVIDER_METHOD_DESCRIPTION);
ifBuilder.returnResult();
});
diff --git
a/plastic/src/main/java/org/apache/tapestry5/plastic/PropertyValueProvider.java
b/plastic/src/main/java/org/apache/tapestry5/plastic/PropertyValueProvider.java
index bbba55a3b..3f841b82d 100644
---
a/plastic/src/main/java/org/apache/tapestry5/plastic/PropertyValueProvider.java
+++
b/plastic/src/main/java/org/apache/tapestry5/plastic/PropertyValueProvider.java
@@ -14,18 +14,16 @@
package org.apache.tapestry5.plastic;
-import java.lang.reflect.Method;
-
/**
* <p>
* Interface that can be implemented to provide access to field values based
on their name.
- * Usually implemented with {@linkplain} FieldValueProviderTransformation}.
- * <p/>
+ * Usually implemented with {@linkplain
PlasticUtils#implementPropertyValueProvider(PlasticClass, java.util.Set)}.
+ * </p>
* <p>
* The name of its abstract method is intended to avoid clashes with other
existing methods
* in the class.
* </p>
- * @see FieldValueProviderTransformation
+ * @see PlasticUtils#implementPropertyValueProvider(PlasticClass,
java.util.Set)
* @since 5.8.4
*/
public interface PropertyValueProvider
diff --git
a/plastic/src/test/java/org/apache/tapestry5/plastic/PlasticUtilsTest.java
b/plastic/src/test/java/org/apache/tapestry5/plastic/PlasticUtilsTest.java
index 3d0e4f14f..40faac5d2 100644
--- a/plastic/src/test/java/org/apache/tapestry5/plastic/PlasticUtilsTest.java
+++ b/plastic/src/test/java/org/apache/tapestry5/plastic/PlasticUtilsTest.java
@@ -31,28 +31,38 @@ import org.junit.jupiter.api.Test;
public class PlasticUtilsTest
{
- public static void main(String[] args) throws ClassNotFoundException {
- final PlasticUtilsTest plasticUtilsTest = new PlasticUtilsTest();
- plasticUtilsTest.implement_field_value_pProvider();
- plasticUtilsTest.implement_property_value_provider();
- }
+// public static void main(String[] args) throws ClassNotFoundException {
+// final PlasticUtilsTest plasticUtilsTest = new PlasticUtilsTest();
+// plasticUtilsTest.implement_field_value_provider();
+// plasticUtilsTest.implement_property_value_provider();
+// }
@Test
- public void implement_field_value_pProvider() throws ClassNotFoundException
+ public void implement_field_value_provider() throws ClassNotFoundException
{
Set<String> packages = new HashSet<>();
packages.add(PlasticUtilsTestObject.class.getPackage().getName());
+
PlasticManager plasticManager = PlasticManager.withContextClassLoader()
.packages(packages).create();
- final PlasticClassTransformation<Object> transformation =
plasticManager.getPlasticClass(PlasticUtilsTestObject.class.getName());
- PlasticClass pc = transformation.getPlasticClass();
+
Set<PlasticUtils.FieldInfo> fieldInfos = new
HashSet<PlasticUtils.FieldInfo>();
+
+ PlasticClassTransformation<Object> transformation2 =
plasticManager.getPlasticClass(PlasticUtilsTestObjectSuperclass.class.getName());
+ PlasticClass pc2 = transformation2.getPlasticClass();
+ fieldInfos.clear();
+ fieldInfos.add(new PlasticUtils.FieldInfo("superString",
"java.lang.String"));
+ PlasticUtils.implementFieldValueProvider(pc2, fieldInfos);
+
+ PlasticClassTransformation<Object> transformation =
plasticManager.getPlasticClass(PlasticUtilsTestObject.class.getName());
+ PlasticClass pc = transformation.getPlasticClass();
for (PlasticField field : pc.getAllFields()) {
fieldInfos.add(PlasticUtils.toFieldInfo(field));
}
- fieldInfos.add(new PlasticUtils.FieldInfo("superString",
"java.lang.String"));
PlasticUtils.implementFieldValueProvider(pc, fieldInfos);
+
+
Object object = transformation.createInstantiator().newInstance();
Class<?> original = PlasticUtilsTestObject.class;
@@ -66,7 +76,7 @@ public class PlasticUtilsTest
assertEquals(PlasticUtilsTestObject.ENUMERATION.toString(),
FieldValueProvider.get(object, "enumeration").toString());
assertTrue(Arrays.equals(PlasticUtilsTestObject.INT_ARRAY, (int[])
FieldValueProvider.get(object, "intArray")));
assertEquals(PlasticUtilsTestObject.TRUE_OF_FALSE, (Boolean)
FieldValueProvider.get(object, "trueOrFalse"));
-
+// assertEquals(PlasticUtilsTestObjectSuperclass.SUPER,
FieldValueProvider.get(object, "superString"));
}
@Test