Auto-Importing via CtrlSpace Scala Classes in Java Classes imports them at the lowest package
Migrated from http://lampsvn.epfl.ch/trac/scala/ticket/1783
Reporter bjackman
I think this can best be explained with two classes
//SomeClass.scala
package bproblems.generics
class SomeClass {
var x : Int = 5
}
//JavaImportIssuesExample.java:
package bproblems.javaimportissues;
/**
//Type in the following sequence of keystrokes and java
//auto imports the wrong thing
//_underscores_ delimit special key combinations
//
//SomeClass_ctrl+space_
//
//notice that Selecting SomeClass from the pop-up list
//will cause java to import
//bproblems.SomeClass
//--instead of the proper--
//bproblems.generics.SomeClass
//Notice that attempting this on
//SomeDeeperClass produces a similar result
//
//SomeDeeperClass_ctrl+space_
//will cause java to import
//bproblems.SomeClass
//--instead of the proper--
//bproblems.generics.deeper.SomeClass
//However importing something from the libraries
//like scala.actors.Actor has no issues
//the import produced by
//Actor_ctrl+space_
//is scala.actors.Actor
}
Reporter bjackman
I think this can best be explained with two classes
//SomeClass.scala
package bproblems.generics
class SomeClass {
var x : Int = 5
}
//JavaImportIssuesExample.java:
package bproblems.javaimportissues;
/**
- This class documents issues encountered when java tries to import scala code
- # */
//Type in the following sequence of keystrokes and java
//auto imports the wrong thing
//_underscores_ delimit special key combinations
//
//SomeClass_ctrl+space_
//
//notice that Selecting SomeClass from the pop-up list
//will cause java to import
//bproblems.SomeClass
//--instead of the proper--
//bproblems.generics.SomeClass
//Notice that attempting this on
//SomeDeeperClass produces a similar result
//
//SomeDeeperClass_ctrl+space_
//will cause java to import
//bproblems.SomeClass
//--instead of the proper--
//bproblems.generics.deeper.SomeClass
//However importing something from the libraries
//like scala.actors.Actor has no issues
//the import produced by
//Actor_ctrl+space_
//is scala.actors.Actor
}
Leave a comment
on 2009-04-02 09:36 *
By tracImporter
Trac author: pelotom
CC Change: pelotom@…
CC Change: pelotom@…
on 2009-04-08 03:21 *
By tracImporter
Trac author: bjackman
CC Change: ben@…
Ok I found the source of the issue, however I am a little unsure of how to fix it, basically the fragment : PackageFragment used for ScalaCompilationUnit has a multiple packages specified, one for each level of package nesting. Deep down with the code completer, if a compilation unit is specified as having multiple packages it just defaults to take the first package defined.
To see a difference in behaviour between java and scala class put a breakpoint down in:
in the constructor of org.eclipse.jdt.internal.core.JavaElement (line 85)
When a java class is viewed here something like this appears if you look at fragment under the variables view in debug:
CC Change: ben@…
Ok I found the source of the issue, however I am a little unsure of how to fix it, basically the fragment : PackageFragment used for ScalaCompilationUnit has a multiple packages specified, one for each level of package nesting. Deep down with the code completer, if a compilation unit is specified as having multiple packages it just defaults to take the first package defined.
To see a difference in behaviour between java and scala class put a breakpoint down in:
in the constructor of org.eclipse.jdt.internal.core.JavaElement (line 85)
When a java class is viewed here something like this appears if you look at fragment under the variables view in debug:
bproblems.javaimportissues [in src [in bproblems]]
[Working copy] JavaImportIssuesExample.java
package bproblems.javaimportissues
class JavaImportIssuesExample
void food()
for scala something like this appears:bproblems.generics.deeper [in src [in bproblems]]
[Working copy] SomeDeeperClass.scala
package bproblems
package bproblems.generics
package bproblems.generics.deeper
class SomeDeeperClass
SomeDeeperClass()
int foo()
int bar()
int zoo()
int cat()
I am trying to find out where these package fragments come from, once i do hopefully I can submit a patch, if anyone else with better knowledge of the jdt could help me I would appreciate it.
on 2009-04-08 09:52 *
By tracImporter
Trac author: bjackman
I am going to attach a preliminary patch here, for some reason importing objects/modules in java doesn't yet work, however importing classes seems to work ok.
I am going to attach a preliminary patch here, for some reason importing objects/modules in java doesn't yet work, however importing classes seems to work ok.
on 2009-04-08 09:52 *
By tracImporter
on 2009-04-08 09:54 *
By tracImporter
Trac author: bjackman
Preliminary patch added, will look into fixing object importing
Preliminary patch added, will look into fixing object importing
on 2009-11-30 00:14 *
By tracImporter
Trac author: spiros
CC Change: sptz45@…
I would love to have this feature. Is this patch compatible with the recent code completion work?
CC Change: sptz45@…
I would love to have this feature. Is this patch compatible with the recent code completion work?
on 2009-11-30 00:29 *
By
Things have changed in this area quite significantly. I'll take another look at Ben's patch and see what can be carried over.
Updating tickets (#1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408, #2459, #2499, #2523, #2572, #2582, #2602, #2614, #2615, #2675, #2710, #2745, #2763, #2816, #2830, #2834, #2878, #2879, #2887, #2888, #2901, #2911, #2912, #2922, #2937, #2938, #2942, #2951, #2955, #2957, #2961, #2964, #2965, #2974, #2975, #2989, #2990, #3002, #3055, #3070, #3087, #3135, #3139, #3173, #3182, #3184, #3200, #3213, #3214, #3221, #3243, #3251)
on 2011-03-25 04:18 *
By Iulian Dragos
Updating tickets (#1000199, #1000200, #1000201, #1000204, #1000205, #1000209, #1000210, #1000211, #1000212, #1000215, #1000217, #1000218, #1000220, #1000222, #1000226, #1000227, #1000228, #1000230, #1000231, #1000232, #1000233, #1000235, #1000236, #1000237, #1000239, #1000240, #1000241, #1000242, #1000243, #1000244, #1000248, #1000249, #1000252, #1000253, #1000254, #1000255, #1000256, #1000258, #1000259, #1000032, #1000059, #1000062, #1000163, #1000197, #1000216, #1000221, #1000224, #1000121, #1000175, #1000219, #1000251, #1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408)