Skip to content

Improve ResolveMainClassHandler.resolveMainClassUnderPaths #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Jul 20, 2025

Fixes #595

@wenytang-ms wenytang-ms requested a review from Copilot August 6, 2025 06:51
Copy link

@Copilot 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 improves the ResolveMainClassHandler.resolveMainClassUnderPaths method to provide more targeted main class resolution by filtering projects based on provided paths instead of searching all Java projects.

  • Adds conditional logic to filter Java projects when specific paths are provided
  • Removes REFERENCED_PROJECTS flag from search scope to focus only on source files
  • Imports JavaCore utility for creating IJavaProject instances

projects = ProjectUtils.getJavaProjects();
} else {
projects = Stream.of(ProjectUtils.getAllProjects())
.filter(p -> ProjectUtils.isJavaProject(p) && ResourceUtils.isContainedIn(p.getLocation(), parentPaths))
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The condition ResourceUtils.isContainedIn(p.getLocation(), parentPaths) may cause issues if p.getLocation() returns null. Project locations can be null for certain project types or when projects are not properly initialized.

Suggested change
.filter(p -> ProjectUtils.isJavaProject(p) && ResourceUtils.isContainedIn(p.getLocation(), parentPaths))
.filter(p -> ProjectUtils.isJavaProject(p) && p.getLocation() != null && ResourceUtils.isContainedIn(p.getLocation(), parentPaths))

Copilot uses AI. Check for mistakes.

projects = Stream.of(ProjectUtils.getAllProjects())
.filter(p -> ProjectUtils.isJavaProject(p) && ResourceUtils.isContainedIn(p.getLocation(), parentPaths))
.map(p -> JavaCore.create(p))
.filter(p -> p != null && p.exists())
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The null check for p is redundant since JavaCore.create() never returns null - it returns a handle that may or may not exist. Consider removing the null check and only keeping the exists() check.

Suggested change
.filter(p -> p != null && p.exists())
.filter(p -> p.exists())

Copilot uses AI. Check for mistakes.

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.

Improve ResolveMainClassHandler.resolveMainClassUnderPaths
1 participant