|
35 | 35 | import org.eclipse.core.runtime.IPath; |
36 | 36 | import org.eclipse.jdt.core.IJavaProject; |
37 | 37 | import org.eclipse.jdt.core.IMethod; |
| 38 | +import org.eclipse.jdt.core.JavaCore; |
38 | 39 | import org.eclipse.jdt.core.JavaModelException; |
39 | 40 | import org.eclipse.jdt.core.search.IJavaSearchConstants; |
40 | 41 | import org.eclipse.jdt.core.search.IJavaSearchScope; |
@@ -100,8 +101,18 @@ private List<ResolutionItem> resolveMainClassCore(List<Object> arguments) { |
100 | 101 |
|
101 | 102 | private List<ResolutionItem> resolveMainClassUnderPaths(List<IPath> parentPaths) { |
102 | 103 | // Limit to search main method from source code only. |
103 | | - IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(ProjectUtils.getJavaProjects(), |
104 | | - IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.SOURCES); |
| 104 | + IJavaProject[] projects; |
| 105 | + if (parentPaths == null || parentPaths.isEmpty()) { |
| 106 | + projects = ProjectUtils.getJavaProjects(); |
| 107 | + } else { |
| 108 | + projects = Stream.of(ProjectUtils.getAllProjects()) |
| 109 | + .filter(p -> ProjectUtils.isJavaProject(p) && p.getLocation() != null && ResourceUtils.isContainedIn(p.getLocation(), parentPaths)) |
| 110 | + .map(p -> JavaCore.create(p)) |
| 111 | + .filter(p -> p.exists()) |
| 112 | + .toArray(IJavaProject[]::new); |
| 113 | + } |
| 114 | + IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(projects, |
| 115 | + IJavaSearchScope.SOURCES); |
105 | 116 | SearchPattern pattern = createMainMethodSearchPattern(); |
106 | 117 | final List<ResolutionItem> res = new ArrayList<>(); |
107 | 118 | SearchRequestor requestor = new SearchRequestor() { |
|
0 commit comments