Skip to content

Commit 170da2e

Browse files
dmealingclaude
andcommitted
refactor(render,codegen-spring): FR-010 Plan 3 clarity cleanup (no behavior change)
- OutputFormatRenderer: extract resolveInstruction(field, overrides) helper to eliminate the two-line override-then-field-default pattern duplicated between inlineContent() and renderGuide(). - OutputFormatSpecEmitter: simplify resolvePromptStyleEnum by using OutputTemplate.getPromptStyle() (which already normalises the attr read + null-default) instead of double hasMetaAttr/getMetaAttr lookup + manual null check; adds OutputTemplate import. - Verify.checkOutputPrompt: move requiredFieldNames null-guard above haystack init so the early-return fires before the defensive string copy. render 211/211 · codegen-spring 71/71 — no assertions weakened. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 04f981e commit 170da2e

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/OutputFormatSpecEmitter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.metaobjects.field.StringField;
1111
import com.metaobjects.object.MetaObject;
1212
import com.metaobjects.template.MetaTemplate;
13+
import com.metaobjects.template.OutputTemplate;
1314
import com.metaobjects.template.TemplateConstants;
1415

1516
import java.util.ArrayList;
@@ -97,12 +98,8 @@ private static String resolveFormatEnum(MetaTemplate template) {
9798
* Default (absent or unrecognized) → {@code PromptStyle.GUIDE}.
9899
*/
99100
private static String resolvePromptStyleEnum(MetaTemplate template) {
100-
String raw = null;
101-
if (template.hasMetaAttr(TemplateConstants.ATTR_PROMPT_STYLE, false)) {
102-
raw = template.getMetaAttr(TemplateConstants.ATTR_PROMPT_STYLE, false).getValueAsString();
103-
}
104-
if (raw == null) return "PromptStyle.GUIDE";
105-
return switch (raw) {
101+
String raw = (template instanceof OutputTemplate ot) ? ot.getPromptStyle() : null;
102+
return switch (raw != null ? raw : TemplateConstants.PROMPT_STYLE_DEFAULT) {
106103
case TemplateConstants.PROMPT_STYLE_INLINE -> "PromptStyle.INLINE";
107104
case TemplateConstants.PROMPT_STYLE_EXAMPLE_ONLY -> "PromptStyle.EXAMPLE_ONLY";
108105
default -> "PromptStyle.GUIDE";

server/java/render/src/main/java/com/metaobjects/render/Verify.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ private Verify() {}
5555
*/
5656
public static List<VerifyError> checkOutputPrompt(String fragment, List<String> requiredFieldNames) {
5757
List<VerifyError> errors = new ArrayList<>();
58-
String haystack = fragment == null ? "" : fragment;
5958
if (requiredFieldNames == null) return errors;
59+
String haystack = fragment == null ? "" : fragment;
6060
for (String name : requiredFieldNames) {
6161
if (!haystack.contains(name)) {
6262
errors.add(new VerifyError(ERR_OUTPUT_PROMPT_FIELD_MISSING, name));

server/java/render/src/main/java/com/metaobjects/render/prompt/OutputFormatRenderer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,26 @@ private static String inlineContent(PromptField field, PromptOverrides overrides
7171
if (field.kind() == FieldKind.BOOLEAN) {
7272
return "true | false";
7373
}
74-
String instruction = overrides.instructions().get(field.name());
75-
if (instruction == null) instruction = field.instruction();
74+
String instruction = resolveInstruction(field, overrides);
7675
if (instruction != null) {
7776
return "{" + instruction + "}";
7877
}
7978
return "{" + field.name() + "}";
8079
}
8180

81+
/** Returns the effective instruction: override first, then field default, or {@code null}. */
82+
private static String resolveInstruction(PromptField field, PromptOverrides overrides) {
83+
String instruction = overrides.instructions().get(field.name());
84+
return instruction != null ? instruction : field.instruction();
85+
}
86+
8287
private static String renderGuide(OutputFormatSpec spec, PromptOverrides overrides) {
8388
StringBuilder sb = new StringBuilder();
8489
sb.append("Fill in each field as described below:\n");
8590
for (PromptField field : spec.fields()) {
8691
String req = field.required() ? "required" : "optional";
8792
sb.append("- ").append(field.name()).append(" (").append(req).append(")");
88-
String instruction = overrides.instructions().get(field.name());
89-
if (instruction == null) instruction = field.instruction();
93+
String instruction = resolveInstruction(field, overrides);
9094
if (instruction != null) {
9195
sb.append(": ").append(instruction);
9296
}

0 commit comments

Comments
 (0)