IDEA 9.0M1 (10372) Optimize Imports applies wildcards liberally
Originally posted in http://jetbrains.net/jira/browse/IDEA-24631
One thing I noticed when trying out 9.0M1, is that when you Optimize
Imports, it tends to use wildcard imports quite a bit. Is there a way to
configure which packages are allowed to use wildcard imports and which are
not?
I don't ever want java.util.* to appear in an import statement, but
javax.swing.* may be ok.
If I recall, this is a preference which can be configured in IDEA 7, but I couldn't find it in IDEA 9. Is this feature in 9.0M1, or will it be added?
Thanks!
Please sign in to leave a comment.
And the answer is:
File -> Settings -> Code Style -> Imports
The problem is, it seems not to work. Attached is a screen cap of my settings. When I optimize imports on the following class, I end up with a 'import java.util.*'. Am I just missing something?
package edu.jhu.library.ivoa.analysis;
import java.util.*;
/**
* Implements the {@link edu.jhu.library.ivoa.analysis.FITSKeywordReporter reporting} and
* {@link FITSKeywordCounter counting} interfaces.
* <p/>
* <em>Not thread safe.</em> Each thread should have an instance of this class. It is not safe
* to share an instance of this class among multiple threads.
*/
public class FITSKeywordReporterImpl implements FITSKeywordReporter, FITSKeywordCounter
{
/**
* Maintains the count of keywords per service, and tracks keyword values.
*/
private KeywordServiceCounter keywordServiceCounts = new KeywordServiceCounter();
/**
* Maintains the count of HDUs per service.
*/
private Map<String, Integer> hduServiceCounts = new HashMap<String, Integer>();
public void countKeyword( String keyword, String serviceId, int count )
{
if ( count < 1 )
{
return;
}
if ( keyword == null || keyword.trim().equals( "" ) )
{
return;
}
keywordServiceCounts.incrementKeyword( keyword, serviceId, count );
}
public void countKeywordValue( String keyword, String serviceId, String value, int count )
{
if ( count < 1 )
{
return;
}
if ( keyword == null || keyword.trim().equals( "" ) )
{
return;
}
keywordServiceCounts.recordValue( keyword, serviceId, value );
}
public void countHdu( String serviceId, int count )
{
if ( count < 1 )
{
throw new IllegalArgumentException( "Count must be 1 or greater." );
}
if ( isEmptyOrNull( serviceId ) )
{
throw new IllegalArgumentException( "Service ID cannot be null." );
}
if ( hduServiceCounts.containsKey( serviceId ) )
{
Integer i = hduServiceCounts.get( serviceId );
hduServiceCounts.put( serviceId, i + count );
}
else
{
hduServiceCounts.put( serviceId, count );
}
}
public int getAnalyzedHduCount()
{
int total = 0;
for ( Map.Entry<String, Integer> entry : hduServiceCounts.entrySet() )
{
total = entry.getValue() + total;
}
return total;
}
public int getAnalyzedHduCount( String serviceId )
{
if ( hduServiceCounts.containsKey( serviceId ) )
{
return hduServiceCounts.get( serviceId );
}
return 0;
}
public int getKeywordHduCount( String keyword )
{
return keywordServiceCounts.getCount( keyword, null );
}
public int getKeywordHduCount( String keyword, String serviceId )
{
return keywordServiceCounts.getCount( keyword, serviceId );
}
public Set<String> keywords()
{
return Collections.unmodifiableSet( keywordServiceCounts.keywords() );
}
public Set<String> services()
{
Set<String> results = new HashSet<String>();
results.addAll( hduServiceCounts.keySet() );
results.addAll( keywordServiceCounts.services() );
return Collections.unmodifiableSet( results );
}
public Set<String> values( String keyword )
{
return Collections.unmodifiableSet( keywordServiceCounts.getValues( keyword ) );
}
public Set<String> values( String keyword, String serviceId )
{
return Collections.unmodifiableSet( keywordServiceCounts.getValues( keyword, serviceId ) );
}
public FITSKeywordReporter getReporter()
{
return this;
}
private static boolean isEmptyOrNull( String s )
{
if ( s == null || s.trim().equals( "" ) )
{
return true;
}
return false;
}
}
Attachment(s):
Screen shot 2009-09-14 at 10.42.39 AM.png
Hello Elliot,
Settings | Code Style | Imports
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
You'll need to increase the value of "Class count to use import with '*'" setting. While there is a setting to specify packages you always want to use the "*" import with, to the best of my knowledge there isn't the opposite setting to specify packages to never use the "*" import with. So the workaround is to set your count parameter high.
If you wanted to open a new JIRA feature request for an option to allow specifying packages to never use the "*" import with, I'd vote for it. There are times that that would be handy.