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.
Summary: | Java hint does not run for some classes e.g. generated JPanel | ||
---|---|---|---|
Product: | java | Reporter: | hlavki <hlavki> |
Component: | Hints | Assignee: | Max Sauer <msauer> |
Status: | RESOLVED FIXED | ||
Severity: | blocker | ||
Priority: | P3 | ||
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | hint example app |
Description
hlavki
2008-07-17 23:52:53 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> 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); } I don't understand what are we required to fix... 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> Maxi do you understand? If it is bug in IDE, please write steps to reproduce. If it is API bug, please write test. 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. Created attachment 66160 [details]
hint example app
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 I wrote steps to reproduce... 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. 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 |