8038644: Fix raw and unchecked warnings in sun.java2d.*
authorhenryjen
Fri, 18 Apr 2014 09:56:34 -0700
changeset 24522 3a0bbf9f5e81
parent 24521 97047c850d31
child 24523 d3d9e027b190
8038644: Fix raw and unchecked warnings in sun.java2d.* Reviewed-by: darcy, prr
jdk/src/share/classes/sun/java2d/Spans.java
jdk/src/share/classes/sun/java2d/SunGraphics2D.java
jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java
jdk/src/share/classes/sun/java2d/loops/Blit.java
jdk/src/share/classes/sun/java2d/loops/CustomComponent.java
jdk/src/share/classes/sun/java2d/loops/GeneralRenderer.java
jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitive.java
jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveMgr.java
jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java
jdk/src/share/classes/sun/java2d/loops/MaskBlit.java
jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java
jdk/src/share/classes/sun/java2d/pipe/AlphaPaintPipe.java
jdk/src/share/classes/sun/java2d/pipe/RenderQueue.java
jdk/src/share/classes/sun/java2d/pipe/SpanClipRenderer.java
jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java
--- a/jdk/src/share/classes/sun/java2d/Spans.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/Spans.java	Fri Apr 18 09:56:34 2014 -0700
@@ -49,7 +49,7 @@
      * Holds a list of individual
      * Span instances.
      */
