Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 140653 - Java hint does not run for some classes e.g. generated JPanel
Java hint does not run for some classes e.g. generated JPanel
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Hints
6.x
All All
: P3 (vote)
: 6.x
Assigned To: Max Sauer
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-07-17 23:52 UTC by hlavki
Modified: 2008-08-30 05:31 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
hint example app (6.80 KB, application/x-compressed)
2008-07-31 12:22 UTC, hlavki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hlavki 2008-07-17 23:52:53 UTC
I have java hint implementation for Kind.Class:
    private static final Set<Tree.Kind> TREE_KINDS = EnumSet.<Tree.Kind>of(Tree.Kind.CLASS);

But method run in hint is not running when I change source in JPanel class that is generated through File -> New 
File... -> Swing GUI Forms
Comment 1 hlavki 2008-07-18 08:31:17 UTC
it doesn't work correctly for generated JFrame with matisse designer. Hint method "run" works but,

treePath = Utilities.getPathElementOfKind(Tree.Kind.CLASS, treePath);
TypeElement typeElement = (TypeElement) info.getTrees().getElement(treePath);

then when I write typeElement.asType().toString() result is:

<anonymous java.lang.Runnable>
Comment 2 hlavki 2008-07-18 08:33:59 UTC
solution for JFrame is:

treePath = Utilities.getPathElementOfKind(Tree.Kind.CLASS, treePath);
TypeElement typeElement = (TypeElement) info.getTrees().getElement(treePath);
if (typeElement.getNestingKind().equals(NestingKind.ANONYMOUS)) {
    treePath = Utilities.getPathElementOfKind(Tree.Kind.CLASS, treePath.getParentPath());
    typeElement = (TypeElement) info.getTrees().getElement(treePath);
}
Comment 3 Jan Becicka 2008-07-25 14:22:28 UTC
I don't understand what are we required to fix...
Comment 4 hlavki 2008-07-25 15:19:39 UTC
Basically hint doesn't work for JPanel and JFrame created by wizard with matisse form.

Method run() in my hint class (extends AbstractHint) doesn't run for JPanel with 

    public Set<Kind> getTreeKinds() {
        return EnumSet.<Tree.Kind>of(Tree.Kind.CLASS);
    }


For JFrame class it runs but:
TypeElement typeElement = (TypeElement) info.getTrees().getElement(treePath);

typeElement is not my JFrame class but <anonymous java.lang.Runnable>
Comment 5 Jan Becicka 2008-07-31 10:45:25 UTC
Maxi do you understand?

If it is bug in IDE, please write steps to reproduce.
If it is API bug, please write test.

Comment 6 Max Sauer 2008-07-31 11:33:13 UTC
Sorry, but I don't get this at all. Seems to me that you are implementing your own hint, which extends AbstractHint. So far so good. I've tried

        treePath = Utilities.getPathElementOfKind(Tree.Kind.CLASS, treePath);
        TypeElement typeElement = (TypeElement) compilationInfo.getTrees().getElement(treePath);
        System.out.println("### " + typeElement.asType().toString());

for one of my own hints, and correct class name has been printed. The above code uses classes from javac. What type is printed out depends on treePath 
passes as run()'s parameter, which depends on context, in case there is an anonymous class (and there is, in every Matisse JFrame, the one inside the 
invokeLater), it will be printed out also.

I don't see anything wrong in our or javac code, sorry.

Comment 7 hlavki 2008-07-31 12:22:22 UTC
Created attachment 66160 [details]
hint example app
Comment 8 hlavki 2008-07-31 12:25:57 UTC
As you can see in attached example, hint is not shown in JPanel and it throws exception in JFrame... There is no problem
in other source files...

How to reproduce:
1. run netbeans with attached module
2. open or create new java application
3. create new JPanel and JFrame using wizard
Comment 9 hlavki 2008-08-27 22:41:52 UTC
I wrote steps to reproduce...
Comment 10 Max Sauer 2008-08-29 10:51:50 UTC
Thanks for the steps. I can see two problems here:

- Inside of a JPanel or anything with guarded sections, the detection whether hint should be disabled because of in guarded section is broken -- it 
should be fixed in: http://hg.netbeans.org/main/rev/2d8b39ed8585

so the hint should be displayed properly from now on.

- The NPE inside JFrame you mentioned. If the getTreeKinds() returns Tree.Kind.CLASS, every class inside of currently opened file is evaluated, and so is 
every anonymous class inside of your file. Since every generated JFrame contains one anonymous Runnable inside of its main method, this is the case. 
You have to detect anonymous classes and treat them differently, look inside java.hints module for how can this be done.

Comment 11 Quality Engineering 2008-08-30 05:31:29 UTC
Integrated into 'main-golden', available in build *200808300201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/2d8b39ed8585
User: Max Sauer <msauer@netbeans.org>
Log: #140653: Java hint does not run for some classes e.g. generated JPanel


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo