Skip to content

Fix generating unnecessary import statements when adding connections, model-providers, function-calls with reference-typed parameters#269

Merged
nipunayf merged 14 commits intoballerina-platform:mainfrom
dulajdilshan:fix-unnecessary-import-stmt
Sep 2, 2025
Merged

Fix generating unnecessary import statements when adding connections, model-providers, function-calls with reference-typed parameters#269
nipunayf merged 14 commits intoballerina-platform:mainfrom
dulajdilshan:fix-unnecessary-import-stmt

Conversation

@dulajdilshan
Copy link
Contributor

@dulajdilshan dulajdilshan commented Sep 1, 2025

Purpose

Addresses the following:

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

@dulajdilshan dulajdilshan marked this pull request as draft September 1, 2025 05:34
@dulajdilshan dulajdilshan force-pushed the fix-unnecessary-import-stmt branch from c273565 to addb061 Compare September 1, 2025 16:00
@dulajdilshan dulajdilshan marked this pull request as ready for review September 1, 2025 16:20
@dulajdilshan dulajdilshan changed the title Fix unnecessary import statements when adding connections, model-providers, function-calls with reference-typed parameters Fix generating unnecessary import statements when adding connections, model-providers, function-calls with reference-typed parameters Sep 1, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issues with generating unnecessary import statements when adding connections, model-providers, function-calls with reference-typed parameters. The fix centralizes import statement generation logic to avoid redundant imports and correctly handles module references.

Key changes:

  • Modified FunctionDataBuilder.java to conditionally generate import statements based on function type
  • Added comprehensive test data updates to reflect the corrected import behavior
  • Enhanced import statement processing in SourceBuilder.java to handle module references properly

Reviewed Changes

Copilot reviewed 77 out of 77 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
model-generator-commons/src/main/java/io/ballerina/modelgenerator/commons/FunctionDataBuilder.java Core logic fix for conditional import statement generation based on function types
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/node/NewConnectionBuilder.java Simplified connection builder import handling
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/node/ModelProviderBuilder.java Added parameter property handling for model providers
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/SourceBuilder.java Enhanced import processing with better module reference handling
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/Property.java Property cleanup fix
Multiple test JSON files Updated test data to reflect corrected import statement behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dulajdilshan dulajdilshan force-pushed the fix-unnecessary-import-stmt branch from 6a531e3 to fc804a7 Compare September 1, 2025 17:30
}

if (moduleName.equals(importModule)) {
imports.remove(orgName + "/" + moduleName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Without modifying the iterating set, shall we modify a duplicated set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Will resolved this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 12811e6

@nipunayf nipunayf merged commit acca7d4 into ballerina-platform:main Sep 2, 2025
3 checks passed
@dulajdilshan dulajdilshan deleted the fix-unnecessary-import-stmt branch September 2, 2025 05:53
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.

4 participants