loplugin:unocast (sd::TextApiObject)

(See the upcoming commit introducing that loplugin:unocast on why such
dynamic_casts from UNO types are dangerous.)

The odd implementation of TextApiObject::getImplementation had been effectively
like that ever since the code's introduction in
5d431414af "CWS-TOOLING: integrate CWS
impressnotes01", for no obvious reason.  And as it can be reduced to a single
comphelper::getFromUnoTunnel call, drop the function and directly call that at
the (single) call site.

Change-Id: If50a81cf8bee0dddbdfb5e6b5516c24a03e858e9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144699
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2022-12-21 16:48:44 +01:00
parent 24e14afd1b
commit 0c7585c5fa
3 changed files with 12 additions and 9 deletions

View file

@ -43,7 +43,8 @@ public:
void SetText( OutlinerParaObject const & rText );
OUString GetText() const;
static TextApiObject* getImplementation( const css::uno::Reference< css::text::XText >& );
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
private:
std::unique_ptr<TextAPIEditSource> mpSource;

View file

@ -23,6 +23,7 @@
#include <textapi.hxx>
#include <drawdoc.hxx>
#include <comphelper/servicehelper.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/editeng.hxx>
#include <editeng/outlobj.hxx>
@ -179,14 +180,14 @@ OUString TextApiObject::GetText() const
return mpSource->GetText();
}
TextApiObject* TextApiObject::getImplementation( const css::uno::Reference< css::text::XText >& xText )
{
TextApiObject* pImpl = dynamic_cast< TextApiObject* >( xText.get() );
sal_Int64 TextApiObject::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(
aIdentifier, this, comphelper::FallbackToGetSomethingOf<SvxUnoText>{});
}
if( !pImpl )
pImpl = dynamic_cast< TextApiObject* >( comphelper::getFromUnoTunnel<SvxUnoTextBase>( xText ) );
return pImpl;
css::uno::Sequence<sal_Int8> const & TextApiObject::getUnoTunnelId() {
static comphelper::UnoIdInit const id;
return id.getSeq();
}
TextAPIEditSource::TextAPIEditSource(const TextAPIEditSource& rSource)

View file

@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <comphelper/servicehelper.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/langitem.hxx>
@ -487,7 +488,7 @@ TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
if( xAnnotation.is() )
{
Reference< XText > xText( xAnnotation->getTextRange() );
return TextApiObject::getImplementation( xText );
return comphelper::getFromUnoTunnel<TextApiObject>( xText );
}
return nullptr;
}