mengdiwang / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Organize imports #540

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A lot of uneseccary import declarations are used, better to remove them:

The import java.util.TreeMap is never 
used    ImmutableSortedMap.java /guava-src-r08/com/google/common/collect    line 
35  Java Problem
The import java.util.TreeMap is never 
used    Sets.java   /guava-src-r08/com/google/common/collect    line 49 Java Problem
The import java.util.SortedSet is never 
used    Ordering.java   /guava-src-r08/com/google/common/collect    line 36 Java Problem
The import java.util.SortedSet is never 
used    Sets.java   /guava-src-r08/com/google/common/collect    line 48 Java Problem
The import java.util.SortedMap is never 
used    Ordering.java   /guava-src-r08/com/google/common/collect    line 35 Java Problem
The import java.util.Set is never 
used    RowSortedTable.java /guava-src-r08/com/google/common/collect    line 23 Java 
Problem
The import java.util.Set is never 
used    SortedSetMultimap.java  /guava-src-r08/com/google/common/collect    line 
24  Java Problem
The import java.util.Set is never 
used    StandardRowSortedTable.java /guava-src-r08/com/google/common/collect    line 
26  Java Problem
The import java.util.Set is never 
used    TreeBasedTable.java /guava-src-r08/com/google/common/collect    line 28 Java 
Problem
The import java.util.Set is never 
used    TreeMultimap.java   /guava-src-r08/com/google/common/collect    line 29 Java 
Problem
The import java.util.regex.PatternSyntaxException is never 
used    PatternFilenameFilter.java  /guava-src-r08/com/google/common/io line 
25  Java Problem
The import java.util.PriorityQueue is never 
used    MinMaxPriorityQueue.java    /guava-src-r08/com/google/common/collect    line 
37  Java Problem
The import java.util.NoSuchElementException is never 
used    Ordering.java   /guava-src-r08/com/google/common/collect    line 34 Java Problem
The import java.util.NoSuchElementException is never 
used    PeekingIterator.java    /guava-src-r08/com/google/common/collect    line 22 Java 
Problem
The import java.util.NoSuchElementException is never 
used    Preconditions.java  /guava-src-r08/com/google/common/base   line 22 Java 
Problem
The import java.util.Map is never 
used    MapMaker.java   /guava-src-r08/com/google/common/collect    line 34 Java Problem
The import java.util.ListIterator is never 
used    AbstractIndexedListIterator.java    /guava-src-r08/com/google/common/collect    l
ine 23  Java Problem
The import java.util.List is never 
used    Multiset.java   /guava-src-r08/com/google/common/collect    line 24 Java Problem
The import java.util.IdentityHashMap is never 
used    Sets.java   /guava-src-r08/com/google/common/collect    line 41 Java Problem
The import java.util.HashSet is never 
used    ImmutableSet.java   /guava-src-r08/com/google/common/collect    line 28 Java 
Problem
The import java.util.HashSet is never 
used    Iterables.java  /guava-src-r08/com/google/common/collect    line 33 Java 
Problem
The import java.util.HashSet is never 
used    Ordering.java   /guava-src-r08/com/google/common/collect    line 30 Java Problem
The import java.util.HashMap is never 
used    ImmutableMap.java   /guava-src-r08/com/google/common/collect    line 27 Java 
Problem
The import java.util.HashMap is never 
used    Sets.java   /guava-src-r08/com/google/common/collect    line 39 Java Problem
The import java.util.Formatter is never 
used    Strings.java    /guava-src-r08/com/google/common/base   line 24 Java Problem
The import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy is never 
used    MoreExecutors.java  /guava-src-r08/com/google/common/util/concurrent    line 
31  Java Problem
The import java.util.concurrent.ThreadFactory is never 
used    MoreExecutors.java  /guava-src-r08/com/google/common/util/concurrent    line 
29  Java Problem
The import java.util.concurrent.RejectedExecutionException is never 
used    ListenableFuture.java   /guava-src-r08/com/google/common/util/concurrent    line
 23 Java Problem
