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 123164 - fix imports for missing types
Summary: fix imports for missing types
Status: VERIFIED FIXED
Alias: None
Product: groovy
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: schmidtm
URL: http://wiki.netbeans.org/wiki/view/Gr...
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-30 17:03 UTC by schmidtm
Modified: 2008-10-30 14:25 UTC (History)
0 users

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description schmidtm 2007-11-30 17:03:19 UTC
Groovy Editor support to fix missing imports.
Comment 1 schmidtm 2008-04-15 14:45:53 UTC
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);
Comment 2 schmidtm 2008-04-28 09:40:59 UTC
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
Comment 3 schmidtm 2008-04-28 11:48:12 UTC
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

Comment 5 Lukas Jungmann 2008-10-13 14:24:17 UTC
v., see issue 149948