Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3433

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/33/3433/1

Java cleanup, use generics in calls to UnoRuntime#queryInterface

A handful of places wrap the call to queryInterface. With a little
generics love, we can reduce the casting required.

Change-Id: I9efca2afb1b23fad2359af24e1c273aea96e45fe
---
M forms/qa/integration/forms/DocumentHelper.java
M forms/qa/integration/forms/DocumentViewHelper.java
M forms/qa/integration/forms/FormComponent.java
M forms/qa/integration/forms/ListSelection.java
M forms/qa/integration/forms/MasterDetailForms.java
M forms/qa/integration/forms/TestCase.java
M odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
M odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
8 files changed, 20 insertions(+), 20 deletions(-)



diff --git a/forms/qa/integration/forms/DocumentHelper.java 
b/forms/qa/integration/forms/DocumentHelper.java
index a26434b..a5a44be 100644
--- a/forms/qa/integration/forms/DocumentHelper.java
+++ b/forms/qa/integration/forms/DocumentHelper.java
@@ -133,12 +133,12 @@
     /* ------------------------------------------------------------------ */
     public boolean isModified()
     {
-        XModifiable modify = (XModifiable)query( XModifiable.class );
+        XModifiable modify = query( XModifiable.class );
         return modify.isModified();
     }
 
     /* ------------------------------------------------------------------ */
-    public Object query( Class aInterfaceClass )
+    public <T> T query( Class<T> aInterfaceClass )
     {
         return UnoRuntime.queryInterface( aInterfaceClass, m_documentComponent );
     }
diff --git a/forms/qa/integration/forms/DocumentViewHelper.java 
b/forms/qa/integration/forms/DocumentViewHelper.java
index 66d8f0b..76a03d0 100644
--- a/forms/qa/integration/forms/DocumentViewHelper.java
+++ b/forms/qa/integration/forms/DocumentViewHelper.java
@@ -73,7 +73,7 @@
         @param aInterfaceClass
                 the class of the interface which shall be returned
     */
-    public Object query( Class aInterfaceClass )
+    public <T> T query( Class<T> aInterfaceClass )
     {
         return UnoRuntime.queryInterface( aInterfaceClass, m_controller );
     }
@@ -92,7 +92,7 @@
         XDispatch xReturn = null;
 
         // go get the current view
-        XController xController = (XController)query( XController.class );
+        XController xController = query( XController.class );
         // go get the dispatch provider of it's frame
         XDispatchProvider xProvider = UnoRuntime.queryInterface(
             XDispatchProvider.class, xController.getFrame() );
@@ -147,7 +147,7 @@
     public XControl getControl( XControlModel xModel ) throws com.sun.star.uno.Exception
     {
         // the current view of the document
-        XControlAccess xCtrlAcc = (XControlAccess)query( XControlAccess.class );
+        XControlAccess xCtrlAcc = query( XControlAccess.class );
         // delegate the task of looking for the control
         return xCtrlAcc.getControl( xModel );
     }
@@ -160,7 +160,7 @@
     }
 
     /* ------------------------------------------------------------------ */
