Bug 714874 - Fix Java warnings about redundant casts. r=pcwalton r=dougt a=dougt
authorChris Peterson <cpeterson@mozilla.com>
Fri, 06 Jan 2012 12:21:49 -0800
changeset 85218 16f5cf776059a57038a46b9868819c9edddda331
parent 85217 c00505771db1342ceef5b9e80deb5e1fbc9d64b2
child 85219 a79e588b6fbdc781538b2f508d2e242c9dec52bb
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton, dougt, dougt
bugs714874
milestone12.0a1
Bug 714874 - Fix Java warnings about redundant casts. r=pcwalton r=dougt a=dougt
mobile/android/base/AwesomeBar.java
mobile/android/base/AwesomeBarTabs.java
mobile/android/base/GeckoApp.java
mobile/android/base/gfx/IntSize.java
mobile/android/base/gfx/LayerRenderer.java
mobile/android/base/gfx/PointUtils.java
mobile/android/base/gfx/RectUtils.java
mobile/android/base/gfx/ScrollbarLayer.java
mobile/android/base/gfx/SingleTileLayer.java
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -434,17 +434,17 @@ public class AwesomeBar extends Activity
             return false;
 
         String url = "";
         byte[] b = null;
         String title = "";
         if (mContextMenuSubject instanceof Cursor) {
             Cursor cursor = (Cursor)mContextMenuSubject;
             url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
-            b = (byte[]) cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
+            b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
             title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
         } else if (mContextMenuSubject instanceof Map) {
             Map map = (Map)mContextMenuSubject;
             url = (String)map.get(URLColumns.URL);
             b = (byte[]) map.get(URLColumns.FAVICON);
             title = (String)map.get(URLColumns.TITLE);
         } else {
             return false;
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -474,18 +474,17 @@ public class AwesomeBarTabs extends TabH
         }
 
         private Drawable getDrawableFromDataURI(String dataURI) {
             String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
             Drawable drawable = null;
             try {
                 byte[] bytes = Base64.decode(base64, Base64.DEFAULT);
                 ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
-                drawable = (Drawable) Drawable.createFromStream(stream, "src");
-            
+                drawable = Drawable.createFromStream(stream, "src");
                 stream.close();
             } catch (IllegalArgumentException e) {
                 Log.i(LOGTAG, "exception while decoding drawable: " + base64, e);
             } catch (IOException e) { }
             return drawable;
         }
 
         private void bindSearchEngineView(int position, View view) {
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2369,20 +2369,20 @@ class PluginLayoutParams extends Absolut
         mOriginalWidth = aWidth;
         mOriginalHeight = aHeight;
         mLastResolution = mOriginalResolution = aResolution;
 
         clampToMaxSize();
     }
 
     public static PluginLayoutParams create(int aX, int aY, int aWidth, int aHeight, float aResolution) {
-        aX = (int)Math.round(aX * aResolution);
-        aY = (int)Math.round(aY * aResolution);
-        aWidth = (int)Math.round(aWidth * aResolution);
-        aHeight = (int)Math.round(aHeight * aResolution);
+        aX = Math.round(aX * aResolution);
+        aY = Math.round(aY * aResolution);
+        aWidth = Math.round(aWidth * aResolution);
+        aHeight = Math.round(aHeight * aResolution);
 
         return new PluginLayoutParams(aX, aY, aWidth, aHeight, aResolution);
     }
 
     private void clampToMaxSize() {
         if (width > MAX_DIMENSION || height > MAX_DIMENSION) {
             if (width > height) {
                 height = (int)(((float)height/(float)width) * MAX_DIMENSION);
@@ -2390,44 +2390,44 @@ class PluginLayoutParams extends Absolut
             } else {
                 width = (int)(((float)width/(float)height) * MAX_DIMENSION);
                 height = MAX_DIMENSION;
             }
         }
     }
 
     public void reset(int aX, int aY, int aWidth, int aHeight, float aResolution) {
-        x = mOriginalX = (int)Math.round(aX * aResolution);
-        y = mOriginalY = (int)Math.round(aY * aResolution);
-        width = mOriginalWidth = (int)Math.round(aWidth * aResolution);
-        height = mOriginalHeight = (int)Math.round(aHeight * aResolution);
+        x = mOriginalX = Math.round(aX * aResolution);
+        y = mOriginalY = Math.round(aY * aResolution);
+        width = mOriginalWidth = Math.round(aWidth * aResolution);
+        height = mOriginalHeight = Math.round(aHeight * aResolution);
         mLastResolution = mOriginalResolution = aResolution;
 
         clampToMaxSize();
 
         Log.i(LOGTAG, "Resetting plugin to " + x + ", " + y + ", " + width + "x" + height + ", (" + (aResolution * 100) + "%)");
     }
 
     private void reposition(Point aOffset, float aResolution) {
         Log.i(LOGTAG, "Repositioning plugin by " + aOffset.x + ", " + aOffset.y + ", (" + (aResolution * 100) + "%)");
         x = mOriginalX + aOffset.x;
         y = mOriginalY + aOffset.y;
 
         if (!FloatUtils.fuzzyEquals(mLastResolution, aResolution)) {
             float scaleFactor = aResolution / mOriginalResolution;
-            width = (int)Math.round(scaleFactor * mOriginalWidth);
-            height = (int)Math.round(scaleFactor * mOriginalHeight);
+            width = Math.round(scaleFactor * mOriginalWidth);
+            height = Math.round(scaleFactor * mOriginalHeight);
             mLastResolution = aResolution;
 
             clampToMaxSize();
         }
     }
 
     public void reposition(ViewportMetrics hostViewport, ViewportMetrics targetViewport) {
         PointF targetOrigin = targetViewport.getOrigin();
         PointF hostOrigin = hostViewport.getOrigin();
 
-        Point offset = new Point((int)Math.round(hostOrigin.x - targetOrigin.x),
-                                 (int)Math.round(hostOrigin.y - targetOrigin.y));
+        Point offset = new Point(Math.round(hostOrigin.x - targetOrigin.x),
+                                 Math.round(hostOrigin.y - targetOrigin.y));
 
         reposition(offset, hostViewport.getZoomFactor());
     }
 }