The import java.util.concurrent.Future is never 
used    CheckedFuture.java  /guava-src-r08/com/google/common/util/concurrent    line 
23  Java Problem
The import java.util.concurrent.ExecutionException is never 
used    CheckedFuture.java  /guava-src-r08/com/google/common/util/concurrent    line 
22  Java Problem
The import java.util.concurrent.ExecutionException is never 
used    Service.java    /guava-src-r08/com/google/common/base   line 21 Java Problem
The import java.util.concurrent.CancellationException is never 
used    CheckedFuture.java  /guava-src-r08/com/google/common/util/concurrent    line 
21  Java Problem
The import java.util.Collections is never 
used    ImmutableList.java  /guava-src-r08/com/google/common/collect    line 29 Java 
Problem
The import java.util.Collections is never 
used    ImmutableMap.java   /guava-src-r08/com/google/common/collect    line 26 Java 
Problem
The import java.util.Collections is never 
used    ImmutableSet.java   /guava-src-r08/com/google/common/collect    line 27 Java 
Problem
The import java.util.Collections is never 
used    Iterables.java  /guava-src-r08/com/google/common/collect    line 32 Java 
Problem
The import java.util.Collections is never 
used    Multiset.java   /guava-src-r08/com/google/common/collect    line 22 Java Problem
The import java.util.Collections is never 
used    SortedLists.java    /guava-src-r08/com/google/common/collect    line 21 Java 
Problem
The import java.util.Collection is never 
used    TreeMultiset.java   /guava-src-r08/com/google/common/collect    line 25 Java 
Problem
The import java.util.BitSet is never 
used    Booleans.java   /guava-src-r08/com/google/common/primitives line 29 Java 
Problem
The import java.util.Arrays is never 
used    Booleans.java   /guava-src-r08/com/google/common/primitives line 28 Java 
Problem
The import java.util.Arrays is never 
used    Bytes.java  /guava-src-r08/com/google/common/primitives line 28 Java Problem
The import java.util.Arrays is never 
used    Chars.java  /guava-src-r08/com/google/common/primitives line 29 Java Problem
The import java.util.Arrays is never 
used    Doubles.java    /guava-src-r08/com/google/common/primitives line 28 Java 
Problem
The import java.util.Arrays is never 
used    Floats.java /guava-src-r08/com/google/common/primitives line 28 Java 
Problem
The import java.util.Arrays is never 
used    Ints.java   /guava-src-r08/com/google/common/primitives line 29 Java Problem
The import java.util.Arrays is never 
used    Lists.java  /guava-src-r08/com/google/common/collect    line 37 Java Problem
The import java.util.Arrays is never 
used    Longs.java  /guava-src-r08/com/google/common/primitives line 29 Java Problem
The import java.util.Arrays is never 
used    Shorts.java /guava-src-r08/com/google/common/primitives line 29 Java 
Problem
The import java.lang.ref.WeakReference is never 
used    MapMaker.java   /guava-src-r08/com/google/common/collect    line 33 Java Problem
The import java.lang.ref.SoftReference is never 
used    MapMaker.java   /guava-src-r08/com/google/common/collect    line 32 Java Problem
The import java.lang.ref.ReferenceQueue is never 
used    FinalizablePhantomReference.java    /guava-src-r08/com/google/common/base   line
 18 Java Problem
The import java.lang.ref.ReferenceQueue is never 
used    FinalizableSoftReference.java   /guava-src-r08/com/google/common/base   line 
17  Java Problem
The import java.lang.ref.ReferenceQueue is never 
used    FinalizableWeakReference.java   /guava-src-r08/com/google/common/base   line 
17  Java Problem
The import java.io.Serializable is never 
used    ForwardingObject.java   /guava-src-r08/com/google/common/collect    line 
21  Java Problem
The import java.io.IOException is never 
used    ByteArrayDataInput.java /guava-src-r08/com/google/common/io line 20 Java 
Problem
The import java.io.IOException is never 
used    ByteArrayDataOutput.java    /guava-src-r08/com/google/common/io line 20 Java 
Problem
The import com.google.common.base.Service.State is never 
used    AbstractService.java    /guava-src-r08/com/google/common/util/concurrent    line 
24  Java Problem
The import com.google.common.base.Objects is never 
used    Table.java  /guava-src-r08/com/google/common/collect    line 21 Java Problem

Original issue reported on code.google.com by ullenb...@gmail.com on 3 Feb 2011 at 10:29

GoogleCodeExporter commented 9 years ago
Hi!

What tool did you use to generate these warnings? Looks interesting.

Regarding the imports you mention, I think they are necessary, because they 
import classes that are referred to in the Javadoc comments.

