Skip to content

Conversation

@jmle
Copy link
Collaborator

@jmle jmle commented Sep 12, 2025

Related to https://issues.redhat.com/browse/MTA-5763

Summary by CodeRabbit

  • New Features
    • Search results now include system libraries by default (outside source-only mode), expanding coverage of symbols.
  • Bug Fixes
    • Improved reliability of symbol detection and navigation for method calls, including cases originating from fields or compiled binaries.
  • Style
    • Minor whitespace cleanup (no functional impact).

@coderabbitai
Copy link

coderabbitai bot commented Sep 12, 2025

Walkthrough

Expands search scope to include system libraries when not in source-only mode and generalizes symbol resolution to handle both methods and fields when determining the compilation unit for AST analysis.

Changes

Cohort / File(s) Summary
Search scope update
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java
Adds SYSTEM_LIBRARIES to non-source-only search scope by OR-ing IJavaSearchScope.SYSTEM_LIBRARIES with existing flags; whitespace tweak.
Symbol provider element handling
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java
Treats match as IJavaElement; supports IMethod and IField for compilation unit retrieval; imports adjusted; falls back to class file working copy when needed; rest of AST processing unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant CommandHandler as SampleDelegateCommandHandler
  participant JDT as JDT Search

  rect rgb(240,248,255)
    note over CommandHandler: Build search scope
    Client->>CommandHandler: search(query, sourceOnly=false)
    alt sourceOnly
      CommandHandler->>JDT: Scope = SOURCES
    else not sourceOnly
      CommandHandler->>JDT: Scope = SOURCES | REFERENCED_PROJECTS | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES
      note right of CommandHandler: SYSTEM_LIBRARIES newly included
    end
    JDT-->>CommandHandler: Search results
    CommandHandler-->>Client: Results
  end
Loading
sequenceDiagram
  autonumber
  participant Client
  participant Provider as MethodCallSymbolProvider
  participant JDT as JDT Model
  participant AST as AST Parser

  Client->>Provider: provideSymbols(query)
  Provider->>JDT: resolve element for query
  JDT-->>Provider: IJavaElement (IMethod or IField or ClassFile)
  alt element is IMethod
    Provider->>Provider: cu = method.getCompilationUnit()
  else element is IField
    Provider->>Provider: cu = field.getCompilationUnit()
  else no CU
    Provider->>JDT: classFile = element.getAncestor(ClassFile)
    Provider->>JDT: cu = classFile.getWorkingCopy()
  end
  Provider->>AST: parse(cu)
  AST-->>Provider: AST root
  Provider-->>Client: filtered symbols
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately reflects the primary change: improving method matching to catch static methods declared on class fields. This aligns with MethodCallSymbolProvider updates that generalize the matched element to IJavaElement and add IField handling for compilation-unit resolution. The title is concise and specific, though it contains an emoji that is stylistic noise.

Poem

A whisker twitch, a library found,
I hop through jars with gentle bound.
Methods? Fields? I nose them out—
Find the CU, no room for doubt.
With ears up high, I scan the streams—
More symbols now to fill my dreams. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
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

🧹 Nitpick comments (1)
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java (1)

206-214: Scope now includes SYSTEM_LIBRARIES — verify perf/recall trade-offs and guard NPE on analysisMode.

Including system libraries can drastically increase search time and noise. Gate it explicitly and make the equals check NPE-safe.

-        //  For Partial results, we are going to filter out based on a list in the engine
-        int s = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
-        if (analysisMode.equals(sourceOnlyAnalysisMode)) {
+        // For partial results, filter based on a list in the engine
+        int s = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES;
+        if (sourceOnlyAnalysisMode.equals(analysisMode)) {
             logInfo("KONVEYOR_LOG: source-only analysis mode only scoping to Sources");
             s = IJavaSearchScope.SOURCES;
         } else {
             logInfo("KONVEYOR_LOG: waiting for source downloads");
             waitForJavaSourceDownloads();
             logInfo("KONVEYOR_LOG: waited for source downloads");
+            // Only include system libraries when not in source-only mode
+            s |= IJavaSearchScope.SYSTEM_LIBRARIES;
         }

Action items:

  • Benchmark large workspaces (cold vs warm) to ensure acceptable latency when SYSTEM_LIBRARIES is included.
  • If needed, expose a toggle for system libraries or scope-inclusion per location (e.g., method_call only).
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69eff90 and 2a79d30.

📒 Files selected for processing (2)
  • java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java (2 hunks)
  • java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build tackle2-addon-analyzer
🔇 Additional comments (2)
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java (1)

230-230: Whitespace-only change.

No functional impact.

java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java (1)

43-48: Good generalization to handle matches originating from fields.

Allowing IField-backed elements helps catch method references that surface via field initializers or class fields.

Comment on lines +43 to +49
ICompilationUnit unit = null;
if (m.getElement() instanceof IMethod) {
unit = ((IMethod) m.getElement()).getCompilationUnit();
} else if (m.getElement() instanceof IField) {
unit = ((IField) m.getElement()).getCompilationUnit();
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid NPEs and only dispose working copies you created; wrap in try/finally.

unit can be null; queryQualificationMatches, setSource, discardWorkingCopy, and close can throw. Also don’t close primary compilation units you didn’t open.

-                ICompilationUnit unit = null;
+                ICompilationUnit unit = null;
+                boolean createdWorkingCopy = false;
                 if (m.getElement() instanceof IMethod) {
                     unit = ((IMethod) m.getElement()).getCompilationUnit();
                 } else if (m.getElement() instanceof IField) {
                     unit = ((IField) m.getElement()).getCompilationUnit();
                 }
 
                 if (unit == null) {
-                    IClassFile cls = (IClassFile) ((IJavaElement) e).getAncestor(IJavaElement.CLASS_FILE);
+                    IClassFile cls = (IClassFile) e.getAncestor(IJavaElement.CLASS_FILE);
                     if (cls != null) {
-                        unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null);
+                        unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null);
+                        createdWorkingCopy = unit != null && unit.isWorkingCopy();
                     }
                 }