-    public Object getControl( Object aModel, Class aInterfaceClass ) throws 
com.sun.star.uno.Exception
+    public <T> T getControl( Object aModel, Class<T> aInterfaceClass ) throws 
com.sun.star.uno.Exception
     {
         XControlModel xModel = UnoRuntime.queryInterface( XControlModel.class, aModel );
         return UnoRuntime.queryInterface( aInterfaceClass, getControl( xModel ) );
@@ -171,7 +171,7 @@
      */
     public XFormController getFormController( XForm _form )
     {
-        XFormLayerAccess formLayerAccess = (XFormLayerAccess)query( XFormLayerAccess.class );
+        XFormLayerAccess formLayerAccess = query( XFormLayerAccess.class );
         return formLayerAccess.getFormController( _form );
     }
 
diff --git a/forms/qa/integration/forms/FormComponent.java 
b/forms/qa/integration/forms/FormComponent.java
index f19ceea..d6ea10d 100644
--- a/forms/qa/integration/forms/FormComponent.java
+++ b/forms/qa/integration/forms/FormComponent.java
@@ -79,7 +79,7 @@
         @param aInterfaceClass
                 the class of the interface which shall be returned
     */
-    public Object query( Class aInterfaceClass )
+    public <T> T query( Class<T> aInterfaceClass )
     {
         return UnoRuntime.queryInterface( aInterfaceClass, m_component );
     }
diff --git a/forms/qa/integration/forms/ListSelection.java 
b/forms/qa/integration/forms/ListSelection.java
index 5d080cb..64fef48 100644
--- a/forms/qa/integration/forms/ListSelection.java
+++ b/forms/qa/integration/forms/ListSelection.java
@@ -96,7 +96,7 @@
             for ( int i = 0; i < runs; ++i )
             {
                 // obtain the active sheet
-                XSpreadsheetView view = (XSpreadsheetView)m_document.getCurrentView().query( 
XSpreadsheetView.class );
+                XSpreadsheetView view = m_document.getCurrentView().query( XSpreadsheetView.class 
);
                 XSpreadsheet activeSheet = view.getActiveSheet();
 
                 // Accessibility access to the list box control in this sheet
@@ -259,7 +259,7 @@
 
         try
         {
-            XStorable storable = (XStorable)m_document.query( XStorable.class );
+            XStorable storable = m_document.query( XStorable.class );
             java.io.File testFile = java.io.File.createTempFile( getTestObjectName(),".ods");
             storable.storeAsURL( testFile.getAbsoluteFile().toURI().toURL().toString(), new 
com.sun.star.beans.PropertyValue[]{} );
             testFile.deleteOnExit();
@@ -277,7 +277,7 @@
         XDrawPageSupplier suppPage = UnoRuntime.queryInterface(
             XDrawPageSupplier.class, sheet );
         FormComponent formsRoot = new FormComponent( suppPage.getDrawPage() );
-        XControlModel listBoxModel = (XControlModel)formsRoot.getByIndex( 0 ).
+        XControlModel listBoxModel = formsRoot.getByIndex( 0 ).
             getByName( "ListBox" ).query( XControlModel.class );
         return listBoxModel;
     }
diff --git a/forms/qa/integration/forms/MasterDetailForms.java 
b/forms/qa/integration/forms/MasterDetailForms.java
index d55263b..dd2a09e 100644
--- a/forms/qa/integration/forms/MasterDetailForms.java
+++ b/forms/qa/integration/forms/MasterDetailForms.java
@@ -288,7 +288,7 @@
             assureEquals( "#i105235#: default value in sub form not working (not propagated to 
column model)", defaultValue, actualValue );
             // However, checking the column model's value alone is not enough - we need to ensure 
it is properly
             // propagated to the control.
-            XGridFieldDataSupplier gridData = 
(XGridFieldDataSupplier)subDocument.getCurrentView().getControl(
+            XGridFieldDataSupplier gridData = subDocument.getCurrentView().getControl(
                 gridControlModel, XGridFieldDataSupplier.class );
             actualValue = (String)(gridData.queryFieldData( 0, Type.STRING )[1]);
             assureEquals( "#i105235#: default value in sub form not working (not propagated to 
column)", defaultValue, actualValue );
diff --git a/forms/qa/integration/forms/TestCase.java b/forms/qa/integration/forms/TestCase.java
index 54f5b1f..85e1d16 100644
--- a/forms/qa/integration/forms/TestCase.java
+++ b/forms/qa/integration/forms/TestCase.java
@@ -62,7 +62,7 @@
             if ( m_document != null )
             {
                 // first, set the document to "unmodified"
-                XModifiable docModify = (XModifiable)m_document.query( XModifiable.class );
+                XModifiable docModify = m_document.query( XModifiable.class );
                 docModify.setModified( false );
 
                 m_document.getCurrentView().dispatch( ".uno:CloseDoc" );
@@ -87,7 +87,7 @@
             // close our document
             if ( m_document != null )
             {
-                XCloseable closeDoc = (XCloseable)m_document.query( XCloseable.class );
+                XCloseable closeDoc = m_document.query( XCloseable.class );
                 closeDoc.close( true );
             }
         }
diff --git a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java 
b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
index 67d0331..608ad19 100644
--- a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
+++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
@@ -52,8 +52,8 @@
             OfficeConnect aConnect = OfficeConnect.createConnection();
 
             com.sun.star.frame.XDesktop xDesktop =
-                (com.sun.star.frame.XDesktop)aConnect.createRemoteInstance(
-                    com.sun.star.frame.XDesktop.class,"com.sun.star.frame.Desktop");
+                aConnect.createRemoteInstance(
+                com.sun.star.frame.XDesktop.class,"com.sun.star.frame.Desktop");
 
             // create a new test document
             com.sun.star.frame.XComponentLoader xCompLoader =
diff --git a/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java 
b/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
index 1efa20c..47bf1bb 100644
--- a/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
+++ b/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
@@ -107,9 +107,9 @@
      * @param  sServiceSpecifier  name of service which should be created
      * @return                    Description of the Returned Value
      */
-    public Object createRemoteInstance(Class aType, String sServiceSpecifier)
+    public <T> T createRemoteInstance(Class<T> aType, String sServiceSpecifier)
     {
-        Object aResult = null;
+        T aResult = null;
         try
         {
             aResult = UnoRuntime.queryInterface(
@@ -136,9 +136,9 @@
      * @param  sServiceSpecifier  Description of Parameter
      * @return                    Description of the Returned Value
      */
-    public Object createRemoteInstanceWithArguments(Class aType, String sServiceSpecifier, Any[] 
lArguments)
+    public <T> T createRemoteInstanceWithArguments(Class<T> aType, String sServiceSpecifier, Any[] 
lArguments)
     {
-        Object aResult = null;
+        T aResult = null;
         try
         {
             aResult = UnoRuntime.queryInterface(

-- 
To view, visit https://gerrit.libreoffice.org/3433
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9efca2afb1b23fad2359af24e1c273aea96e45fe
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Noel Grandin <noelgrandin@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.