Removing unneeded package information

Is there a way in IDEA to remove unneeded package information class usages?
For example consider the following file:

package com.verylong.package.name.for.you;
class Something {
com.verylong.package.name.for.you.OtherClass otherClass;
com.verylong.package.name.for.someone.ThirdClass thirdClass;
}

I would want IDEA to parse it as follows:

package com.verylong.package.name.for.you;
import com.verylong.package.name.for.someone.ThirdClass;
class Something {
OtherClass otherClass;
ThirdClass thirdClass;
}

Currently IDEA doesn't seem to do that either with "Format source" or
"Optimize imports" functionalities.

Thanks,
Markus


2 comments

+1

In generics support for Alt+Enter pasted Full class name, how switch if of?

Thanks!

"Markus Halttunen" <markus.halttunen@tietoteollisuus.com> wrote in message
news:bpinir$tdk$1@is.intellij.net...

Is there a way in IDEA to remove unneeded package information class

usages?

For example consider the following file:

>

package com.verylong.package.name.for.you;
class Something {
com.verylong.package.name.for.you.OtherClass otherClass;
com.verylong.package.name.for.someone.ThirdClass thirdClass;
}

>

I would want IDEA to parse it as follows:

>

package com.verylong.package.name.for.you;
import com.verylong.package.name.for.someone.ThirdClass;
class Something {
OtherClass otherClass;
ThirdClass thirdClass;
}

>

Currently IDEA doesn't seem to do that either with "Format source" or
"Optimize imports" functionalities.

>

Thanks,
Markus

>
>


0


The InspectionGadgets plugin currently includes an inspection for unnecessary fully-qualified names, which will point out all instances of fully qualified names which could be replaced by imports. There is also a quick fix which allows you to fix these names either in batch via the inspections panel, or individually as an intention. I will note that it's not the most stable inspection I've written, and has some issues with inner classes and classes with the same name as java.lang classes, but for most uses it'll do just what you want.
I'll be fixing these issues in the next InspectionGadgets release.

--Dave

0

Please sign in to leave a comment.