Skip to content

Comments

Fix source generation in type conversion of data mapper#721

Merged
KavinduZoysa merged 2 commits intoballerina-platform:mainfrom
KavinduZoysa:fix-issue-2517
Feb 20, 2026
Merged

Fix source generation in type conversion of data mapper#721
KavinduZoysa merged 2 commits intoballerina-platform:mainfrom
KavinduZoysa:fix-issue-2517

Conversation

@KavinduZoysa
Copy link
Contributor

@KavinduZoysa KavinduZoysa commented Feb 19, 2026

Purpose

Addresses wso2/product-ballerina-integrator#2517

Summary

This pull request fixes source generation in type conversion within the data mapper component.

Changes Made

  • Refined conversion expression handling to recognize json/xml conversion forms using the updated xmldata prefix and to unwrap let expressions when resolving converted variables.
  • Standardized let-binding resolution to use letExpr.letVarDeclarations(), improving consistency when locating bindings for mapping and conversion.
  • Adjusted convertType logic and text-edit range calculations so generated variable declarations are inserted at the correct positions and with correct punctuation/spacing.
  • Updated test configuration fixtures to reflect the corrected insertion ranges and formatting for generated variable declarations.

Outcome

These changes improve the accuracy and consistency of generated source for type conversions in the data mapper, ensuring converted variables are correctly identified and inserted in the generated code.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Refactors conversion-resolution in DataMapManager to use xmldata:toXml(...) (instead of xml:toXml) and to resolve LET bindings via letExpr.letVarDeclarations(), unwrapping LET_EXPRESSION inner expressions as needed. Test JSON fixtures updated to new insertion ranges and punctuation placement.

Changes

Cohort / File(s) Summary
Core conversion & binding changes
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/DataMapManager.java
Replaces xml:toXml(...) with xmldata:toXml(...) and aligns json conversions to jsondata:toJson(...); refactors findConvertedVariable, getMappingExpr, getTargetNode, and convertType to use letExpr.letVarDeclarations() for LET binding resolution, unwrap LET_EXPRESSION inner exprs, and adjust text-edit/range calculations.
Test fixtures — insertion range & punctuation
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_convert_type/config/variable3.json, .../variable5.json
Updated JSON patch ranges (start/end char positions changed from 56 to 7) and changed inserted newText from ", Student studentConverted = check student.ensureType()" to " Student studentConverted = check student.ensureType(),", moving punctuation/whitespace to match new insertion point.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through lets and conversion streams,

jsondata songs and xmldata dreams.
I nudged a comma, moved a space,
unwrapped an inner LET with grace.
Now mappings hum in tidy place.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only includes the Purpose section with a link to the issue; it is missing most required sections including Goals, Approach, User stories, Release note, Documentation, and others from the template. Complete the PR description by filling in all required sections from the template, especially Goals, Approach, and Documentation sections to provide comprehensive context for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing source generation in type conversion within the data mapper component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/DataMapManager.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/DataMapManager.java`:
- Around line 1728-1745: In DataMapManager, the XML conversion match string is
wrong: update the xmlConversion comparator in findConvertedVariable to use the
actual Ballerina function prefix "xmldata:toXml(" + varName + ")" instead of
"xml:toXml(...)" so XML-converted variables are detected and unwrapped; apply
the same correction to the other identical match sites (the other occurrences in
this class, e.g., the comparisons created by addTypeConversion and the duplicate
match near the end of the file) so all places compare against
"xmldata:toXml(...)" consistently.

@KavinduZoysa KavinduZoysa merged commit 18e1035 into ballerina-platform:main Feb 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants