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.
The following hint taken from NetBeans help "Syntax Rules for Declarative Hints" does not work. Note it appears that the mere presence of a custom import kills the hint, even when the import is not used; see ex 3. ======== FAIL ex 1 =============== <? import java.util.LinkedList; import java.util.ArrayList; ?> new LinkedList() => new ArrayList() ;; ================================== This hint does work. ======== WORKS ex 2 ============== new java.util.LinkedList() => new java.util.ArrayList() ;; ================================== The following also fails. Note that this is the same as ex 2, only a custom import section has been added. ======== FAIL ex 3 =============== <? import java.util.Set; ?> new java.util.LinkedList() => new java.util.ArrayList() ;; ==================================
I've tried in NB dev, copy pasted the FAIL ex 1, then typed a simple statement List ll = new LinkedList(); The expression was underlined and the hint applied smoothly. What exactly is your code on which the hint does not work ? Do you use generics in the new expression ?
I just tried it with a build I did a few days ago (see below). There's no plugins (installed junit to get test project I'm working with OK) and a fresh userdir, no changes made. It fails, don't see any hint lightbulb. I get "No Pattern Found" dialog. I'm attaching a png to show the setup. Maybe there's some logging I can turn on? Product Version: NetBeans IDE Dev (Build 20150302-90a1dce2ad09) Updates: Updates available Java: 1.8.0_31; Java HotSpot(TM) 64-Bit Server VM 25.31-b07 Runtime: Java(TM) SE Runtime Environment 1.8.0_31-b13 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Created attachment 152448 [details] showing the setup
Doh! I just reread your comment, where you asked if i used generics. Yep, that's it.
I haven't been able to find a bug about the generics. I also haven't been able to rewrite the hint to recognize generics (keep getting some exceptions). Is it considered a bug? Is there an outstanding issue?
Using a build I made today, with todays sources. NB dev can't handle these declarative hints. Starting with a clean userdir/cache, open a project with one source file: package debug; import java.util.LinkedList; public class NewClass { void foo() { LinkedList linkedList = new LinkedList(); } } do Refactor>InspectAndTransform>Browse>New...>EditScript and paste "FAIL ex 1" in there. Get's an exception. Click save, an exception. Click cancel, click cancel, close IDE. The save actually occured. $ cat /errw/AppData/Roaming/NetBeans/dev/config/rules/Inspection.hint <!description="Empty Inspection"> <? import java.util.LinkedList; import java.util.ArrayList; ?> new LinkedList() => new ArrayList() ;; Restarting the IDE, get many exceptions during startup, see below, and any keystrokes in the editor (such as moving the cursor) produces exceptions. INFO [org.openide.util.lookup.MetaInfServicesLookup]: Cannot create class org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl java.lang.ClassCastException: class com.sun.tools.javac.api.JavacTool at java.lang.Class.asSubclass(Class.java:3396) at javax.tools.ToolProvider.getSystemToolClass(ToolProvider.java:178) at javax.tools.ToolProvider.getSystemTool(ToolProvider.java:158) at javax.tools.ToolProvider.getSystemJavaCompiler(ToolProvider.java:102) at org.netbeans.modules.java.hints.declarative.Hacks.compile(Hacks.java:102) at org.netbeans.modules.java.hints.declarative.MethodInvocationContext.setCode(MethodInvocationContext.java:257) at org.netbeans.modules.java.hints.declarative.DeclarativeHintsParser$Impl.parseInput(DeclarativeHintsParser.java:188) ... at org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl.reload(RulesManagerImpl.java:84) at org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl.<init>(RulesManagerImpl.java:76) ... [catch] at org.openide.util.lookup.MetaInfServicesLookup$Item.getInstance(MetaInfServicesLookup.java:514) .... SEVERE [org.openide.util.Exceptions] java.lang.NullPointerException at org.netbeans.modules.java.hints.spiimpl.hints.HintsInvoker.computeHints(HintsInvoker.java:154) ...
I opened bug 250982 earlier, but now I'm confused and maybe both bugs aren't needed.
I wrote the rule as new java.util.LinkedList<$any$>() => new java.util.ArrayList<$any$>() ;; and it matches the generics.
(In reply to err from comment #8) This is generics on both on NB8.0.2 and nb-dev. Also on NB8.0.2 I still can not get the <? import... ?> to work, with or without generics. And on nb-dev I can't seem to do anything with "<?" in it, as mentioned earlier, because of the exceptions.
(In reply to err from comment #9) > (In reply to err from comment #8) > This is generics on both on NB8.0.2 and nb-dev. > > Also on NB8.0.2 I still can not get the <? import... ?> to work, with or > without generics. > > And on nb-dev I can't seem to do anything with "<?" in it, as mentioned > earlier, because of the exceptions. The <? import ?> section seems to work for me on dev builds, once issue #250982 was fixed. As <$any$> allows to match generic and two forms (non-generic + generic) of the hint can be entered - is the issue still valid ?
Since issue #250982 has a fix for the import/custom-hint issues I'll dup this issue to it. The generics, and using <$any$>, just confused the real issue when I was investigating. *** This bug has been marked as a duplicate of bug 250982 ***
(Guess it wasn't a duplicate after all) (BTW, in messages.log about "malformed html" triggered by "<$any$>" are probably innocuous?) Using a locally built NB. Given the source file: package debug; import java.util.List; import java.util.LinkedList; public class NewClass { void foo() { List<String> linkedList = new LinkedList<>(); List linkedList2 = new LinkedList(); } } === This hint WORKS === $ cat /errw/AppData/Roaming/NetBeans/dev/config/rules/LinkedListToArray.hint <!description="change LinkedList to ArrayList"> new java.util.LinkedList<$any$>() => new java.util.ArrayList<$any$>() ;; new java.util.LinkedList() => new java.util.ArrayList() ;; =========================== === This hint DOES NOTHING === $ cat /errw/AppData/Roaming/NetBeans/dev/config/rules/LinkedListToArray.hint <!description="change LinkedList to ArrayList"> <? import java.util.LinkedList; import java.util.ArrayList; ?> new LinkedList<$any$>() => new ArrayList<$any$>() ;; new LinkedList() => new ArrayList() ;; =========================== Product Version: NetBeans IDE Dev (Build 20150401-09512dd8aa7b) Java: 1.8.0_40; Java HotSpot(TM) 64-Bit Server VM 25.40-b25 Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b26 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb) $ hg log -r 5767ca601f74 changeset: 285322:5767ca601f74 user: Svata Dedic <sdedic@netbeans.org> date: Wed Mar 25 14:11:34 2015 +0100 summary: #250982: prevent loading JavacTool from JDK
I just tried it again on Product Version: NetBeans IDE Dev (Build 201505280001) (you never know...)
Got it. The culprit is here: <!description="Empty Inspection"> <? import java.util.LinkedList; import java.util.ArrayList; ?> You have to put the processing instruction at the very top - the <!description must go after it. Other java blocks may be interleaved with rules and options, but imports must go first.