Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute generated resolvers - getters should take precedence over fields #30609

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2542,17 +2542,7 @@ private static AnnotationTarget findProperty(String name, ClassInfo clazz, Looku
if (interfaceNames != null) {
addInterfaces(clazz, config.index(), interfaceNames);
}
// Fields
for (FieldInfo field : clazz.fields()) {
if (!config.filter().test(field)) {
continue;
}
if (field.name().equals(name)) {
// Name matches and it's either an enum constant or a non-static field
return field;
}
}
// Methods
// Methods; getters should take precedence over fields
for (MethodInfo method : clazz.methods()) {
if (method.returnType().kind() != org.jboss.jandex.Type.Kind.VOID
&& config.filter().test(method)
Expand All @@ -2563,6 +2553,16 @@ private static AnnotationTarget findProperty(String name, ClassInfo clazz, Looku
return method;
}
}
// Fields
for (FieldInfo field : clazz.fields()) {
if (!config.filter().test(field)) {
continue;
}
if (field.name().equals(name)) {
// Name matches and it's either an enum constant or a non-static field
return field;
}
}
DotName superName = clazz.superName();
if (config.declaredMembersOnly() || superName == null) {
clazz = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,35 +350,6 @@ private boolean implementResolve(ClassCreator valueResolver, String clazzName, C

BytecodeCreator zeroParamsBranch = resolve.ifZero(paramsCount).trueBranch();

for (FieldInfo field : fields) {
String getterName = fieldToGetterFun != null ? fieldToGetterFun.apply(field) : null;
if (getterName != null && noneMethodMatches(methods, getterName)) {
LOGGER.debugf("Forced getter added: %s", field);
BytecodeCreator getterMatch = zeroParamsBranch.createScope();
// Match the getter name
BytecodeCreator notMatched = getterMatch.ifTrue(Gizmo.equals(getterMatch, getterMatch.load(getterName),
name)).falseBranch();
// Match the property name
notMatched.ifTrue(Gizmo.equals(notMatched, notMatched.load(field.name()),
name)).falseBranch().breakScope(getterMatch);
ResultHandle value = getterMatch.invokeVirtualMethod(
MethodDescriptor.ofMethod(clazz.name().toString(), getterName,
DescriptorUtils.typeToString(field.type())),
base);
getterMatch.returnValue(getterMatch.invokeStaticMethod(Descriptors.COMPLETED_STAGE, value));
} else {
LOGGER.debugf("Field added: %s", field);
// Match field name
BytecodeCreator fieldMatch = zeroParamsBranch
.ifTrue(Gizmo.equals(zeroParamsBranch, resolve.load(field.name()), name))
.trueBranch();
ResultHandle value = fieldMatch
.readInstanceField(FieldDescriptor.of(clazzName, field.name(), field.type().name().toString()),
base);
fieldMatch.returnValue(fieldMatch.invokeStaticMethod(Descriptors.COMPLETED_STAGE, value));
}
}

if (!noParamMethods.isEmpty()) {
Switch.StringSwitch nameSwitch = zeroParamsBranch.stringSwitch(name);
Set<String> matchedNames = new HashSet<>();
Expand Down Expand Up @@ -421,6 +392,35 @@ public void accept(BytecodeCreator bc) {
}
}

for (FieldInfo field : fields) {
String getterName = fieldToGetterFun != null ? fieldToGetterFun.apply(field) : null;
if (getterName != null && noneMethodMatches(methods, getterName)) {
LOGGER.debugf("Forced getter added: %s", field);
BytecodeCreator getterMatch = zeroParamsBranch.createScope();
// Match the getter name
BytecodeCreator notMatched = getterMatch.ifTrue(Gizmo.equals(getterMatch, getterMatch.load(getterName),
name)).falseBranch();
// Match the property name
notMatched.ifTrue(Gizmo.equals(notMatched, notMatched.load(field.name()),
name)).falseBranch().breakScope(getterMatch);
ResultHandle value = getterMatch.invokeVirtualMethod(
MethodDescriptor.ofMethod(clazz.name().toString(), getterName,
DescriptorUtils.typeToString(field.type())),
base);
getterMatch.returnValue(getterMatch.invokeStaticMethod(Descriptors.COMPLETED_STAGE, value));
} else {
LOGGER.debugf("Field added: %s", field);
// Match field name
BytecodeCreator fieldMatch = zeroParamsBranch
.ifTrue(Gizmo.equals(zeroParamsBranch, resolve.load(field.name()), name))
.trueBranch();
ResultHandle value = fieldMatch
.readInstanceField(FieldDescriptor.of(clazzName, field.name(), field.type().name().toString()),
base);
fieldMatch.returnValue(fieldMatch.invokeStaticMethod(Descriptors.COMPLETED_STAGE, value));
}
}

// Match methods by name and number of params
for (Entry<Match, List<MethodInfo>> entry : matches.entrySet()) {
Match match = entry.getKey();
Expand Down Expand Up @@ -1308,10 +1308,6 @@ public MethodKey(MethodInfo method) {
}
}

public MethodInfo getMethod() {
return method;
}

@Override
public int compareTo(MethodKey other) {
// compare the name, then number of params and param type names
Expand Down