--- a/mobile/android/base/gfx/IntSize.java
+++ b/mobile/android/base/gfx/IntSize.java
@@ -73,18 +73,18 @@ public class IntSize {
     public boolean isPositive() {
         return (width > 0 && height > 0);
     }
 
     @Override
     public String toString() { return "(" + width + "," + height + ")"; }
 
     public IntSize scale(float factor) {
-        return new IntSize((int)Math.round(width * factor),
-                           (int)Math.round(height * factor));
+        return new IntSize(Math.round(width * factor),
+                           Math.round(height * factor));
     }
 
     /* Returns the power of two that is greater than or equal to value */
     public static int nextPowerOfTwo(int value) {
         // code taken from http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
         if (0 == value--) {
             return 1;
         }
--- a/mobile/android/base/gfx/LayerRenderer.java
+++ b/mobile/android/base/gfx/LayerRenderer.java
@@ -292,17 +292,17 @@ public class LayerRenderer implements GL
         int frameElapsedTime = (int)(SystemClock.uptimeMillis() - frameStartTime);
 
         /* Update the running statistics. */
         mFrameTimingsSum -= mFrameTimings[mCurrentFrame];
         mFrameTimingsSum += frameElapsedTime;
         mDroppedFrames -= (mFrameTimings[mCurrentFrame] + 1) / MAX_FRAME_TIME;
         mDroppedFrames += (frameElapsedTime + 1) / MAX_FRAME_TIME;
 
-        mFrameTimings[mCurrentFrame] = (int)frameElapsedTime;
+        mFrameTimings[mCurrentFrame] = frameElapsedTime;
         mCurrentFrame = (mCurrentFrame + 1) % mFrameTimings.length;
 
         int averageTime = mFrameTimingsSum / mFrameTimings.length;
 
         mFrameRateLayer.beginTransaction();
         try {
             mFrameRateLayer.setText(averageTime + " ms/" + mDroppedFrames);
         } finally {
--- a/mobile/android/base/gfx/PointUtils.java
+++ b/mobile/android/base/gfx/PointUtils.java
@@ -32,19 +32,23 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko.gfx;
 
-import org.mozilla.gecko.FloatUtils;
 import android.graphics.Point;
 import android.graphics.PointF;
+
+import org.json.JSONObject;
+import org.json.JSONException;
+import org.mozilla.gecko.FloatUtils;
+
 import java.lang.Math;
 
 public final class PointUtils {
     public static PointF add(PointF one, PointF two) {
         return new PointF(one.x + two.x, one.y + two.y);
     }
 
     public static PointF subtract(PointF one, PointF two) {
@@ -67,10 +71,20 @@ public final class PointUtils {
        float y = FloatUtils.interpolate(startPoint.y, endPoint.y, weight);
        return new PointF(x, y);
    }
 
    /* Computes the magnitude of the given vector. */
    public static float distance(PointF point) {
         return (float)Math.sqrt(point.x * point.x + point.y * point.y);
    }
+
+    public static JSONObject toJSON(PointF point) throws JSONException {
+        // Ensure we put ints, not longs, because Gecko message handlers call getInt().
+        int x = Math.round(point.x);
+        int y = Math.round(point.y);
+        JSONObject json = new JSONObject();
+        json.put("x", x);
+        json.put("y", y);
+        return json;
+    }
 }
 
--- a/mobile/android/base/gfx/RectUtils.java
+++ b/mobile/android/base/gfx/RectUtils.java
@@ -52,22 +52,22 @@ public final class RectUtils {
             int height = json.getInt("height");
             return new Rect(x, y, x + width, y + height);
         } catch (JSONException e) {
             throw new RuntimeException(e);
         }
     }
 
     public static Rect contract(Rect rect, int lessWidth, int lessHeight) {
-        float halfLessWidth = (float)lessWidth / 2.0f;
-        float halfLessHeight = (float)lessHeight / 2.0f;
-        return new Rect((int)Math.round((float)rect.left + halfLessWidth),
-                        (int)Math.round((float)rect.top + halfLessHeight),
-                        (int)Math.round((float)rect.right - halfLessWidth),
-                        (int)Math.round((float)rect.bottom - halfLessHeight));
+        float halfLessWidth = lessWidth / 2.0f;
+        float halfLessHeight = lessHeight / 2.0f;
+        return new Rect(Math.round(rect.left + halfLessWidth),
+                        Math.round(rect.top + halfLessHeight),
+                        Math.round(rect.right - halfLessWidth),
+                        Math.round(rect.bottom - halfLessHeight));
     }
 
     public static RectF contract(RectF rect, float lessWidth, float lessHeight) {
         float halfLessWidth = lessWidth / 2;
         float halfLessHeight = lessHeight / 2;
         return new RectF(rect.left + halfLessWidth,
                          rect.top + halfLessHeight,
                          rect.right - halfLessWidth,
--- a/mobile/android/base/gfx/ScrollbarLayer.java
+++ b/mobile/android/base/gfx/ScrollbarLayer.java
@@ -147,17 +147,17 @@ public class ScrollbarLayer extends Tile
 
     private void setOpacity(float opacity) {
         mOpacity = opacity;
 
         Paint foregroundPaint = new Paint();
         foregroundPaint.setAntiAlias(true);
         foregroundPaint.setStyle(Paint.Style.FILL);
         // use a (a,r,g,b) color of (127,0,0,0), and multiply the alpha by mOpacity for fading
-        foregroundPaint.setColor(Color.argb((int)Math.round(mOpacity * 127), 0, 0, 0));
+        foregroundPaint.setColor(Color.argb(Math.round(mOpacity * 127), 0, 0, 0));
 
         mCanvas.drawColor(Color.argb(0, 0, 0, 0), PorterDuff.Mode.CLEAR);
         mCanvas.drawCircle(CAP_RADIUS, CAP_RADIUS, CAP_RADIUS, foregroundPaint);
 
         mBitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
     }
 
     @Override
--- a/mobile/android/base/gfx/SingleTileLayer.java
+++ b/mobile/android/base/gfx/SingleTileLayer.java
@@ -75,18 +75,18 @@ public class SingleTileLayer extends Til
 
         RectF bounds;
         int[] cropRect;
         IntSize size = getSize();
         RectF viewport = context.viewport;
 
         if (repeats()) {
             bounds = new RectF(0.0f, 0.0f, viewport.width(), viewport.height());
-            int width = (int)Math.round(viewport.width());
-            int height = (int)Math.round(-viewport.height());
+            int width = Math.round(viewport.width());
+            int height = Math.round(-viewport.height());
             cropRect = new int[] { 0, size.height, width, height };
         } else {
             bounds = getBounds(context, new FloatSize(size));
             cropRect = new int[] { 0, size.height, size.width, -size.height };
         }
 
         GLES11.glTexParameteriv(GL10.GL_TEXTURE_2D, GLES11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect,
                                 0);
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -37,17 +37,16 @@
 
 package org.mozilla.gecko.ui;
 
 import org.json.JSONObject;
 import org.json.JSONException;
 import org.mozilla.gecko.gfx.FloatSize;
 import org.mozilla.gecko.gfx.LayerController;
 import org.mozilla.gecko.gfx.PointUtils;
-import org.mozilla.gecko.gfx.RectUtils;
 import org.mozilla.gecko.gfx.ViewportMetrics;
 import org.mozilla.gecko.FloatUtils;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoEventListener;
 import android.graphics.PointF;
 import android.graphics.RectF;
@@ -902,21 +901,21 @@ public class PanZoomController
         /* First, we adjust the zoom factor so that we can make no overscrolled area visible. */
         float zoomFactor = viewportMetrics.getZoomFactor();
         FloatSize pageSize = viewportMetrics.getPageSize();
         RectF viewport = viewportMetrics.getViewport();
 
         float minZoomFactor = 0.0f;
         if (viewport.width() > pageSize.width && pageSize.width > 0) {
             float scaleFactor = viewport.width() / pageSize.width;
-            minZoomFactor = (float)Math.max(minZoomFactor, zoomFactor * scaleFactor);
+            minZoomFactor = Math.max(minZoomFactor, zoomFactor * scaleFactor);
         }
         if (viewport.height() > pageSize.height && pageSize.height > 0) {
             float scaleFactor = viewport.height() / pageSize.height;
-            minZoomFactor = (float)Math.max(minZoomFactor, zoomFactor * scaleFactor);
+            minZoomFactor = Math.max(minZoomFactor, zoomFactor * scaleFactor);
         }
 
         if (!FloatUtils.fuzzyEquals(minZoomFactor, 0.0f)) {
             PointF center = new PointF(viewport.width() / 2.0f, viewport.height() / 2.0f);
             viewportMetrics.scaleTo(minZoomFactor, center);
         } else if (zoomFactor > MAX_ZOOM) {
             PointF center = new PointF(viewport.width() / 2.0f, viewport.height() / 2.0f);
             viewportMetrics.scaleTo(MAX_ZOOM, center);
@@ -1032,91 +1031,88 @@ public class PanZoomController
         mState = PanZoomState.TOUCHING;
         mX.velocity = mY.velocity = 0.0f;
         mX.locked = mY.locked = false;
         mLastEventTime = detector.getEventTime();
     }
 
     @Override
     public void onLongPress(MotionEvent motionEvent) {
-        JSONObject ret = new JSONObject();
+        String json;
         try {
             PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
             point = mController.convertViewPointToLayerPoint(point);
             if (point == null) {
                 return;
             }
-            ret.put("x", (int)Math.round(point.x));
-            ret.put("y", (int)Math.round(point.y));
+            json = PointUtils.toJSON(point).toString();
         } catch(Exception ex) {
             Log.w(LOGTAG, "Error building return: " + ex);
+            return; // json would be null
         }
 
-        GeckoEvent e = new GeckoEvent("Gesture:LongPress", ret.toString());
+        GeckoEvent e = new GeckoEvent("Gesture:LongPress", json);
         GeckoAppShell.sendEventToGecko(e);
     }
 
     public boolean getRedrawHint() {
         return (mState == PanZoomState.NOTHING || mState == PanZoomState.FLING);
     }
 
     @Override
     public boolean onDown(MotionEvent motionEvent) {
-        JSONObject ret = new JSONObject();
+        String json;
         try {
             PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
             point = mController.convertViewPointToLayerPoint(point);
-            ret.put("x", (int)Math.round(point.x));
-            ret.put("y", (int)Math.round(point.y));
+            json = PointUtils.toJSON(point).toString();
         } catch(Exception ex) {
             throw new RuntimeException(ex);
         }
 
-        GeckoEvent e = new GeckoEvent("Gesture:ShowPress", ret.toString());
+        GeckoEvent e = new GeckoEvent("Gesture:ShowPress", json);
         GeckoAppShell.sendEventToGecko(e);
         return false;
     }
 
     @Override
     public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
-        JSONObject ret = new JSONObject();
+        String json;
         try {
             PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
             point = mController.convertViewPointToLayerPoint(point);
-            ret.put("x", (int)Math.round(point.x));
-            ret.put("y", (int)Math.round(point.y));
+            json = PointUtils.toJSON(point).toString();
         } catch(Exception ex) {
             throw new RuntimeException(ex);
         }
 
         GeckoApp.mAppContext.mAutoCompletePopup.hide();
 
-        GeckoEvent e = new GeckoEvent("Gesture:SingleTap", ret.toString());
+        GeckoEvent e = new GeckoEvent("Gesture:SingleTap", json);
         GeckoAppShell.sendEventToGecko(e);
         return true;
     }
 
     private void cancelTouch() {
         GeckoEvent e = new GeckoEvent("Gesture:CancelTouch", "");
         GeckoAppShell.sendEventToGecko(e);
     }
 
     @Override
     public boolean onDoubleTap(MotionEvent motionEvent) {
-        JSONObject ret = new JSONObject();
+        String json;
         try {
             PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
             point = mController.convertViewPointToLayerPoint(point);
-            ret.put("x", (int)Math.round(point.x));
-            ret.put("y", (int)Math.round(point.y));
+            json = PointUtils.toJSON(point).toString();
         } catch(Exception ex) {
             throw new RuntimeException(ex);
         }
 
-        GeckoEvent e = new GeckoEvent("Gesture:DoubleTap", ret.toString());
+        GeckoEvent e = new GeckoEvent("Gesture:DoubleTap", json);
         GeckoAppShell.sendEventToGecko(e);
         return true;
     }
 
     private boolean animatedZoomTo(RectF zoomToRect) {
         GeckoApp.mAppContext.hidePluginViews();
         GeckoApp.mAppContext.mAutoCompletePopup.hide();