Java cleanup - use generics to reduce casting

More queryInterface related cleanup.

Change-Id: I97d064c425389e687c6f0fbc3a962080f46dd511
Reviewed-on: https://gerrit.libreoffice.org/3568
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
This commit is contained in:
Noel Grandin
2013-04-23 09:18:08 +02:00
committed by Fridrich Strba
parent ada0298167
commit bc8b419b0d
5 changed files with 16 additions and 16 deletions

View File

@@ -148,7 +148,7 @@ public class ButtonOperator implements XActionListener, XFeatureInvalidation
public void actionPerformed( ActionEvent aEvent ) throws com.sun.star.uno.RuntimeException public void actionPerformed( ActionEvent aEvent ) throws com.sun.star.uno.RuntimeException
{ {
// get the model's name // get the model's name
XPropertySet buttonModel = (XPropertySet)FLTools.getModel( aEvent.Source, XPropertySet.class ); XPropertySet buttonModel = FLTools.getModel( aEvent.Source, XPropertySet.class );
try try
{ {
short formFeature = getAssociatedFormFeature( buttonModel ); short formFeature = getAssociatedFormFeature( buttonModel );

View File

@@ -69,7 +69,7 @@ class DocumentViewHelper
@param aInterfaceClass @param aInterfaceClass
the class of the interface which shall be returned the class of the interface which shall be returned
*/ */
public Object get( Class aInterfaceClass ) public <T> T get( Class<T> aInterfaceClass )
{ {
return UnoRuntime.queryInterface( aInterfaceClass, m_controller ); return UnoRuntime.queryInterface( aInterfaceClass, m_controller );
} }
@@ -88,7 +88,7 @@ class DocumentViewHelper
XDispatch xReturn = null; XDispatch xReturn = null;
// go get the current view // go get the current view
XController xController = (XController)get( XController.class ); XController xController = get( XController.class );
// go get the dispatch provider of it's frame // go get the dispatch provider of it's frame
XDispatchProvider xProvider = UnoRuntime.queryInterface( XDispatchProvider xProvider = UnoRuntime.queryInterface(
XDispatchProvider.class, xController.getFrame() ); XDispatchProvider.class, xController.getFrame() );
@@ -119,7 +119,7 @@ class DocumentViewHelper
*/ */
public XFormController getFormController( Object _form ) public XFormController getFormController( Object _form )
{ {
XFormLayerAccess formLayer = (XFormLayerAccess)get( XFormLayerAccess.class ); XFormLayerAccess formLayer = get( XFormLayerAccess.class );
return formLayer.getFormController( UnoRuntime.queryInterface( XForm.class, _form ) ); return formLayer.getFormController( UnoRuntime.queryInterface( XForm.class, _form ) );
} }
@@ -133,7 +133,7 @@ class DocumentViewHelper
public XControl getFormControl( XControlModel xModel ) throws com.sun.star.uno.Exception public XControl getFormControl( XControlModel xModel ) throws com.sun.star.uno.Exception
{ {
// the current view of the document // the current view of the document
XControlAccess xCtrlAcc = (XControlAccess)get( XControlAccess.class ); XControlAccess xCtrlAcc = get( XControlAccess.class );
// delegate the task of looking for the control // delegate the task of looking for the control
return xCtrlAcc.getControl( xModel ); return xCtrlAcc.getControl( xModel );
} }
@@ -146,7 +146,7 @@ class DocumentViewHelper
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
public Object getFormControl( Object aModel, Class aInterfaceClass ) throws com.sun.star.uno.Exception public <T> T getFormControl( Object aModel, Class<T> aInterfaceClass ) throws com.sun.star.uno.Exception
{ {
XControlModel xModel = UnoRuntime.queryInterface( XControlModel.class, aModel ); XControlModel xModel = UnoRuntime.queryInterface( XControlModel.class, aModel );
return UnoRuntime.queryInterface( aInterfaceClass, getFormControl( xModel ) ); return UnoRuntime.queryInterface( aInterfaceClass, getFormControl( xModel ) );

View File

@@ -159,7 +159,7 @@ public class FLTools
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/** retrieves the parent of the given object /** retrieves the parent of the given object
*/ */
static Object getParent( Object aComponent, Class aInterfaceClass ) static <T> T getParent( Object aComponent, Class<T> aInterfaceClass )
{ {
XChild xAsChild = UnoRuntime.queryInterface( XChild.class, aComponent ); XChild xAsChild = UnoRuntime.queryInterface( XChild.class, aComponent );
@@ -171,7 +171,7 @@ public class FLTools
*/ */
static XPropertySet getParent( Object aComponent ) static XPropertySet getParent( Object aComponent )
{ {
return (XPropertySet)getParent( aComponent, XPropertySet.class ); return getParent( aComponent, XPropertySet.class );
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
@@ -188,7 +188,7 @@ public class FLTools
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/** get's the XControlModel for a control /** get's the XControlModel for a control
*/ */
static public Object getModel( Object aControl, Class aInterfaceClass ) static public <T> T getModel( Object aControl, Class<T> aInterfaceClass )
{ {
XControl xControl = UnoRuntime.queryInterface( XControl xControl = UnoRuntime.queryInterface(
XControl.class, aControl ); XControl.class, aControl );

View File

@@ -107,7 +107,7 @@ class SalesFilter implements XActionListener, XPropertyChangeListener, XResetLis
// for the button, we can add to the control only, not to the model // for the button, we can add to the control only, not to the model
// - clicking a button is something which happens on the _control_. // - clicking a button is something which happens on the _control_.
DocumentViewHelper aView = m_aDocument.getCurrentView(); DocumentViewHelper aView = m_aDocument.getCurrentView();
XButton xButton = (XButton)aView.getFormControl( m_xApplyFilter, XButton.class ); XButton xButton = aView.getFormControl( m_xApplyFilter, XButton.class );
xButton.addActionListener( this ); xButton.addActionListener( this );
} }
catch ( com.sun.star.uno.Exception e ) catch ( com.sun.star.uno.Exception e )

View File

@@ -126,10 +126,10 @@ public class OfficeConnect
* @param sServiceSpecifier name of service which should be created * @param sServiceSpecifier name of service which should be created
* @return the new created service object * @return the new created service object
*/ */
public static synchronized Object createRemoteInstance( public static synchronized <T> T createRemoteInstance(
Class aType, String sServiceSpecifier) Class<T> aType, String sServiceSpecifier)
{ {
Object aResult = null; T aResult = null;
try try
{ {
aResult = UnoRuntime.queryInterface(aType, aResult = UnoRuntime.queryInterface(aType,
@@ -157,10 +157,10 @@ public class OfficeConnect
* @param sServiceSpecifier Description of Parameter * @param sServiceSpecifier Description of Parameter
* @return the new create service object * @return the new create service object
*/ */
public static synchronized Object createRemoteInstanceWithArguments( public static synchronized <T> T createRemoteInstanceWithArguments(
Class aType, String sServiceSpecifier, Any[] lArguments) Class<T> aType, String sServiceSpecifier, Any[] lArguments)
{ {
Object aResult = null; T aResult = null;
try try
{ {
aResult = UnoRuntime.queryInterface(aType, aResult = UnoRuntime.queryInterface(aType,