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 258702 - FindUsages and Rename miss method calls
Summary: FindUsages and Rename miss method calls
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.2
Hardware: All All
: P1 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-07 08:18 UTC by Vladimir Voskresensky
Modified: 2016-06-07 18:02 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
sample project (100.00 KB, application/x-tar)
2016-04-07 08:19 UTC, Vladimir Voskresensky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Voskresensky 2016-04-07 08:18:53 UTC
Usecase:
- I had Class with static method 
- static method is used in big project using static import
- Class was split into Base and Derived and static method was moved into base
-- all is compiled and works just fine

PROBLEM:
now static method can not be found by FindUsages and if try to Rename calls are not renamed

I will attach simplified test project
Comment 1 Vladimir Voskresensky 2016-04-07 08:19:44 UTC
Created attachment 159144 [details]
sample project

usage in callDerived is not visible by FindUsages and Refactoring
Comment 2 Ralph Ruijs 2016-05-05 10:13:10 UTC
Derived extends Base which contains { static void foo(){} }

import static Derived.*; and calling foo() is not indexed as Base.foo(), but as Derived.foo().



While debugging I got as far as Resolve.java:1896

for (Symbol currentSym : env.toplevel.starImportScope.getSymbolsByName(name)) {
            Symbol origin = env.toplevel.starImportScope.getOrigin(currentSym).owner;
            if (currentSym.kind == MTH) {
                if (currentSym.owner.type != origin.type)
                    currentSym = currentSym.clone(origin);


where the origin of the symbol gets changed from Base to Derived.


Reassigning to hopefully the right component and adding Jan Lahoda to CC as he changed the code as part of JDK-8031569.
Comment 3 Jan Lahoda 2016-05-05 10:53:02 UTC
(In reply to Ralph Ruijs from comment #2)
> Derived extends Base which contains { static void foo(){} }
> 
> import static Derived.*; and calling foo() is not indexed as Base.foo(), but
> as Derived.foo().
> 
> 
> 
> While debugging I got as far as Resolve.java:1896
> 
> for (Symbol currentSym :
> env.toplevel.starImportScope.getSymbolsByName(name)) {
>             Symbol origin =
> env.toplevel.starImportScope.getOrigin(currentSym).owner;
>             if (currentSym.kind == MTH) {
>                 if (currentSym.owner.type != origin.type)
>                     currentSym = currentSym.clone(origin);
> 
> 
> where the origin of the symbol gets changed from Base to Derived.

I believe it was always the case - this is needed as the classfile should refer to the method in terms of Derived, not Base. This usually does not propagate to the API, as TreeInfo.symbolFor (used by Trees.getElement) does:
    public static Symbol symbolFor(JCTree node) {
        Symbol sym = symbolForImpl(node);

        return sym != null ? sym.baseSymbol() : null;
    }

I see SourceAnalyzerFactory accesses JCIdent/JCFieldAcces/JCMemberReference.sym directly - I'd suggest to change that to use TreeInfo.symbolFor, which should produce a reasonable Symbol for the IDE's pruposes.
Comment 4 Ralph Ruijs 2016-05-05 11:11:17 UTC
Reassinging to java.source. Thanks Honza!
Comment 5 Tomas Zezula 2016-06-06 14:16:33 UTC
Fixed jet-main e1d3c69d5f09
Comment 6 Tomas Zezula 2016-06-06 14:43:19 UTC
Forgot to mention: You need to reindex the sources to make the fix work.
Comment 7 Vladimir Voskresensky 2016-06-07 18:02:55 UTC
Excellent! Verified! Thanks!