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

Take into account that configuration properties can contain a dot in RunTimeConfigurationGenerator #26960

Merged
merged 1 commit into from
Aug 1, 2022
Merged
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 @@ -1310,10 +1310,7 @@ private MethodDescriptor generateParserBody(final ConfigPatternMap<Container> ke
if (matched instanceof FieldContainer) {
final FieldContainer fieldContainer = (FieldContainer) matched;
if (dynamic) {
if (!itemMember.getPropertyName().isEmpty()) {
// consume segment
matchedBody.invokeVirtualMethod(NI_PREVIOUS, keyIter);
}
generateConsumeSegments(matchedBody, keyIter, itemMember.getPropertyName());
// we have to get or create all containing (and contained) groups of this member
matchedBody.invokeStaticMethod(generateGetEnclosing(fieldContainer, type), keyIter,
config);
Expand Down Expand Up @@ -1467,10 +1464,7 @@ private MethodDescriptor generateGetEnclosing(final FieldContainer matchNode, fi
// get the parent
final FieldContainer fieldContainer = (FieldContainer) parent;
final ClassDefinition.ClassMember classMember = fieldContainer.getClassMember();
if (!classMember.getPropertyName().isEmpty()) {
// consume segment
mc.invokeVirtualMethod(NI_PREVIOUS, keyIter);
}
int consumedSegmentsCount = generateConsumeSegments(mc, keyIter, classMember.getPropertyName());
final ResultHandle enclosing = mc.invokeStaticMethod(generateGetEnclosing(fieldContainer, type),
keyIter, config);

Expand Down Expand Up @@ -1518,10 +1512,7 @@ private MethodDescriptor generateGetEnclosing(final FieldContainer matchNode, fi
} else {
mc.assign(group, fieldVal);
}
if (!classMember.getPropertyName().isEmpty()) {
// restore
mc.invokeVirtualMethod(NI_NEXT, keyIter);
}
generateRestoreSegments(mc, keyIter, consumedSegmentsCount);
mc.returnValue(group);
} else {
assert parent instanceof MapContainer;
Expand Down Expand Up @@ -1576,16 +1567,11 @@ private MethodDescriptor generateGetEnclosing(final MapContainer matchNode, fina
if (parent instanceof FieldContainer) {
// get the parent
final FieldContainer fieldContainer = (FieldContainer) parent;
if (!fieldContainer.getClassMember().getPropertyName().isEmpty()) {
// consume segment
mc.invokeVirtualMethod(NI_PREVIOUS, keyIter);
}
int consumedSegmentsCount = generateConsumeSegments(mc, keyIter,
fieldContainer.getClassMember().getPropertyName());
final ResultHandle enclosing = mc.invokeStaticMethod(generateGetEnclosing(fieldContainer, type),
keyIter, config);
if (!fieldContainer.getClassMember().getPropertyName().isEmpty()) {
// restore
mc.invokeVirtualMethod(NI_NEXT, keyIter);
}
generateRestoreSegments(mc, keyIter, consumedSegmentsCount);

final ResultHandle result;
if (isFieldEligibleForDirectAccess(fieldContainer.getClassMember())) {
Expand Down Expand Up @@ -1619,6 +1605,29 @@ private MethodDescriptor generateGetEnclosing(final MapContainer matchNode, fina
return md;
}

private int generateConsumeSegments(BytecodeCreator bc, ResultHandle keyIter, String propertyName) {
if (propertyName.isEmpty()) {
return 0;
}
bc.invokeVirtualMethod(NI_PREVIOUS, keyIter);
int consumedSegmentsCount = 1;
// For properties whose name contains dots,
// we need to call previous() multiple times
int dotIndex = propertyName.indexOf('.');
while (dotIndex >= 0) {
bc.invokeVirtualMethod(NI_PREVIOUS, keyIter);
++consumedSegmentsCount;
dotIndex = propertyName.indexOf('.', dotIndex + 1);
}
return consumedSegmentsCount;
}

private void generateRestoreSegments(BytecodeCreator bc, ResultHandle keyIter, int consumedSegmentsCount) {
for (int i = 0; i < consumedSegmentsCount; i++) {
bc.invokeVirtualMethod(NI_NEXT, keyIter);
}
}

private FieldDescriptor getOrCreateConverterInstance(Field field) {
return getOrCreateConverterInstance(field, ConverterType.of(field));
}
Expand Down