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.
Groovy Editor support to fix missing imports.
To fix imports of missing types, we have to test for these type-usage-patterns and see which information we get from the groovy-compiler: 1.) create a new type with dflt. constructor: MyType t = new MyType() 2.) create a new type with special constructor: MyType t = new MyType(input) 3.) Access static method of type: result = MyType.staticMethod(input) 4.) Access public field of unknown type: result = MyType.fieldVar 5.) .class access of unknown type: Class x = MyType.class 6.) declare class in parameters: void testFct(MyType m) { } 7.) Reflection access/query: Class.forName((MyType);
To implement group of related features we have to provide this to the user: 1.) Add missing imports 2.) Provide drop-down box if multiple candidates exist 3.) Hint provider for missing *and* unused imports 4.) Remove unused imports The corresponding code in the Java editor can be found here: java.editor/src/org/netbeans/modules/java/editor/imports
OK - here are the corresponding groovy errer-messages: //------------------------------------------------------------------------------------ //1.) create a new type with dflt. constructor: MyType t = new MyType() // gives: "unable to resolve class" at compile-time // Found: COMPILE-TIME //------------------------------------------------------------------------------------ //2.) create a new type with special constructor: // gives: String t2 = new String(1L) //Caught: groovy.lang.GroovyRuntimeException: failed to invoke constructor: public java.lang.String(byte[]) with arguments: {[1]} reason: java.lang.IllegalArgumentException: argument type mismatch // at unresolvedTypes.run(unresolvedTypes.groovy:17) // at unresolvedTypes.main(unresolvedTypes.groovy) // Found: RUN-TIME //------------------------------------------------------------------------------------ //3.) Access static method of type: // gives: String.valueOf2(true) //Caught: groovy.lang.MissingMethodException: No signature of method: static java.lang.String.valueOf2() is applicable for argument types: (java.lang.Boolean) values: {true} // at unresolvedTypes.run(unresolvedTypes.groovy:27) // at unresolvedTypes.main(unresolvedTypes.groovy) // Found: RUN-TIME //------------------------------------------------------------------------------------ //4.) Access public field of unknown type: // gives: System.out2 //Caught: groovy.lang.MissingPropertyException: No such property: out2 for class: java.lang.System // at unresolvedTypes.run(unresolvedTypes.groovy:5) // at unresolvedTypes.main(unresolvedTypes.groovy) // Found: RUN-TIME //------------------------------------------------------------------------------------ //5.) .class access of unknown type: // gives: Class x = UnknownType.class //Caught: groovy.lang.MissingPropertyException: No such property: UnknownType for class: unresolvedTypes // at unresolvedTypes.main(unresolvedTypes.groovy) // Found: RUN-TIME //------------------------------------------------------------------------------------ //6.) declare class in parameters: // gives: void testFct(MyType m) { } // gives: "unable to resolve class" at compile-time // Found: COMPILE-TIME //------------------------------------------------------------------------------------ //7.) Reflection access/query: // gives: Class t3 = Class.forName("java.lang.Thread4") //Caught: java.lang.ClassNotFoundException: java.lang.Thread4 // at unresolvedTypes.run(unresolvedTypes.groovy:76) // at unresolvedTypes.main(unresolvedTypes.groovy) // Found: RUN-TIME
OK, this one should be fixed now: http://hg.netbeans.org/main/contrib/rev/06bb7da58c96 http://hg.netbeans.org/main/contrib/rev/a7d658f97499 http://hg.netbeans.org/main/contrib/rev/7ad45d82386f http://hg.netbeans.org/main/contrib/rev/13ace1d25379 ...
v., see issue 149948