-    private List mSpans = new Vector(kMaxAddsSinceSort);
+    private List<Span> mSpans = new Vector<>(kMaxAddsSinceSort);
 
     /**
      * The number of <code>Span</code>
@@ -144,7 +144,7 @@
         Collections.sort(mSpans);
         mAddsSinceSort = 0;
 
-        Iterator iter = mSpans.iterator();
+        Iterator<Span> iter = mSpans.iterator();
 
         /* Have 'span' start at the first span in
          * the collection. The collection may be empty
@@ -152,7 +152,7 @@
          */
         Span span = null;
         if (iter.hasNext()) {
-            span = (Span) iter.next();
+            span = iter.next();
         }
 
         /* Loop over the spans collapsing those that intersect
@@ -160,7 +160,7 @@
          */
         while (iter.hasNext()) {
 
-            Span nextSpan = (Span) iter.next();
+            Span nextSpan = iter.next();
 
             /* The spans are in ascending start position
              * order and so the next span's starting point
@@ -202,9 +202,9 @@
     private void printSpans() {
         System.out.println("----------");
         if (mSpans != null) {
-            Iterator iter = mSpans.iterator();
+            Iterator<Span> iter = mSpans.iterator();
             while (iter.hasNext()) {
-                Span span = (Span) iter.next();
+                Span span = iter.next();
                 System.out.println(span);
             }
         }
@@ -216,7 +216,7 @@
     /**
      * Holds a single half-open interval.
      */
-    static class Span implements Comparable {
+    static class Span implements Comparable<Span> {
 
         /**
          * The span includes the starting point.
@@ -315,8 +315,7 @@
          * position. The end position is ignored
          * in this ranking.
          */
-        public int compareTo(Object o) {
-            Span otherSpan = (Span) o;
+        public int compareTo(Span otherSpan) {
             float otherStart = otherSpan.getStart();
             int result;
 
@@ -345,7 +344,7 @@
      * <code>SpanIntersection.instance</code> to
      * get the single instance of this class.
      */
-    static class SpanIntersection implements Comparator {
+    static class SpanIntersection implements Comparator<Span> {
 
         /**
          * This class is a Singleton and the following
@@ -361,10 +360,8 @@
 
         }
 
-        public int compare(Object o1, Object o2) {
+        public int compare(Span span1, Span span2) {
             int result;
-            Span span1 = (Span) o1;
-            Span span2 = (Span) o2;
 
             /* Span 1 is entirely to the left of span2.
              * span1:   <-----<
--- a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java	Fri Apr 18 09:56:34 2014 -0700
@@ -1430,8 +1430,11 @@
         }
     }
 
-    RenderingHints makeHints(Map hints) {
-        RenderingHints model = new RenderingHints(hints);
+    RenderingHints makeHints(Map<?,?> hints) {
+        RenderingHints model = new RenderingHints(null);
+        if (hints != null) {
+            model.putAll(hints);
+        }
         model.put(SunHints.KEY_RENDERING,
                   SunHints.Value.get(SunHints.INTKEY_RENDERING,
                                      renderHint));
--- a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Fri Apr 18 09:56:34 2014 -0700
@@ -82,7 +82,7 @@
 
     public SunGraphicsEnvironment() {
         java.security.AccessController.doPrivileged(
-                                    new java.security.PrivilegedAction() {
+                                    new java.security.PrivilegedAction<Object>() {
             public Object run() {
                     String version = System.getProperty("os.version", "0.0");
                     try {
--- a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java	Fri Apr 18 09:56:34 2014 -0700
@@ -189,7 +189,7 @@
                                            LCMSImageLayout dest);
     public static native void freeTransform(long ID);
 
-    public static native void initLCMS(Class Trans, Class IL, Class Pf);
+    public static native void initLCMS(Class<?> Trans, Class<?> IL, Class<?> Pf);
 
     private LCMS() {};
 
@@ -201,7 +201,7 @@
         }
 
         java.security.AccessController.doPrivileged(
-                new java.security.PrivilegedAction() {
+                new java.security.PrivilegedAction<Object>() {
                     public Object run() {
                         /* We need to load awt here because of usage trace and
                          * disposer frameworks
--- a/jdk/src/share/classes/sun/java2d/loops/Blit.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/Blit.java	Fri Apr 18 09:56:34 2014 -0700
@@ -217,8 +217,8 @@
         Blit performop;
         Blit convertresult;
 
-        WeakReference srcTmp;
-        WeakReference dstTmp;
+        WeakReference<SurfaceData> srcTmp;
+        WeakReference<SurfaceData> dstTmp;
 
         public GeneralXorBlit(SurfaceType srctype,
                               CompositeType comptype,
@@ -257,14 +257,14 @@
             } else {
                 SurfaceData cachedSrc = null;
                 if (srcTmp != null) {
-                    cachedSrc = (SurfaceData) srcTmp.get();
+                    cachedSrc = srcTmp.get();
                 }
                 src = convertFrom(convertsrc, srcData, srcx, srcy,
                                   width, height, cachedSrc);
                 sx = 0;
                 sy = 0;
                 if (src != cachedSrc) {
-                    srcTmp = new WeakReference(src);
+                    srcTmp = new WeakReference<>(src);
                 }
             }
 
@@ -277,7 +277,7 @@
                 // assert: convertresult != null
                 SurfaceData cachedDst = null;
                 if (dstTmp != null) {
-                    cachedDst = (SurfaceData) dstTmp.get();
+                    cachedDst = dstTmp.get();
                 }
                 dst = convertFrom(convertdst, dstData, dstx, dsty,
                                   width, height, cachedDst);
@@ -285,7 +285,7 @@
                 dy = 0;
                 opclip = null;
                 if (dst != cachedDst) {
-                    dstTmp = new WeakReference(dst);
+                    dstTmp = new WeakReference<>(dst);
                 }
             }
 
--- a/jdk/src/share/classes/sun/java2d/loops/CustomComponent.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/CustomComponent.java	Fri Apr 18 09:56:34 2014 -0700
@@ -50,7 +50,7 @@
     public static void register() {
         // REMIND: This does not work for all destinations yet since
         // the screen SurfaceData objects do not implement getRaster
-        Class owner = CustomComponent.class;
+        Class<?> owner = CustomComponent.class;
         GraphicsPrimitive[] primitives = {
             new GraphicsPrimitiveProxy(owner, "OpaqueCopyAnyToArgb",
                                        Blit.methodSignature,
--- a/jdk/src/share/classes/sun/java2d/loops/GeneralRenderer.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/GeneralRenderer.java	Fri Apr 18 09:56:34 2014 -0700
@@ -50,7 +50,7 @@
 
 public final class GeneralRenderer {
     public static void register() {
-        Class owner = GeneralRenderer.class;
+        Class<?> owner = GeneralRenderer.class;
         GraphicsPrimitive[] primitives = {
             new  GraphicsPrimitiveProxy(owner, "SetFillRectANY",
                                         FillRect.methodSignature,
--- a/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitive.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitive.java	Fri Apr 18 09:56:34 2014 -0700
@@ -316,7 +316,7 @@
 
     public abstract GraphicsPrimitive traceWrap();
 
-    static HashMap traceMap;
+    static HashMap<Object, int[]> traceMap;
 
     public static int traceflags;
     public static String tracefile;
@@ -427,13 +427,14 @@
 
         public void run() {
             PrintStream ps = getTraceOutputFile();
-            Iterator iterator = traceMap.entrySet().iterator();
+            Iterator<Map.Entry<Object, int[]>> iterator =
+                traceMap.entrySet().iterator();
             long total = 0;
             int numprims = 0;
             while (iterator.hasNext()) {
-                Map.Entry me = (Map.Entry) iterator.next();
+                Map.Entry<Object, int[]> me = iterator.next();
                 Object prim = me.getKey();
-                int[] count = (int[]) me.getValue();
+                int[] count = me.getValue();
                 if (count[0] == 1) {
                     ps.print("1 call to ");
                 } else {
@@ -455,15 +456,15 @@
     public synchronized static void tracePrimitive(Object prim) {
         if ((traceflags & TRACECOUNTS) != 0) {
             if (traceMap == null) {
-                traceMap = new HashMap();
+                traceMap = new HashMap<>();
                 TraceReporter.setShutdownHook();
             }
-            Object o = traceMap.get(prim);
+            int[] o = traceMap.get(prim);
             if (o == null) {
                 o = new int[1];
                 traceMap.put(prim, o);
             }
-            ((int[]) o)[0]++;
+            o[0]++;
         }
         if ((traceflags & TRACELOG) != 0) {
             PrintStream ps = getTraceOutputFile();
--- a/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveMgr.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveMgr.java	Fri Apr 18 09:56:34 2014 -0700
@@ -45,11 +45,11 @@
     private static GraphicsPrimitive generalPrimitives[];
     private static boolean needssort = true;
 
-    private static native void initIDs(Class GP, Class ST, Class CT,
-                                       Class SG2D, Class Color, Class AT,
-                                       Class XORComp, Class AlphaComp,
-                                       Class Path2D, Class Path2DFloat,
-                                       Class SHints);
+    private static native void initIDs(Class<?> GP, Class<?> ST, Class<?> CT,
+                                       Class<?> SG2D, Class<?> Color, Class<?> AT,
+                                       Class<?> XORComp, Class<?> AlphaComp,
+                                       Class<?> Path2D, Class<?> Path2DFloat,
+                                       Class<?> SHints);
     private static native void registerNativeLoops();
 
     static {
@@ -73,16 +73,17 @@
         public int uniqueID;
     }
 
-    private static Comparator primSorter = new Comparator() {
-        public int compare(Object o1, Object o2) {
-            int id1 = ((GraphicsPrimitive) o1).getUniqueID();
-            int id2 = ((GraphicsPrimitive) o2).getUniqueID();
+    private static Comparator<GraphicsPrimitive> primSorter =
+            new Comparator<GraphicsPrimitive>() {
+        public int compare(GraphicsPrimitive o1, GraphicsPrimitive o2) {
+            int id1 = o1.getUniqueID();
+            int id2 = o2.getUniqueID();
 
             return (id1 == id2 ? 0 : (id1 < id2 ? -1 : 1));
         }
     };
 
-    private static Comparator primFinder = new Comparator() {
+    private static Comparator<Object> primFinder = new Comparator<Object>() {
         public int compare(Object o1, Object o2) {
             int id1 = ((GraphicsPrimitive) o1).getUniqueID();
             int id2 = ((PrimitiveSpec) o2).uniqueID;
--- a/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java	Fri Apr 18 09:56:34 2014 -0700
@@ -41,7 +41,7 @@
  */
 public class GraphicsPrimitiveProxy extends GraphicsPrimitive {
 
-    private Class owner;
+    private Class<?> owner;
     private String relativeClassName;
 
     /**
@@ -53,7 +53,7 @@
      * @param relativeClassName  The name of the class this is a proxy for.
      *          This should not include the package.
      */
-    public GraphicsPrimitiveProxy(Class owner, String relativeClassName,
+    public GraphicsPrimitiveProxy(Class<?> owner, String relativeClassName,
                                   String methodSignature,
                                   int primID,
                                   SurfaceType srctype,
@@ -80,7 +80,7 @@
         String name = getPackageName(owner.getName()) + "."
                         + relativeClassName;
         try {
-            Class clazz = Class.forName(name);
+            Class<?> clazz = Class.forName(name);
             GraphicsPrimitive p = (GraphicsPrimitive) clazz.newInstance();
             if (!satisfiesSameAs(p)) {
                 throw new RuntimeException("Primitive " + p
--- a/jdk/src/share/classes/sun/java2d/loops/MaskBlit.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/loops/MaskBlit.java	Fri Apr 18 09:56:34 2014 -0700
@@ -143,8 +143,8 @@
         MaskBlit performop;
         Blit convertresult;
 
-        WeakReference srcTmp;
-        WeakReference dstTmp;
+        WeakReference<SurfaceData> srcTmp;
+        WeakReference<SurfaceData> dstTmp;
 
         public General(SurfaceType srctype,
                        CompositeType comptype,
@@ -184,14 +184,14 @@
             } else {
                 SurfaceData cachedSrc = null;
                 if (srcTmp != null) {
-                    cachedSrc = (SurfaceData) srcTmp.get();
+                    cachedSrc = srcTmp.get();
                 }
                 src = convertFrom(convertsrc, srcData, srcx, srcy,
                                   width, height, cachedSrc);
                 sx = 0;
                 sy = 0;
                 if (src != cachedSrc) {
-                    srcTmp = new WeakReference(src);
+                    srcTmp = new WeakReference<>(src);
                 }
             }
 
@@ -204,7 +204,7 @@
                 // assert: convertresult != null
                 SurfaceData cachedDst = null;
                 if (dstTmp != null) {
-                    cachedDst = (SurfaceData) dstTmp.get();
+                    cachedDst = dstTmp.get();
                 }
                 dst = convertFrom(convertdst, dstData, dstx, dsty,
                                   width, height, cachedDst);
@@ -212,7 +212,7 @@
                 dy = 0;
                 opclip = null;
                 if (dst != cachedDst) {
-                    dstTmp = new WeakReference(dst);
+                    dstTmp = new WeakReference<>(dst);
                 }
             }
 
--- a/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java	Fri Apr 18 09:56:34 2014 -0700
@@ -728,7 +728,7 @@
 class OGLGeneralBlit extends Blit {
 
     private Blit performop;
-    private WeakReference srcTmp;
+    private WeakReference<SurfaceData> srcTmp;
 
     OGLGeneralBlit(SurfaceType dstType,
                    CompositeType compType,
@@ -750,7 +750,7 @@
         SurfaceData cachedSrc = null;
         if (srcTmp != null) {
             // use cached intermediate surface, if available
-            cachedSrc = (SurfaceData)srcTmp.get();
+            cachedSrc = srcTmp.get();
         }
 
         // convert source to IntArgbPre
@@ -763,7 +763,7 @@
 
         if (src != cachedSrc) {
             // cache the intermediate surface
-            srcTmp = new WeakReference(src);
+            srcTmp = new WeakReference<>(src);
         }
     }
 }
@@ -802,7 +802,7 @@
 
         if (dstBuffer != cachedDst) {
             // cache the intermediate surface
-            dstTmp = new WeakReference(dstBuffer);
+            dstTmp = new WeakReference<>(dstBuffer);
         }
 
         // now blit the buffer back to the destination
--- a/jdk/src/share/classes/sun/java2d/pipe/AlphaPaintPipe.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/AlphaPaintPipe.java	Fri Apr 18 09:56:34 2014 -0700
@@ -48,16 +48,16 @@
  * SunGraphics2D.
  */
 public class AlphaPaintPipe implements CompositePipe {
-    static WeakReference cachedLastRaster;
-    static WeakReference cachedLastColorModel;
-    static WeakReference cachedLastData;
+    static WeakReference<Raster> cachedLastRaster;
+    static WeakReference<ColorModel> cachedLastColorModel;
+    static WeakReference<SurfaceData> cachedLastData;
 
     static class TileContext {
         SunGraphics2D sunG2D;
         PaintContext paintCtxt;
         ColorModel paintModel;
-        WeakReference lastRaster;
-        WeakReference lastData;
+        WeakReference<Raster> lastRaster;
+        WeakReference<SurfaceData> lastData;
         MaskBlit lastMask;
         Blit     lastBlit;
         SurfaceData dstData;
@@ -105,8 +105,8 @@
         SurfaceData srcData = null;
         Raster lastRas = null;
         if (context.lastData != null && context.lastRaster != null) {
-            srcData = (SurfaceData) context.lastData.get();
-            lastRas = (Raster) context.lastRaster.get();
+            srcData = context.lastData.get();
+            lastRas = context.lastRaster.get();
             if (srcData == null || lastRas == null) {
                 srcData = null;
                 lastRas = null;
@@ -127,7 +127,7 @@
                 }
                 if (lastRas != srcRaster) {
                     lastRas = srcRaster;
-                    context.lastRaster = new WeakReference(lastRas);
+                    context.lastRaster = new WeakReference<>(lastRas);
                     // REMIND: This will fail for a non-Writable raster!
                     BufferedImage bImg =
                         new BufferedImage(paintModel,
@@ -135,7 +135,7 @@
                                           paintModel.isAlphaPremultiplied(),
                                           null);
                     srcData = BufImgSurfaceData.createData(bImg);
-                    context.lastData = new WeakReference(srcData);
+                    context.lastData = new WeakReference<>(srcData);
                     context.lastMask = null;
                     context.lastBlit = null;
                 }
@@ -197,7 +197,7 @@
                 {
                     // Avoid creating new WeakReference if possible
                     cachedLastColorModel =
-                        new WeakReference(context.paintModel);
+                        new WeakReference<>(context.paintModel);
                 }
                 cachedLastData = context.lastData;
             }
--- a/jdk/src/share/classes/sun/java2d/pipe/RenderQueue.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/RenderQueue.java	Fri Apr 18 09:56:34 2014 -0700
@@ -81,10 +81,10 @@
      * A Set containing hard references to Objects that must stay alive until
      * the queue has been completely flushed.
      */
-    protected Set refSet;
+    protected Set<Object> refSet;
 
     protected RenderQueue() {
-        refSet = new HashSet();
+        refSet = new HashSet<>();
         buf = RenderBuffer.allocate(BUFFER_SIZE);
     }
 
--- a/jdk/src/share/classes/sun/java2d/pipe/SpanClipRenderer.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/SpanClipRenderer.java	Fri Apr 18 09:56:34 2014 -0700
@@ -39,14 +39,14 @@
 {
     CompositePipe outpipe;
 
-    static Class RegionClass = Region.class;
-    static Class RegionIteratorClass = RegionIterator.class;
+    static Class<?> RegionClass = Region.class;
+    static Class<?> RegionIteratorClass = RegionIterator.class;
 
     static {
         initIDs(RegionClass, RegionIteratorClass);
     }
 
-    static native void initIDs(Class rc, Class ric);
+    static native void initIDs(Class<?> rc, Class<?> ric);
 
     public SpanClipRenderer(CompositePipe pipe) {
         outpipe = pipe;
--- a/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Fri Apr 18 20:10:39 2014 +0400
+++ b/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Fri Apr 18 09:56:34 2014 -0700
@@ -72,7 +72,7 @@
 
     protected int depth;
 
-    private static native void initIDs(Class xorComp, boolean tryDGA);
+    private static native void initIDs(Class<?> xorComp, boolean tryDGA);
     protected native void initSurface(int depth, int width, int height,
                                       long drawable);