Skip to content

Conversation

@tangcent
Copy link
Owner

@tangcent tangcent commented Nov 4, 2025

PR Type

Bug fix, Enhancement


Description

  • Improve module finding logic by prioritizing subclass context for inherited API methods

  • Add new overload findModule(psiClass, psiMethod) to handle inherited methods correctly

  • Change PsiResource interface methods to return non-nullable types

  • Refactor DefaultModuleHelper to use named parameters and extract PsiResource handling

  • Expand test coverage with separate test methods for different parameter types


Diagram Walkthrough

flowchart LR
  A["PsiResource Interface"] -->|"Return non-nullable types"| B["Updated Contract"]
  C["DefaultModuleHelper"] -->|"Add overload method"| D["findModule with Class+Method"]
  D -->|"Prioritize subclass module"| E["Inherited Method Resolution"]
  C -->|"Refactor logic"| F["Named Parameters"]
  G["Test Coverage"] -->|"Expand test cases"| H["Separate Test Methods"]
Loading

File Walkthrough

Relevant files
Refactoring
DefaultFormatFolderHelper.kt
Simplify null-safe chaining logic                                               

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/DefaultFormatFolderHelper.kt

  • Simplify null-safe chaining logic by removing unnecessary intermediate
    let blocks
  • Flatten nested null checks for resource.resource() and
    resource.resourceClass() calls
  • Improve code readability by using direct method calls instead of
    chained optional handling
+2/-6     
Enhancement
PsiResource.kt
Make PsiResource methods return non-nullable types             

idea-plugin/src/main/kotlin/com/itangcent/idea/psi/PsiResource.kt

  • Change resourceClass() return type from nullable PsiClass? to
    non-nullable PsiClass
  • Change resource() return type from nullable PsiElement? to
    non-nullable PsiElement
  • Remove blank line between method declarations for consistency
+2/-3     
ModuleHelper.kt
Add class+method overload to ModuleHelper interface           

idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ModuleHelper.kt

  • Add new interface method findModule(psiClass: PsiClass, psiMethod:
    PsiMethod) for explicit class+method resolution
  • Rename parameter cls to psiClass in existing method signature for
    consistency
+3/-1     
Bug fix
DefaultModuleHelper.kt
Add subclass-aware module resolution for inherited methods

idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultModuleHelper.kt

  • Add new overloaded method findModule(psiClass, psiMethod) to handle
    inherited methods with subclass context prioritization
  • Extract PsiResource handling into separate private method
    findModule(psiResource) with special logic for PsiMethod resources
  • Refactor main findModule method to use named parameters for clarity
  • Rename parameter cls to psiClass for consistency across all overloads
  • Implement module resolution that prioritizes subclass module when
    dealing with inherited methods
+27/-12 
Tests
DefaultModuleHelperTest.kt
Expand tests with inherited method resolution coverage     

