From 0d8719b0ff9aacb7cdd8a238b8060540d4d00eff Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 17 Apr 2013 15:10:06 +0200 Subject: 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 Reviewed-on: https://gerrit.libreoffice.org/3433 Reviewed-by: Fridrich Strba Tested-by: Fridrich Strba --- forms/qa/integration/forms/DocumentHelper.java | 4 ++-- forms/qa/integration/forms/DocumentViewHelper.java | 10 +++++----- forms/qa/integration/forms/FormComponent.java | 2 +- forms/qa/integration/forms/ListSelection.java | 6 +++--- forms/qa/integration/forms/MasterDetailForms.java | 2 +- forms/qa/integration/forms/TestCase.java | 4 ++-- .../DevelopersGuide/OfficeDev/ContextMenuInterceptor.java | 4 ++-- odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java | 8 ++++---- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/forms/qa/integration/forms/DocumentHelper.java b/forms/qa/integration/forms/DocumentHelper.java index a26434b1931c..a5a44be9bb41 100644 --- a/forms/qa/integration/forms/DocumentHelper.java +++ b/forms/qa/integration/forms/DocumentHelper.java @@ -133,12 +133,12 @@ public class DocumentHelper /* ------------------------------------------------------------------ */ public boolean isModified() { - XModifiable modify = (XModifiable)query( XModifiable.class ); + XModifiable modify = query( XModifiable.class ); return modify.isModified(); } /* ------------------------------------------------------------------ */ - public Object query( Class aInterfaceClass ) + public T query( Class aInterfaceClass ) { return UnoRuntime.queryInterface( aInterfaceClass, m_documentComponent ); } diff --git a/forms/qa/integration/forms/DocumentViewHelper.java b/forms/qa/integration/forms/DocumentViewHelper.java index 66d8f0bf667a..76a03d0e16a2 100644 --- a/forms/qa/integration/forms/DocumentViewHelper.java +++ b/forms/qa/integration/forms/DocumentViewHelper.java @@ -73,7 +73,7 @@ public class DocumentViewHelper @param aInterfaceClass the class of the interface which shall be returned */ - public Object query( Class aInterfaceClass ) + public T query( Class aInterfaceClass ) { return UnoRuntime.queryInterface( aInterfaceClass, m_controller ); } @@ -92,7 +92,7 @@ public class DocumentViewHelper 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 class DocumentViewHelper 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 class DocumentViewHelper } /* ------------------------------------------------------------------ */ - public Object getControl( Object aModel, Class aInterfaceClass ) throws com.sun.star.uno.Exception + public T getControl( Object aModel, Class 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 class DocumentViewHelper */ 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 f19ceea87b9d..d6ea10d3bb6e 100644 --- a/forms/qa/integration/forms/FormComponent.java +++ b/forms/qa/integration/forms/FormComponent.java @@ -79,7 +79,7 @@ public class FormComponent @param aInterfaceClass the class of the interface which shall be returned */ - public Object query( Class aInterfaceClass ) + public T query( Class aInterfaceClass ) { return UnoRuntime.queryInterface( aInterfaceClass, m_component ); } diff --git a/forms/qa/integration/forms/ListSelection.java b/forms/qa/integration/forms/ListSelection.java index 5d080cb7691c..64fef4894987 100644 --- a/forms/qa/integration/forms/ListSelection.java +++ b/forms/qa/integration/forms/ListSelection.java @@ -96,7 +96,7 @@ public class ListSelection extends integration.forms.TestCase 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 @@ public class ListSelection extends integration.forms.TestCase 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 @@ public class ListSelection extends integration.forms.TestCase 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 d55263b94cad..dd2a09e62dee 100644 --- a/forms/qa/integration/forms/MasterDetailForms.java +++ b/forms/qa/integration/forms/MasterDetailForms.java @@ -288,7 +288,7 @@ public class MasterDetailForms extends complexlib.ComplexTestCase implements com 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 54f5b1ff8abd..85e1d16ac91f 100644 --- a/forms/qa/integration/forms/TestCase.java +++ b/forms/qa/integration/forms/TestCase.java @@ -62,7 +62,7 @@ public abstract class TestCase extends complexlib.ComplexTestCase implements com 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 @@ public abstract class TestCase extends complexlib.ComplexTestCase implements com // 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 67d0331b2c29..608ad199c065 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java +++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java @@ -52,8 +52,8 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { 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 1efa20c4fc1b..47bf1bb74b04 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java +++ b/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java @@ -107,9 +107,9 @@ public class OfficeConnect * @param sServiceSpecifier name of service which should be created * @return Description of the Returned Value */ - public Object createRemoteInstance(Class aType, String sServiceSpecifier) + public T createRemoteInstance(Class aType, String sServiceSpecifier) { - Object aResult = null; + T aResult = null; try { aResult = UnoRuntime.queryInterface( @@ -136,9 +136,9 @@ public class OfficeConnect * @param sServiceSpecifier Description of Parameter * @return Description of the Returned Value */ - public Object createRemoteInstanceWithArguments(Class aType, String sServiceSpecifier, Any[] lArguments) + public T createRemoteInstanceWithArguments(Class aType, String sServiceSpecifier, Any[] lArguments) { - Object aResult = null; + T aResult = null; try { aResult = UnoRuntime.queryInterface( -- cgit v1.2.3