-                if (this.queryQualificationMatches(this.query, unit, location)) {
-                    ASTParser astParser = ASTParser.newParser(AST.getJLSLatest());
-                    astParser.setSource(unit);
-                    astParser.setResolveBindings(true);
-                    CompilationUnit cu = (CompilationUnit) astParser.createAST(null);
-                    CustomASTVisitor visitor = new CustomASTVisitor(query, match, QueryLocation.METHOD_CALL);
-                    // Under tests, resolveConstructorBinding will return null if there are problems
-                    IProblem[] problems = cu.getProblems();
-                    if (problems != null && problems.length > 0) {
-                        logInfo("KONVEYOR_LOG: " + "Found " + problems.length + " problems while compiling");
-                        int count = 0;
-                        for (IProblem problem : problems) {
-                            logInfo("KONVEYOR_LOG: Problem - ID: " + problem.getID() + " Message: " + problem.getMessage());
-                            count++;
-                            if (count >= SymbolProvider.MAX_PROBLEMS_TO_LOG) {
-                                logInfo("KONVEYOR_LOG: Only showing first " + SymbolProvider.MAX_PROBLEMS_TO_LOG + " problems, " +
-                                       (problems.length - SymbolProvider.MAX_PROBLEMS_TO_LOG) + " more not displayed");
-                                break;
-                            }
-                        }
-                    }
-                    cu.accept(visitor);
-                    if (visitor.symbolMatches()) {
-                        symbols.add(symbol);
-                    }
-                }
-                unit.discardWorkingCopy();
-                unit.close();
+                if (unit == null) {
+                    // No source/working copy available to qualify; skip deep check.
+                } else {
+                    try {
+                        if (this.queryQualificationMatches(this.query, unit, location)) {
+                            ASTParser astParser = ASTParser.newParser(AST.getJLSLatest());
+                            astParser.setSource(unit);
+                            astParser.setResolveBindings(true);
+                            CompilationUnit cu = (CompilationUnit) astParser.createAST(null);
+                            CustomASTVisitor visitor = new CustomASTVisitor(query, match, QueryLocation.METHOD_CALL);
+                            IProblem[] problems = cu.getProblems();
+                            if (problems != null && problems.length > 0) {
+                                logInfo("KONVEYOR_LOG: " + "Found " + problems.length + " problems while compiling");
+                                int count = 0;
+                                for (IProblem problem : problems) {
+                                    logInfo("KONVEYOR_LOG: Problem - ID: " + problem.getID() + " Message: " + problem.getMessage());
+                                    count++;
+                                    if (count >= SymbolProvider.MAX_PROBLEMS_TO_LOG) {
+                                        logInfo("KONVEYOR_LOG: Only showing first " + SymbolProvider.MAX_PROBLEMS_TO_LOG + " problems, " +
+                                               (problems.length - SymbolProvider.MAX_PROBLEMS_TO_LOG) + " more not displayed");
+                                        break;
+                                    }
+                                }
+                            }
+                            cu.accept(visitor);
+                            if (visitor.symbolMatches()) {
+                                symbols.add(symbol);
+                            }
+                        }
+                    } finally {
+                        if (createdWorkingCopy && unit.isWorkingCopy()) {
+                            unit.discardWorkingCopy();
+                        }
+                    }
+                }

Notes:

  • Removing unit.close() avoids closing shared primary CUs the search engine or other code may rely on.
  • createdWorkingCopy ensures we only dispose of what we created.

Also applies to: 50-56, 56-61, 82-84

🤖 Prompt for AI Agents
In
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java
around lines 43-49 (and similarly for the other ranges noted: 50-56, 56-61,
82-84), the current code can NPE when unit is null and may improperly close or
discard compilation units it didn't create; wrap the working-copy logic in a
try/finally, null-check unit before using it, call createdWorkingCopy to record
whether you created the working copy and only call discardWorkingCopy/close when
you actually created it, and catch or let checked exceptions propagate as
appropriate so setSource/queryQualificationMatches/discardWorkingCopy/close are
executed safely in finally without closing primary CUs you didn't open.

Copy link
Member

@aufi aufi left a comment

Choose a reason for hiding this comment

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

I don't have all background on java, but overall looks good.

@jmle jmle merged commit 8f942d2 into konveyor:main Sep 12, 2025
8 checks passed
@jmle
Copy link
Collaborator Author

jmle commented Sep 17, 2025

Fixes konveyor/analyzer-lsp#769

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