compilerplugins/clang/referencecasting.cxx            |   11 ++++++++++-
 compilerplugins/clang/test/referencecasting.cxx       |    5 +++++
 connectivity/source/drivers/hsqldb/HDriver.cxx        |    3 +--
 forms/source/component/DatabaseForm.cxx               |    2 +-
 forms/source/component/FormComponent.cxx              |    2 +-
 reportdesign/source/core/sdr/RptModel.cxx             |    2 +-
 sd/source/ui/slideshow/slideshow.cxx                  |   13 ++++++-------
 sd/source/ui/tools/EventMultiplexer.cxx               |    7 ++-----
 sw/source/uibase/uno/SwXDocumentSettings.cxx          |    3 +--
 toolkit/source/controls/controlmodelcontainerbase.cxx |   16 +++++-----------
 toolkit/source/controls/formattedcontrol.cxx          |    3 +--
 toolkit/source/controls/tabpagemodel.cxx              |    9 ++++-----
 unotools/source/ucbhelper/tempfile.cxx                |    4 ++--
 unotools/source/ucbhelper/xtempfile.cxx               |   10 +++++-----
 14 files changed, 45 insertions(+), 45 deletions(-)

New commits:
commit 767092fe2cab4a8b28426a6b2b1c752277fc7df6
Author:     Noel Grandin <[email protected]>
AuthorDate: Fri Oct 21 11:58:39 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Oct 21 15:50:35 2022 +0200

    loplugin:referencecasting look for a new pattern
    
    Change-Id: Ib7ded8db2c513909159f0876389f63b60082a529
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141618
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/compilerplugins/clang/referencecasting.cxx 
b/compilerplugins/clang/referencecasting.cxx
index dae0ce89d81f..2cc4a627bba9 100644
--- a/compilerplugins/clang/referencecasting.cxx
+++ b/compilerplugins/clang/referencecasting.cxx
@@ -151,7 +151,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const 
CXXConstructExpr* cce)
     {
         if (auto castExpr = dyn_cast<CastExpr>(constructorArg0))
         {
-            constructorArg0 = castExpr->getSubExpr();
+            constructorArg0 = castExpr->getSubExprAsWritten();
             continue;
         }
         if (auto matTempExpr = 
dyn_cast<MaterializeTemporaryExpr>(constructorArg0))
@@ -174,6 +174,15 @@ bool ReferenceCasting::VisitCXXConstructExpr(const 
CXXConstructExpr* cce)
             constructorArg0 = parenExpr->getSubExpr();
             continue;
         }
+        // for the "uno::Reference<X>(*this, UNO_QUERY)" case
+        if (auto unaryOper = dyn_cast<UnaryOperator>(constructorArg0))
+        {
+            if (unaryOper->getOpcode() == UO_Deref)
+            {
+                constructorArg0 = unaryOper->getSubExpr();
+                continue;
+            }
+        }
         argType = constructorArg0->getType();
         break;
     }
diff --git a/compilerplugins/clang/test/referencecasting.cxx 
b/compilerplugins/clang/test/referencecasting.cxx
index 1f3480dbee5b..beb69cc86616 100644
--- a/compilerplugins/clang/test/referencecasting.cxx
+++ b/compilerplugins/clang/test/referencecasting.cxx
@@ -206,6 +206,11 @@ class Foo : public 
cppu::WeakImplHelper<css::lang::XComponent, css::io::XInputSt
         return 
css::uno::Reference<css::io::XInputStream>(static_cast<css::io::XInputStream*>(this),
                                                           css::uno::UNO_QUERY);
     }
+    css::uno::Reference<css::io::XInputStream> bar3()
+    {
+        // expected-error@+1 {{the source reference is already a subtype of 
the destination reference, just use = [loplugin:referencecasting]}}
+        return css::uno::Reference<css::io::XInputStream>(*this, 
css::uno::UNO_QUERY);
+    }
 };
 }
 
diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx 
b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 9e80676f20e6..09686ef6dbdf 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -358,8 +358,7 @@ namespace connectivity
                     Reference<XTransactionBroadcaster> 
xBroad(xStorage,UNO_QUERY);
                     if ( xBroad.is() )
                     {
-                        Reference<XTransactionListener> 
xListener(*this,UNO_QUERY);
-                        xBroad->addTransactionListener(xListener);
+                        
xBroad->addTransactionListener(Reference<XTransactionListener>(this));
                     }
                 }
             }