For example, in ImmutableSortedMap, the TreeMap import is there because we 
reference {@link TreeMap#comparator()} in the Javadoc (at line 605: 
http://code.google.com/p/guava-libraries/source/browse/trunk/src/com/google/comm
on/collect/ImmutableSortedMap.java?r=113#602 ).

We could remove these imports by using fully-qualified class names in the 
Javadoc comments (e.g. {@link java.util.TreeMap#comparator()}), but it would be 
far less readable IMO.

I have only checked a few of the imports you listed, so it's possible that some 
of them are indeed unnecessary, and are not even used in Javadoc comments.

Original comment by nev...@gmail.com on 4 Feb 2011 at 12:12

GoogleCodeExporter commented 9 years ago
It's possible some are unneeded, but if it took you 30 seconds to investigate, 
that would be 30 seconds of your life you'd never get back.

Original comment by kevinb@google.com on 4 Feb 2011 at 1:42

GoogleCodeExporter commented 9 years ago
It's just Eclipse with the default setting which shows you which import aren't 
needed. 

I just quickly copied the result from Eclipse, but its true that the explicit 
reference is necessary for the JavaDoc. 
(http://java.sun.com/j2se/javadoc/faq/#missinglinks explains why an import with 
@link is needed.)

There is just 2 useless imports because there are coming from inside the Guava 
library:

The import com.google.common.base.Service.State is never 
used    AbstractService.java    /guava-src-r08/com/google/common/util/concurrent    line 
24  Java Problem
The import com.google.common.base.Objects is never 
used    Table.java  /guava-src-r08/com/google/common/collect    line 21 Java Problem

I would better just reported them to avoid confusion.

Original comment by ullenb...@gmail.com on 4 Feb 2011 at 4:48

GoogleCodeExporter commented 9 years ago
About javadoc readability:

One pattern I use a lot is to use the fully qualified link with a readable 
alias, so instead of this:

{@link java.util.TreeMap#comparator()})

I'd use this:

{@link java.util.TreeMap#comparator() TreeMap.comparator()})

This gets rid of the import but still renders the output nicely as 
"TreeMap.comparator()"

Original comment by SeanPFl...@googlemail.com on 4 Feb 2011 at 11:45

GoogleCodeExporter commented 9 years ago
The readable alias is a nice trick, and I sometimes use it for other use cases 
(not to hide inline imports).

I prefer having the import statements at the top of the file, instead of having 
them inline inside Javadoc comments: I rarely look at the import statements, 
and I think it's better to make the Javadoc comments as short as possible. With 
the alias trick, the Javadoc looks the same either way, but the source code 
comment is cleaner / shorter without inline imports + alias:

{@link TreeMap#comparator()}

versus

{@link java.util.TreeMap#comparator() TreeMap.comparator()}

Original comment by nev...@gmail.com on 4 Feb 2011 at 12:55

GoogleCodeExporter commented 9 years ago
Personally I would prefer to see full-qualified types for the JavaDoc and not 
import statements for mainly two reasons:

a) Using an import declaration for any external tool is IMHO not the right way 
to go. This is a technical dependency which has nothing to do with the source 
itself but just "makes javadoc works". And I don't care that much about fully 
qualified types in JavaDoc but I care about unnecessary imports which clutters 
my source.

b) import declarations show dependencies the source have (not the JavaDoc). 
That means from the imports I can see on what other types my type rely on. The 
"JavaDoc-import" blurs this and it is misguiding that is shows a dependency 
which is actually doesn’t exit. Should a Swing-class like java.awt.EventQueue 
be imported from some core thread-class "just" to link to the JavaDoc and show 
a similar behaviour? Yes, no, depends?

At least a comment on the import-line would be great. Or wait until Java X 
comes with Annotations on import declarations to document it like 
@VisibleForTesting does ...

Original comment by ullenb...@gmail.com on 4 Feb 2011 at 9:55

GoogleCodeExporter commented 9 years ago
Re comment 3:

import com.google.common.base.Service.State is never used   AbstractService.java

If I removed that, I would have to change

   * Implementing classes should invoke this method once their service has
   * started. It will cause the service to transition from {@link
   * State#STARTING} to {@link State#RUNNING}.

to

   * Implementing classes should invoke this method once their service has
   * started. It will cause the service to transition from {@link
   * com.google.common.base.Service.State#STARTING} to {@link
   * com.google.common.base.Service.State#RUNNING}.

in fact, to preserve the output I might even have to do this

   * Implementing classes should invoke this method once their service has
   * started. It will cause the service to transition from {@link
   * com.google.common.base.Service.State#STARTING Service.STARTING} to {@link
   * com.google.common.base.Service.State#RUNNING Service.RUNNING}.

(but that I don't know.)

Is that worth it?  To me, the ease of readability of javadoc in both source 
form and generated form is more important than these other concerns.

BTW, I even commented the import specifically hoping to avoid this complaint:

import com.google.common.base.Service.State; // javadoc needs this

It would be nice if javadoc didn't need it, and could just tell that "State" 
refers to the nested class of the supertype, but it does.

Your other issue:

The import com.google.common.base.Objects is never used Table.java

is indeed used in javadoc just like all this others.

I'm going to let this drop now because it's really not worth all this time and 
thought.

Original comment by kevinb@google.com on 4 Feb 2011 at 11:47

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15