Now that we aren't hiding as many errors, ecj spits
out a lot of stuff on building.  This is the first of
a series of patches to attempt to clean this up.

ChangeLog:

2008-02-16  Andrew John Hughes  <[EMAIL PROTECTED]>


        * gnu/classpath/ServiceFactory.java:
        Use generics.
        * gnu/classpath/ServiceProviderLoadingAction.java:
        Likewise.

-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
Index: gnu/classpath/ServiceFactory.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/classpath/ServiceFactory.java,v
retrieving revision 1.6
diff -u -3 -p -u -r1.6 ServiceFactory.java
--- gnu/classpath/ServiceFactory.java	1 Jan 2007 20:27:37 -0000	1.6
+++ gnu/classpath/ServiceFactory.java	16 Feb 2008 00:22:01 -0000
@@ -48,6 +48,7 @@ import java.security.PrivilegedActionExc
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.ServiceConfigurationError;
 import java.util.logging.Level;
@@ -222,8 +223,8 @@ public final class ServiceFactory
    * @throws IllegalArgumentException if <code>spi</code> is
    * <code>null</code>.
    */
-  public static Iterator lookupProviders(Class spi,
-                                         ClassLoader loader)
+  public static <P> Iterator<P> lookupProviders(Class<P> spi,
+						ClassLoader loader)
   {
     return lookupProviders(spi, loader, false);
   }
@@ -266,12 +267,12 @@ public final class ServiceFactory
    * @throws IllegalArgumentException if <code>spi</code> is
    * <code>null</code>.
    */
-  public static Iterator lookupProviders(Class spi,
-                                         ClassLoader loader,
-					 boolean error)
+  public static <P> Iterator<P> lookupProviders(Class<P> spi,
+						ClassLoader loader,
+						boolean error)
   {
     String resourceName;
-    Enumeration urls;
+    Enumeration<URL> urls;
 
     if (spi == null)
       throw new IllegalArgumentException();
@@ -295,11 +296,14 @@ public final class ServiceFactory
 	  throw new ServiceConfigurationError("Failed to access + " +
 					      resourceName, ioex);
 	else
-	  return Collections.EMPTY_LIST.iterator();
+	  {
+	    List<P> empty = Collections.emptyList();
+	    return empty.iterator();
+	  }
       }
 
-    return new ServiceIterator(spi, urls, loader, error,
-                               AccessController.getContext());
+    return new ServiceIterator<P>(spi, urls, loader, error,
+				  AccessController.getContext());
   }
 
 
@@ -318,7 +322,7 @@ public final class ServiceFactory
    *
    * @see #lookupProviders(Class, ClassLoader)
    */
-  public static Iterator lookupProviders(Class spi)
+  public static <P> Iterator<P> lookupProviders(Class<P> spi)
   {
     ClassLoader ctxLoader;
 
@@ -335,14 +339,14 @@ public final class ServiceFactory
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Sascha Brawer</a>
    */
-  private static final class ServiceIterator
-    implements Iterator
+  private static final class ServiceIterator<P>
+    implements Iterator<P>
   {
     /**
      * The service provider interface (usually an interface, sometimes
      * an abstract class) which the services must implement.
      */
-    private final Class spi;
+    private final Class<P> spi;
 
 
     /**
@@ -350,7 +354,7 @@ public final class ServiceFactory
      * <code>META-INF/services/&lt;org.foo.SomeService&gt;</code>,
      * as returned by [EMAIL PROTECTED] ClassLoader#getResources(String)}.
      */
-    private final Enumeration urls;
+    private final Enumeration<URL> urls;
 
 
     /**
@@ -389,7 +393,7 @@ public final class ServiceFactory
      * [EMAIL PROTECTED] #next()}, or <code>null</code> if the iterator has
      * already returned all service providers.
      */
-    private Object nextProvider;
+    private P nextProvider;
 
     /**
      * True if a [EMAIL PROTECTED] ServiceConfigurationError} should be thrown
@@ -420,7 +424,7 @@ public final class ServiceFactory
      * @param securityContext the security context to use when loading
      * and initializing service providers.
      */
-    ServiceIterator(Class spi, Enumeration urls, ClassLoader loader,
+    ServiceIterator(Class<P> spi, Enumeration<URL> urls, ClassLoader loader,
 		    boolean error, AccessControlContext securityContext)
     {
       this.spi = spi;
@@ -436,9 +440,9 @@ public final class ServiceFactory
      * @throws NoSuchElementException if [EMAIL PROTECTED] #hasNext} returns
      * <code>false</code>.
      */
-    public Object next()
+    public P next()
     {
-      Object result;
+      P result;
 
       if (!hasNext())
         throw new NoSuchElementException();
@@ -461,7 +465,7 @@ public final class ServiceFactory
     }
 
 
-    private Object loadNextServiceProvider()
+    private P loadNextServiceProvider()
     {
       String line;
       
@@ -523,7 +527,7 @@ public final class ServiceFactory
                * active when calling lookupProviders.
                */
               return AccessController.doPrivileged(
-                new ServiceProviderLoadingAction(spi, line, loader),
+                new ServiceProviderLoadingAction<P>(spi, line, loader),
                 securityContext);
             }
           catch (Exception ex)
@@ -577,7 +581,7 @@ public final class ServiceFactory
         if (!urls.hasMoreElements())
           return;
 
-        currentURL = (URL) urls.nextElement();
+        currentURL = urls.nextElement();
         try
           {
             reader = new BufferedReader(new InputStreamReader(
Index: gnu/classpath/ServiceProviderLoadingAction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/classpath/ServiceProviderLoadingAction.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 ServiceProviderLoadingAction.java
--- gnu/classpath/ServiceProviderLoadingAction.java	12 Feb 2006 19:38:46 -0000	1.3
+++ gnu/classpath/ServiceProviderLoadingAction.java	16 Feb 2008 00:22:01 -0000
@@ -54,15 +54,15 @@ import java.security.PrivilegedException
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Sascha Brawer</a>
  */
-final class ServiceProviderLoadingAction
-  implements PrivilegedExceptionAction
+final class ServiceProviderLoadingAction<P>
+  implements PrivilegedExceptionAction<P>
 {
   /**
    * The interface to which the loaded service provider implementation
    * must conform.  Usually, this is a Java interface type, but it
    * might also be an abstract class or even a concrete class.
    */
-  private final Class spi;
+  private final Class<P> spi;
 
 
   /**
@@ -97,7 +97,7 @@ final class ServiceProviderLoadingAction
    * <code>providerName</code> or <code>loader</code> is
    * <code>null</code>.
    */
-  ServiceProviderLoadingAction(Class spi, String providerName,
+  ServiceProviderLoadingAction(Class<P> spi, String providerName,
                                ClassLoader loader)
   {
     if (spi == null || providerName == null || loader == null)
@@ -130,13 +130,13 @@ final class ServiceProviderLoadingAction
    * no-argument constructor; or if there some other problem with
    * creating a new instance of the service provider.
    */
-  public Object run()
+  public P run()
     throws Exception
   {
-    Class loadedClass;
-    Object serviceProvider;
+    Class<P> loadedClass;
+    P serviceProvider;
 
-    loadedClass = loader.loadClass(providerName);
+    loadedClass = (Class<P>) loader.loadClass(providerName);
     serviceProvider = loadedClass.newInstance();
 
     // Ensure that the loaded provider is actually implementing

Attachment: signature.asc
Description: Digital signature

Reply via email to