diff --git a/forms/source/component/DatabaseForm.cxx 
b/forms/source/component/DatabaseForm.cxx
index fff1fdf6b5c8..d4795414a43d 100644
--- a/forms/source/component/DatabaseForm.cxx
+++ b/forms/source/component/DatabaseForm.cxx
@@ -1328,7 +1328,7 @@ void ODatabaseForm::describeFixedAndAggregateProperties(
 
 Reference< XMultiPropertySet > ODatabaseForm::getPropertiesInterface()
 {
-    return Reference< XMultiPropertySet >( *this, UNO_QUERY );
+    return this;
 }
 
 
diff --git a/forms/source/component/FormComponent.cxx 
b/forms/source/component/FormComponent.cxx
index 7b6dd36c5e75..e18ca14628c1 100644
--- a/forms/source/component/FormComponent.cxx
+++ b/forms/source/component/FormComponent.cxx
@@ -1061,7 +1061,7 @@ void OControlModel::describeFixedAndAggregateProperties( 
Sequence< Property >& _
 
 Reference< XMultiPropertySet > OControlModel::getPropertiesInterface()
 {
-    return Reference< XMultiPropertySet >( *this, UNO_QUERY );
+    return this;
 }
 
 Reference< XPropertySetInfo> SAL_CALL OControlModel::getPropertySetInfo()
diff --git a/reportdesign/source/core/sdr/RptModel.cxx 
b/reportdesign/source/core/sdr/RptModel.cxx
index f79c2a214fca..3dc4bb216b57 100644
--- a/reportdesign/source/core/sdr/RptModel.cxx
+++ b/reportdesign/source/core/sdr/RptModel.cxx
@@ -155,7 +155,7 @@ uno::Reference< uno::XInterface > 
OReportModel::createShape(const OUString& aSer
             xRet = xProp;
             if ( _rShape.is() )
                 throw uno::Exception("no shape", nullptr);
-            xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, 
uno::Any(uno::Reference< util::XNumberFormatsSupplier 
>(*m_pReportDefinition,uno::UNO_QUERY)) );
+            xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, 
uno::Any(uno::Reference< util::XNumberFormatsSupplier >(m_pReportDefinition)) );
         }
         else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
         {
diff --git a/sd/source/ui/slideshow/slideshow.cxx 
b/sd/source/ui/slideshow/slideshow.cxx
index aeee4ca7cae0..194cb3c62804 100644
--- a/sd/source/ui/slideshow/slideshow.cxx
+++ b/sd/source/ui/slideshow/slideshow.cxx
@@ -735,13 +735,12 @@ void SAL_CALL SlideShow::end()
                     pDrawViewShell->SwitchPage( 
static_cast<sal_uInt16>(xController->getRestoreSlide()) );
                 else
                 {
-                    Reference<XDrawView> xDrawView (
-                        
Reference<XWeak>(&mpCurrentViewShellBase->GetDrawController()), UNO_QUERY);
-                    if (xDrawView.is())
-                        xDrawView->setCurrentPage(
-                            Reference<XDrawPage>(
-                                
mpDoc->GetSdPage(xController->getRestoreSlide(), 
PageKind::Standard)->getUnoPage(),
-                                UNO_QUERY));
+                    DrawController& rDrawController =
+                        mpCurrentViewShellBase->GetDrawController();
+                    rDrawController.setCurrentPage(
+                        Reference<XDrawPage>(
+                            mpDoc->GetSdPage(xController->getRestoreSlide(), 
PageKind::Standard)->getUnoPage(),
+                            UNO_QUERY));
                 }
             }
 
diff --git a/sd/source/ui/tools/EventMultiplexer.cxx 
b/sd/source/ui/tools/EventMultiplexer.cxx
index a61413ac624e..26d43b9b6dc6 100644
--- a/sd/source/ui/tools/EventMultiplexer.cxx
+++ b/sd/source/ui/tools/EventMultiplexer.cxx
@@ -211,13 +211,10 @@ EventMultiplexer::Implementation::Implementation 
(ViewShellBase& rBase)
         StartListening (*mpDocument);
 
     // Listen for configuration changes.