idea-plugin/src/test/kotlin/com/itangcent/idea/utils/DefaultModuleHelperTest.kt

  • Add baseControllerPsiClass field to support testing inherited method
    scenarios
  • Split single testFindModule() into four focused test methods:
    testFindModuleWithString, testFindModuleWithPsiFile,
    testFindModuleWithPsiClass, testFindModuleWithPsiMethod
  • Add new test method testFindModuleWithInheritedMethods() to verify
    subclass context prioritization for inherited methods (issue #1267)
  • Rename testFindModuleByPath() as separate test method for path-based
    module resolution
  • Load BaseController.java in setUp to provide inherited method test
    data
+39/-7   
ConstantModuleHelper.kt
Update mock helper for new interface method                           

idea-plugin/src/test/kotlin/com/itangcent/mock/ConstantModuleHelper.kt

  • Implement new interface method findModule(psiClass, psiMethod) in mock
    helper
  • Rename parameter cls to psiClass for consistency with interface
    changes
+8/-1     

@github-actions github-actions bot added the type: bug Something isn't working label Nov 4, 2025
@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No auditing: New logic for resolving modules and prioritizing subclass context performs critical
resolution decisions without any audit logging of inputs, decisions, or outcomes.

Referred Code
//region find module
override fun findModule(resource: Any): String? {
    return actionContext!!.callInReadUI {
        when (resource) {
            is PsiResource -> findModule(psiResource = resource)
            is PsiMethod -> findModule(psiMethod = resource)
            is PsiClass -> findModule(psiClass = resource)
            is PsiFile -> findModule(psiFile = resource)
            else -> null
        }
    }
}

private fun findModule(psiResource: PsiResource): String? {
    val resource = psiResource.resource()
    if (resource is PsiMethod) {
        return findModule(psiResource.resourceClass(), resource)
    }
    return findModule(resource = resource)
}



 ... (clipped 10 lines)
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Null-safety risk: The code assumes non-null actionContext and ruleComputer (!!) and non-null PsiResource
returns, lacking explicit handling or fallbacks if these are unavailable.

Referred Code
    return actionContext!!.callInReadUI {
        when (resource) {
            is PsiResource -> findModule(psiResource = resource)
            is PsiMethod -> findModule(psiMethod = resource)
            is PsiClass -> findModule(psiClass = resource)
            is PsiFile -> findModule(psiFile = resource)
            else -> null
        }
    }
}

private fun findModule(psiResource: PsiResource): String? {
    val resource = psiResource.resource()
    if (resource is PsiMethod) {
        return findModule(psiResource.resourceClass(), resource)
    }
    return findModule(resource = resource)
}

