Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit aa66379

Browse files
committed
Use field names instead of value ids for ValueAccessor
If multiple fields had the same id, but different parents, they would all have the same value. This uses field name to retrieve getter/setter lambda functions rather than label id to prevent conflict.
1 parent 3a9a12d commit aa66379

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/main/java/clientapi/load/transform/impl/ValueAccessorTransformer.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public final void transform(ClassNode cn) {
8383
if (!an.desc.equals("Lclientapi/util/annotation/Label;"))
8484
continue;
8585

86-
for (int i = 0; i < an.values.size(); i++) {
87-
if (i % 2 == 0 && an.values.get(i).equals("id")) {
88-
fieldCache.put(an.values.get(i + 1).toString(), fn);
89-
}
90-
}
86+
fieldCache.put(fn.name, fn);
9187
}
9288
}
9389

@@ -135,7 +131,7 @@ private void createFieldGetter(ClassNode cn) {
135131
// Create label for IF statement jump
136132
Label skip = new Label();
137133

138-
// Compare the target value with the expected valu
134+
// Compare the target value with the expected value
139135
mn.visitVarInsn(ALOAD, 1);
140136
mn.visitLdcInsn(id);
141137
mn.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);

src/main/java/clientapi/value/Value.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public Value(String name, String parent, String id, String description, Object o
105105

106106
// Accessor
107107
this.direct = object instanceof ValueAccessor;
108-
this.setter = direct ? ((ValueAccessor) object).getFieldSetter(id) : null;
109-
this.getter = direct ? ((ValueAccessor) object).getFieldGetter(id) : null;
108+
this.setter = direct ? ((ValueAccessor) object).getFieldSetter(field.getName()) : null;
109+
this.getter = direct ? ((ValueAccessor) object).getFieldGetter(field.getName()) : null;
110110
}
111111

112112
@Override

src/main/java/clientapi/value/holder/ValueAccessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public interface ValueAccessor {
3535

3636
/**
3737
* Returns a supplier that can be used to get
38-
* the value of the target field. (By id)
38+
* the value of the target field. (By field name)
3939
*
40-
* @param id The ID of the field
40+
* @param field The name of the field
4141
* @return The supplier "getter"
4242
*/
43-
Supplier<Object> getFieldGetter(String id);
43+
Supplier<Object> getFieldGetter(String field);
4444

4545
/**
4646
* Returns a consumer that can be used to set the
47-
* value of the target field. (By id)
47+
* value of the target field. (By field name)
4848
*
49-
* @param id The ID of the field
49+
* @param field The name of the field
5050
* @return The consumer "setter"
5151
*/
52-
Consumer<Object> getFieldSetter(String id);
52+
Consumer<Object> getFieldSetter(String field);
5353
}

0 commit comments

Comments
 (0)