-    Reference<XControllerManager> xControllerManager (
-        Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY);
-    if (!xControllerManager.is())
-        return;
+    DrawController& rDrawController = mrBase.GetDrawController();
 
     Reference<XConfigurationController> xConfigurationController (
-        xControllerManager->getConfigurationController());
+        rDrawController.getConfigurationController());
     mxConfigurationControllerWeak = xConfigurationController;
     if (!xConfigurationController.is())
         return;
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx 
b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index f22afc97d38b..a30473028d1e 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -1124,8 +1124,7 @@ void SwXDocumentSettings::_getSingleValue( const 
comphelper::PropertyInfo & rInf
     {
         case HANDLE_FORBIDDEN_CHARS:
         {
-            Reference<XForbiddenCharacters> 
xRet(*mpModel->GetPropertyHelper(), UNO_QUERY);
-            rValue <<= xRet;
+            rValue <<= 
Reference<XForbiddenCharacters>(mpModel->GetPropertyHelper());
         }
         break;
         case HANDLE_LINK_UPDATE_MODE:
diff --git a/toolkit/source/controls/controlmodelcontainerbase.cxx 
b/toolkit/source/controls/controlmodelcontainerbase.cxx
index 5ab12eb1934d..b0b37df4cbf7 100644
--- a/toolkit/source/controls/controlmodelcontainerbase.cxx
+++ b/toolkit/source/controls/controlmodelcontainerbase.cxx
@@ -736,30 +736,26 @@ void SAL_CALL ControlModelContainerBase::initialize 
(const Sequence<Any>& rArgum
 sal_Bool SAL_CALL ControlModelContainerBase::getEnabled()
 {
     SolarMutexGuard aGuard;
-    Reference<XPropertySet> xThis(*this, UNO_QUERY);
     bool bEnabled = false;
-    xThis->getPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED)) >>= 
bEnabled;
+    getPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED)) >>= bEnabled;
     return bEnabled;
 }
 void SAL_CALL ControlModelContainerBase::setEnabled( sal_Bool _enabled )
 {
     SolarMutexGuard aGuard;
-    Reference<XPropertySet> xThis(*this, UNO_QUERY);
-    xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED), 
Any(_enabled));
+    setPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED), Any(_enabled));
 }
 OUString SAL_CALL ControlModelContainerBase::getTitle()
 {
     SolarMutexGuard aGuard;
-    Reference<XPropertySet> xThis(*this,UNO_QUERY);
     OUString sTitle;
-    xThis->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)) >>= sTitle;
+    getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)) >>= sTitle;
     return sTitle;
 }
 void SAL_CALL ControlModelContainerBase::setTitle( const OUString& _title )
 {
     SolarMutexGuard aGuard;
-    Reference<XPropertySet> xThis(*this,UNO_QUERY);
-    xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),Any(_title));
+    setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),Any(_title));
 }
 OUString SAL_CALL ControlModelContainerBase::getImageURL()
 {
@@ -769,9 +765,7 @@ void SAL_CALL ControlModelContainerBase::setImageURL( const 
OUString& _imageurl
 {
     m_sImageURL = _imageurl;
     SolarMutexGuard aGuard;
-    Reference<XPropertySet> xThis(*this, UNO_QUERY);
-    xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL), 
Any(_imageurl));
-
+    setPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL), Any(_imageurl));
 }
 OUString SAL_CALL ControlModelContainerBase::getToolTip()
 {
diff --git a/toolkit/source/controls/formattedcontrol.cxx 
b/toolkit/source/controls/formattedcontrol.cxx
index 238c8d5876f3..e96a6986a7d0 100644
--- a/toolkit/source/controls/formattedcontrol.cxx
+++ b/toolkit/source/controls/formattedcontrol.cxx
@@ -201,8 +201,7 @@ namespace toolkit
                 }
             }
 
-            Reference< XPropertySet > xThis( *this, UNO_QUERY );
-            xThis->setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), 
Any( sStringValue ) );
+            setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), Any( 
sStringValue ) );
         }
         catch( const Exception& )
         {
diff --git a/toolkit/source/controls/tabpagemodel.cxx 
b/toolkit/source/controls/tabpagemodel.cxx
index cbfbebd78c51..355f794197bc 100644
--- a/toolkit/source/controls/tabpagemodel.cxx
+++ b/toolkit/source/controls/tabpagemodel.cxx
@@ -143,11 +143,10 @@ void SAL_CALL UnoControlTabPageModel::initialize (const 
Sequence<Any>& rArgument
             if ( xDialogProp.is() )
             {
                 static constexpr OUStringLiteral s_sResourceResolver = 
u"ResourceResolver";
-                Reference<XPropertySet> xThis(*this,UNO_QUERY);
-                
xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
-                
xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
-                
xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
-                
xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
+                
setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
+                
setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
+                
setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
+                
setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
             }
         }
     }
diff --git a/unotools/source/ucbhelper/tempfile.cxx 
b/unotools/source/ucbhelper/tempfile.cxx
index 09e3eda62e22..f55c421a0291 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -741,12 +741,12 @@ sal_Int64 SAL_CALL TempFileFastService::getLength()
 
 css::uno::Reference< css::io::XInputStream > SAL_CALL 
TempFileFastService::getInputStream()
 {
-    return css::uno::Reference< css::io::XInputStream >( *this, 
css::uno::UNO_QUERY );
+    return this;
 }
 
 css::uno::Reference< css::io::XOutputStream > SAL_CALL 
TempFileFastService::getOutputStream()
 {
-    return css::uno::Reference< css::io::XOutputStream >( this );
+    return this;
 }
 
 // XTruncate
diff --git a/unotools/source/ucbhelper/xtempfile.cxx 
b/unotools/source/ucbhelper/xtempfile.cxx
index a5772d8ba0c7..1515bc05f3e9 100644
--- a/unotools/source/ucbhelper/xtempfile.cxx
+++ b/unotools/source/ucbhelper/xtempfile.cxx
@@ -290,14 +290,14 @@ sal_Int64 SAL_CALL OTempFileService::getLength(  )
 // XStream
 
 css::uno::Reference< css::io::XInputStream > SAL_CALL 
OTempFileService::getInputStream()
-    {
-    return css::uno::Reference< css::io::XInputStream >( *this, 
css::uno::UNO_QUERY );
+{
+    return this;
 }
 
 css::uno::Reference< css::io::XOutputStream > SAL_CALL 
OTempFileService::getOutputStream()
-    {
-    return css::uno::Reference< css::io::XOutputStream >( *this, 
css::uno::UNO_QUERY );
-    }
+{
+    return this;
+}
 
 // XTruncate
 

Reply via email to