This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 131944

Summary: Missing API query to search package references
Product: java Reporter: Jan Pokorsky <jpokorsky>
Component: SourceAssignee: Tomas Zezula <tzezula>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 203806    
Bug Blocks: 94325, 131846, 168923    
Attachments: ClassIndexTest added test

Description Jan Pokorsky 2008-04-03 14:57:53 UTC
I propose to add new method to ClassIndex that would return all resources referencing a queried package.

public Set<FileObject> getResources(ElementHandle<PackageElement> element,
                                    Set<ClassIndex.SearchKind> searchKind,
                                    Set<ClassIndex.SearchScope> scope)

With present queries I am not able to find package reference e.g. 'org.mypkg' used in following statement

  import org.mypkg.*;
Comment 1 Tomas Zezula 2009-12-15 01:51:04 UTC
It's not so easy to distinguish the package name from enclosing class name, may require change of index format.
Comment 2 Tomas Zezula 2011-10-20 14:04:15 UTC
Fixed jet-main 6e6ba0910998
Comment 3 Ralph Ruijs 2011-10-21 14:05:09 UTC
Created attachment 112309 [details]
ClassIndexTest added test

It looks like the newly added API does not fix this issue. I added a test case which seems to fail.
Comment 4 Tomas Zezula 2011-10-21 14:16:01 UTC
In fact import of package which has no type used is not used, see JLS.
Comment 5 Ralph Ruijs 2011-10-21 14:20:37 UTC
(In reply to comment #4)
> In fact import of package which has no type used is not used, see JLS.

true, but we still need to be able to find these statements. When the last class gets removed from a package, the package no longer exists and these statements become invalid.
Comment 6 Tomas Zezula 2011-10-21 18:25:11 UTC
I found a ugly workaround how to do it. It's so ugly that I will not describe it here ;-).
I will try it and let you know.
Comment 7 Quality Engineering 2011-10-24 14:12:32 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/6e6ba0910998
User: Tomas Zezula <tzezula@netbeans.org>
Log: #131944:Missing API query to search package references
Comment 8 Tomas Zezula 2011-10-24 17:54:49 UTC
The getResourcesForPkg ans getRefrencesForPkg is now able to find references for unused package import. jet-main 797bd4e21cff
Comment 9 Quality Engineering 2011-10-25 14:45:22 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/797bd4e21cff
User: Tomas Zezula <tzezula@netbeans.org>
Log: #131944: Missing API query to search package references