override fun findModule(psiClass: PsiClass, psiMethod: PsiMethod): String? {
    val moduleByRule = NonReentrant.call("findModule") {


 ... (clipped 7 lines)
Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Non-null contract: Changing PsiResource.resource() and resourceClass() to non-null increases trust in inputs
without visible validation, which may rely on external guarantees not shown in the diff.

Referred Code
fun resourceClass(): PsiClass

fun resource(): PsiElement
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Pass subclass as rule context

In findModule(psiClass, psiMethod), pass psiClass as the context to
ruleComputer.computer to ensure rules are evaluated correctly for inherited
methods.

idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultModuleHelper.kt [59-61]

 val moduleByRule = NonReentrant.call("findModule") {
-    ruleComputer!!.computer(ClassExportRuleKeys.MODULE, psiMethod)
+    ruleComputer!!.computer(ClassExportRuleKeys.MODULE, psiMethod, psiClass)
 }
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a logical flaw where the new findModule overload fails to pass the psiClass as context to the rule computer, undermining the feature's purpose of handling inherited methods.

Medium
  • More

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

📦 Plugin has been packaged for this PR. You can download easy-api-2.4.2.212.0.zip from the GitHub Actions workflow run by clicking on the "Artifacts" dropdown.

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the wontfix This will not be worked on label Nov 24, 2025
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.006%. Comparing base (adbc290) to head (c0b27ab).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...in/com/itangcent/idea/utils/DefaultModuleHelper.kt 93.750% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master      #615       +/-   ##
===============================================
+ Coverage     53.879%   54.006%   +0.127%     
+ Complexity      2366      2350       -16     
===============================================
  Files            259       259               
  Lines          14707     13541     -1166     
  Branches        3254      3252        -2     
===============================================
- Hits            7924      7313      -611     
+ Misses          5339      4787      -552     
+ Partials        1444      1441        -3     
Flag Coverage Δ
unittests 54.006% <94.444%> (+0.127%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...lugin/api/export/core/DefaultFormatFolderHelper.kt 77.049% <100.000%> (+2.049%) ⬆️
.../main/kotlin/com/itangcent/idea/psi/PsiResource.kt 85.714% <ø> (ø)
...in/com/itangcent/idea/utils/DefaultModuleHelper.kt 67.797% <93.750%> (+7.419%) ⬆️

... and 157 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update adbc290...c0b27ab. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot removed the wontfix This will not be worked on label Nov 25, 2025
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the wontfix This will not be worked on label Dec 15, 2025
@github-actions github-actions bot closed this Dec 21, 2025
@tangcent tangcent reopened this Jan 12, 2026
@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Possible NPEs: New module-resolution paths rely on non-null assertions (e.g.,
actionContext!!/ruleComputer!!) without visible guarding, which could crash instead of
degrading gracefully if DI is not initialized.

Referred Code
    return actionContext!!.callInReadUI {
        when (resource) {
            is PsiResource -> findModule(psiResource = resource)
            is PsiMethod -> findModule(psiMethod = resource)
            is PsiClass -> findModule(psiClass = resource)
            is PsiFile -> findModule(psiFile = resource)
            else -> null
        }
    }
}

private fun findModule(psiResource: PsiResource): String? {
    val resource = psiResource.resource()
    if (resource is PsiMethod) {
        return findModule(psiResource.resourceClass(), resource)
    }
    return findModule(resource = resource)
}

override fun findModule(psiClass: PsiClass, psiMethod: PsiMethod): String? {
    val moduleByRule = NonReentrant.call("findModule") {


 ... (clipped 7 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Pass subclass as context for rules

In the findModule(psiClass, psiMethod) method, pass psiClass as the context to
the ruleComputer.computer call. This ensures rules are evaluated with the
subclass context for inherited methods.

idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultModuleHelper.kt [58-67]

 override fun findModule(psiClass: PsiClass, psiMethod: PsiMethod): String? {
     val moduleByRule = NonReentrant.call("findModule") {
-        ruleComputer!!.computer(ClassExportRuleKeys.MODULE, psiMethod)
+        ruleComputer!!.computer(ClassExportRuleKeys.MODULE, psiMethod, psiClass)
     }
     if (moduleByRule.notNullOrBlank()) {
         return moduleByRule
     }
 
     return findModule(psiClass)
 }
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies a logical flaw in the new findModule method. By not passing psiClass as context to ruleComputer, the implementation fails to achieve its primary goal of handling inherited methods with subclass context, which is a significant bug in the new functionality.

High
General
Avoid recursion by calling specific methods

In findModule(psiResource), replace the recursive call findModule(resource =
resource) with a when block to directly invoke the appropriate findModule
overload based on the resource's type.

idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultModuleHelper.kt [50-56]

 private fun findModule(psiResource: PsiResource): String? {
     val resource = psiResource.resource()
     if (resource is PsiMethod) {
         return findModule(psiResource.resourceClass(), resource)
     }
-    return findModule(resource = resource)
+    return when (resource) {
+        is PsiMethod -> findModule(psiMethod = resource)
+        is PsiClass -> findModule(psiClass = resource)
+        is PsiFile -> findModule(psiFile = resource)
+        else -> null
+    }
 }
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly points out an unnecessary recursive call and proposes a more direct and efficient implementation. While the current code is functionally correct, this change improves code clarity and performance by removing a redundant delegation layer.

Low
  • More

@tangcent tangcent removed the wontfix This will not be worked on label Jan 12, 2026
@github-actions
Copy link
Contributor

📦 Plugin has been packaged for this PR. You can download easy-api-2.4.2.212.0.zip from the GitHub Actions workflow run by clicking on the "Artifacts" dropdown.

@tangcent tangcent merged commit 2ad327c into master Jan 13, 2026
38 of 42 checks passed
@tangcent tangcent deleted the chore/merge_easy-yapi branch January 13, 2026 01:14
@tangcent tangcent mentioned this pull request Jan 14, 2026
@github-actions
Copy link
Contributor

A PR (#616) has been opened to fix this issue. You can download the packaged plugin easy-api-2.4.3.212.0.zip from the GitHub Actions workflow run by clicking on the "Artifacts" dropdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants