Bug 519151 - [9][search] Need a way to use modules as a search scope
Summary: [9][search] Need a way to use modules as a search scope
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-04 06:49 EDT by Stephan Herrmann CLA
Modified: 2023-11-06 02:39 EST (History)
3 users (show)

See Also:


Attachments
minimal workspace to reproduce the issue in prev comment (7.86 KB, application/octet-stream)
2018-01-10 01:18 EST, Manoj N Palat CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2017-07-04 06:49:20 EDT
FUP from bug 518829:

In the modular world, searching for a type by its qualified name no longer yields unique results. If a sought module is known, search should be able to consider only that module (or a set of modules - a module graph(?) for that matter).
Comment 1 Manoj N Palat CLA 2017-11-27 12:23:14 EST
An initial WIP gerrit  at https://git.eclipse.org/r/112348

supports two kinds of module list

a) <List of comma separated modules> : pack.X
or
b) Regex based list of modules (experimental) - the module name should start with 0

Examples available in JavSB9Tests. The mix of the above not supported - an alternate option is to give the choice of each element of the list to be a normal string or a pattern - should not end up in an overkill though.

Module Graph input needs to be looked into to figure out how to support - mostly this would require a pre-proc stage since the input does not contain the closure info.

The above gerrit is for TypeDeclarationPattern only but is a working version.
@Stephan : Inputs welcome
Comment 2 Eclipse Genie CLA 2017-11-27 14:05:00 EST
New Gerrit change created: https://git.eclipse.org/r/112348
Comment 3 Eclipse Genie CLA 2017-11-27 14:05:05 EST
New Gerrit change created: https://git.eclipse.org/r/112346
Comment 4 Eclipse Genie CLA 2017-11-28 00:05:42 EST
New Gerrit change created: https://git.eclipse.org/r/112405
Comment 5 Manoj N Palat CLA 2017-11-28 00:10:15 EST
(In reply to Eclipse Genie from comment #4)
> New Gerrit change created: https://git.eclipse.org/r/112405

(In reply to Eclipse Genie from comment #3)
> New Gerrit change created: https://git.eclipse.org/r/112346

These are abandoned in favor of gerrit in comment 2, ie
https://git.eclipse.org/r/#/c/112348/
Comment 6 Manoj N Palat CLA 2017-11-28 03:43:01 EST
(In reply to Manoj Palat from comment #5)
> https://git.eclipse.org/r/#/c/112348/

The gerrit above enables a module name/a list of module names in a TypeDeclaration pattern

Starting with the Javadoc changes of SearchPattern.createPattern():

Since 3.14 for Java 9, Type Declaration Patterns can have module names also embedded with the following syntax 
[moduleName1[,moduleName2,..]]:[qualification '.']typeName ['<' typeArguments '>']

Examples:
◦java.base:java.lang.Object
◦mod.one, mod.two:pack.X find declaration in the list of given modules.
◦:pack.X find in the unnamed module.

To note that module name(s) and the type declaration pattern separated by a ':' character
Comment 8 Jay Arthanareeswaran CLA 2017-11-28 10:20:02 EST
(In reply to Eclipse Genie from comment #7)
> Gerrit change https://git.eclipse.org/r/112348 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=7b578e6c554f0780808d7dc0a5748e53798be2a7
> 

This commit left a new warning in the workspace.
Manoj, can you please fix this?
Comment 9 Manoj N Palat CLA 2017-11-28 21:18:59 EST
(In reply to Jay Arthanareeswaran from comment #8)
> (In reply to Eclipse Genie from comment #7)
> > Gerrit change https://git.eclipse.org/r/112348 was merged to [master].
> > Commit:
> > http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=7b578e6c554f0780808d7dc0a5748e53798be2a7
> > 
> 
> This commit left a new warning in the workspace.
> Manoj, can you please fix this?

yep- aware of that - unused variable - will be pushing another commit soon.
Comment 10 Eclipse Genie CLA 2017-11-30 07:34:51 EST
New Gerrit change created: https://git.eclipse.org/r/112628
Comment 11 Stephan Herrmann CLA 2017-11-30 08:06:13 EST
(In reply to Manoj Palat from comment #6)
> Since 3.14 for Java 9, Type Declaration Patterns can have module names also
> embedded with the following syntax 
> [moduleName1[,moduleName2,..]]:[qualification '.']typeName ['<'
> typeArguments '>']
> 
> Examples:
> ◦java.base:java.lang.Object
> ◦mod.one, mod.two:pack.X find declaration in the list of given modules.
> ◦:pack.X find in the unnamed module.
> 
> To note that module name(s) and the type declaration pattern separated by a
> ':' character

Why did you choose ':'? AFAICS most (all?) other situations use '/', e.g., in stack traces or JEP 261 options. Do type patterns accept binary syntax "java/lang/Object" (which would obviously a conflict)?

Also, if ":pack.X" is too implicit for denoting unnamed module, you may consider using "ALL-UNNAMED/org.foo.Bar".
Comment 12 Manoj N Palat CLA 2017-11-30 10:55:11 EST
(In reply to Eclipse Genie from comment #10)
> New Gerrit change created: https://git.eclipse.org/r/112628

(In reply to Stephan Herrmann from comment #11)
> Why did you choose ':'? AFAICS most (all?) other situations use '/', e.g.,
> in stack traces or JEP 261 options. Do type patterns accept binary syntax
> "java/lang/Object" (which would obviously a conflict)?
> 
> Also, if ":pack.X" is too implicit for denoting unnamed module, you may
> consider using "ALL-UNNAMED/org.foo.Bar".

Thanks Stephan for the comments - Have incorporated both suggestions, added a few more test cases and the module graph based additions (list of module graphs actually) along with the above gerrit. Please note that now the Unnamed can be given implicitly as well with the explicit option as suggested.

Now the relevant JavaDoc is modified as shown below - please let know if there are further comments. tia

-----------snip-------------

Since 3.14 for Java 9, Type Declaration Patterns can have module names also embedded with the following syntax 
[moduleName1[,moduleName2,..]]/[qualification '.']typeName ['<' typeArguments '>'] 

Unnamed modules can also be included and are represented either by an absence of module name implicitly or explicitly by specifying ALL-UNNAMED for module name. Module graph search is also supported with the limitTo option set to IJavaSearchConstants.MODULE_GRAPH. In the module graph case, the given type is searched in all the modules required directly as well as indirectly by the given module(s). 

Note that whitespaces are ignored in between module names. It is an error to give multiple module separators - in such cases a null pattern will be returned. 

Examples:
?java.base/java.lang.Object
?mod.one, mod.two/pack.X find declaration in the list of given modules.
?/pack.X find in the unnamed module.
?ALL-UNNAMED/pack.X find in the unnamed module.
-----------snip-------------

Under limitTo:
-----------snip-------------
MODULE_GRAPH: for types with a module prefix, will find all types present in required modules (directly or indirectly required) ie in any module present in the module graph of the given module. 
-----------snip-------------
Comment 13 Manoj N Palat CLA 2017-11-30 10:58:51 EST
(In reply to Manoj Palat from comment #12)

> Examples:
> ?java.base/java.lang.Object
> ?mod.one, mod.two/pack.X find declaration in the list of given modules.
> ?/pack.X find in the unnamed module.
> ?ALL-UNNAMED/pack.X find in the unnamed module.
> -----------snip-------------
> 
To be read as the following:
Examples:
java.base/java.lang.Object
mod.one, mod.two/pack.X find declaration in the list of given modules.
/pack.X find in the unnamed module.
ALL-UNNAMED/pack.X find in the unnamed module.

The extra ? at the start was a contribution of editor (representing the item char)
Comment 15 Eclipse Genie CLA 2017-12-06 03:03:57 EST
New Gerrit change created: https://git.eclipse.org/r/112929
Comment 16 Manoj N Palat CLA 2017-12-06 03:05:17 EST
(In reply to Eclipse Genie from comment #15)
> New Gerrit change created: https://git.eclipse.org/r/112929

A missed out case of simple types with modules - thanks Sasi for catching this - re-opening to address this with the above gerrit patch.
Comment 18 Manoj N Palat CLA 2017-12-06 05:14:15 EST
search failing in one of the workspaces -needs further investigation -moving to M5
Comment 19 Manoj N Palat CLA 2017-12-06 22:23:55 EST
(In reply to Manoj Palat from comment #18)
> search failing in one of the workspaces -needs further investigation -moving
> to M5

getting a null binding for modules for the types in the failing workspace - under investigation
Comment 20 Manoj N Palat CLA 2018-01-10 01:18:43 EST
Created attachment 272206 [details]
minimal workspace to reproduce the issue in prev comment

Search for java.sql/java.sql.Driver in Type + Declaration with JRE search selected.
The search will not return Driver declaration.
Issue:
Here the first project has compliance 1.8 though using the identical JRE 9 as of project second.  When an openable is received at: 
JavaWorkspaceScope.packageFragmentRoot(String, int, String) line: 149	
HandleFactory.getJarPkgFragmentRoot(String, int, String, IJavaSearchScope) line: 317	
HandleFactory.createOpenable(String, IJavaSearchScope) line: 92	
MatchLocator.locateMatches(SearchDocument[]) line: 1466	
JavaSearchParticipant.locateMatches(SearchDocument[], SearchPattern, IJavaSearchScope, SearchRequestor, IProgressMonitor) line: 105	
BasicSearchEngine.findMatches(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) line: 237	
BasicSearchEngine.search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) line: 582	
SearchEngine.search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) line: 604	
that of first comes up which a non-module-aware project .
Consequently the ModuleBinding of the concerned type will not have the module name.
and hence zero results.
One option is to have multiple openables ?? in the works..
Comment 21 Eclipse Genie CLA 2018-01-12 06:16:56 EST
New Gerrit change created: https://git.eclipse.org/r/115292
Comment 23 Sasikanth Bharadwaj CLA 2018-01-18 04:09:50 EST
Quick tests revealed the following issues

I see a CCE when searching for module declarations named java.*. Another issue is that searching for type prefixed by module name returns types from non-modular JREs as well. For example, searching for java.base/Driver results in two matches, one from rt.jar and one from java.base module. I guess only one should show up.

Will continue a little while longer and update if I see any others
Comment 24 Sasikanth Bharadwaj CLA 2018-01-18 04:10:36 EST
Here's the stack trace of the CCE
java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.classfmt.ModuleInfo cannot be cast to org.eclipse.jdt.internal.core.MemberElementInfo
	at org.eclipse.jdt.internal.core.Member.getNameRange(Member.java:351)
	at org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction.getMember(FindOccurrencesInFileAction.java:140)
	at org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction.selectionChanged(FindOccurrencesInFileAction.java:130)
Comment 25 Sasikanth Bharadwaj CLA 2018-01-18 04:29:43 EST
Another thing that needs clarification is whether searching for a type declaration using the prefixed by module name pattern returns just types declared in that module or types visible in the context of that module. 
For example, if a project defining module mod.one has a jar on its build path (which is not a module) and if both declare a class named Driver (in different packages), if we search for mod.one/Driver, currently I see two results, one from the project and one from the jar, which is wrong
Comment 26 Manoj N Palat CLA 2018-01-19 04:16:22 EST
(In reply to Sasikanth Bharadwaj from comment #23)
Thanks Sasi for testing out - my first response below
> Quick tests revealed the following issues
> 
> I see a CCE when searching for module declarations named java.*.

This issue is due to a bug in the model tracked via bug 530024.

> Another
> issue is that searching for type prefixed by module name returns types from
> non-modular JREs as well. For example, searching for java.base/Driver
> results in two matches, one from rt.jar and one from java.base module. I
> guess only one should show up.

I get to see only one. need to investigate further/reproducible workspace for this

> Will continue a little while longer and update if I see any others
Comment 27 Manoj N Palat CLA 2018-08-16 00:30:11 EDT
Bulk move out of 4.9
Comment 28 Eclipse Genie CLA 2020-10-02 09:26:28 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 29 Eclipse Genie CLA 2022-12-16 15:31:41 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 30 Jay Arthanareeswaran CLA 2023-11-06 02:39:20 EST
I am sure this is still relevant. Also see this PR that shows that some of the code introduced by this are unused.

https://github.com/eclipse-jdt/eclipse.jdt.core/pull/1544