tdf#80731: Only check closing parenthesis when in IDE

This reinstates the fix by Pierre Lepage, which was reverted in
351dead74b4c213b13102f81b5ae9bb47ad8ca39, and makes sure it only
has effect when the compilation is started from IDE.

The idea is that the IDE is used primarily for development, and
that's a good opportunity to detect any error in the code. When
the code is compiled from outside of the IDE (like running an
extension), the error is tolerated to allow users run the legacy
code having this error. Hopefully this is enough for tdf#106529.

This re-uses comphelper's NoEnableJavaInteractionContext class,
which is converted into general-purpose SetFlagContext class to
avoid code duplication.

Change-Id: Ie290019cb190b8d1d590699ec13bd63eac478d09
Reviewed-on: https://gerrit.libreoffice.org/81616
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2019-10-28 18:59:57 +03:00
parent 7e7e97fc0b
commit d628258f27
7 changed files with 91 additions and 62 deletions

View File

@ -36,6 +36,7 @@
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/FilePicker.hpp> #include <com/sun/star/ui/dialogs/FilePicker.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
#include <svl/srchdefs.hxx> #include <svl/srchdefs.hxx>
#include <svtools/ehdl.hxx> #include <svtools/ehdl.hxx>
@ -282,7 +283,11 @@ void ModulWindow::CheckCompileBasic()
bool bWasModified = GetBasic()->IsModified(); bool bWasModified = GetBasic()->IsModified();
bDone = m_xModule->Compile(); {
// tdf#106529: only use strict compilation mode when compiling from the IDE
css::uno::ContextLayer layer(comphelper::NewFlagContext("BasicStrict"));
bDone = m_xModule->Compile();
}
if ( !bWasModified ) if ( !bWasModified )
GetBasic()->SetModified(false); GetBasic()->SetModified(false);

View File

@ -22,6 +22,7 @@
#include <parser.hxx> #include <parser.hxx>
#include <basic/sbx.hxx> #include <basic/sbx.hxx>
#include <expr.hxx> #include <expr.hxx>
#include <uno/current_context.hxx>
SbiExpression::SbiExpression( SbiParser* p, SbiExprType t, SbiExpression::SbiExpression( SbiParser* p, SbiExprType t,
SbiExprMode eMode, const KeywordSymbolInfo* pKeywordSymbolInfo ) SbiExprMode eMode, const KeywordSymbolInfo* pKeywordSymbolInfo )
@ -1033,6 +1034,21 @@ SbiExprListPtr SbiExprList::ParseParameters( SbiParser* pParser, bool bStandalon
{ {
if( ( pExprList->bBracket && eTok == RPAREN ) || SbiTokenizer::IsEoln( eTok ) ) if( ( pExprList->bBracket && eTok == RPAREN ) || SbiTokenizer::IsEoln( eTok ) )
{ {
// tdf#80731
if (SbiTokenizer::IsEoln(eTok) && pExprList->bBracket)
{
// tdf#106529: only fail here in strict mode (i.e. when compiled from IDE), and
// allow legacy code with missing closing parenthesis when started e.g. from
// extensions and event handlers
bool bCheckStrict = false;
if (auto xContext = css::uno::getCurrentContext())
xContext->getValueByName("BasicStrict") >>= bCheckStrict;
if (bCheckStrict)
{
pParser->Error(ERRCODE_BASIC_EXPECTED, RPAREN);
pExprList->bError = true;
}
}
break; break;
} }
pParser->Error( pExprList->bBracket ? ERRCODE_BASIC_BAD_BRACKETS : ERRCODE_BASIC_EXPECTED, COMMA ); pParser->Error( pExprList->bBracket ? ERRCODE_BASIC_BAD_BRACKETS : ERRCODE_BASIC_EXPECTED, COMMA );

View File

@ -40,7 +40,7 @@
#include <strings.hrc> #include <strings.hrc>
#include <bitmaps.hlst> #include <bitmaps.hlst>
#include <sfx2/minfitem.hxx> #include <sfx2/minfitem.hxx>
#include <comphelper/DisableInteractionHelper.hxx> #include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/documentinfo.hxx> #include <comphelper/documentinfo.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequenceashashmap.hxx>
@ -52,7 +52,6 @@
#include <vcl/commandinfoprovider.hxx> #include <vcl/commandinfoprovider.hxx>
#include <vcl/help.hxx> #include <vcl/help.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <uno/current_context.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
@ -487,8 +486,7 @@ void CuiConfigGroupListBox::FillScriptList(const css::uno::Reference< css::scrip
if ( xRootNode->hasChildNodes() ) if ( xRootNode->hasChildNodes() )
{ {
// tdf#120362: Don't ask to enable disabled Java when filling script list // tdf#120362: Don't ask to enable disabled Java when filling script list
css::uno::ContextLayer layer( css::uno::ContextLayer layer(comphelper::NoEnableJavaInteractionContext());
new comphelper::NoEnableJavaInteractionContext(css::uno::getCurrentContext()));
Sequence< Reference< browse::XBrowseNode > > children = Sequence< Reference< browse::XBrowseNode > > children =
xRootNode->getChildNodes(); xRootNode->getChildNodes();

View File

@ -24,7 +24,6 @@
#include <sfx2/objsh.hxx> #include <sfx2/objsh.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/weld.hxx> #include <vcl/weld.hxx>
#include <uno/current_context.hxx>
#include <strings.hrc> #include <strings.hrc>
#include <bitmaps.hlst> #include <bitmaps.hlst>
@ -47,7 +46,7 @@
#include <com/sun/star/script/XInvocation.hpp> #include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/document/XEmbeddedScripts.hpp> #include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <comphelper/DisableInteractionHelper.hxx> #include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/documentinfo.hxx> #include <comphelper/documentinfo.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
@ -255,8 +254,7 @@ SvxScriptOrgDialog::getLangNodeFromRootNode( Reference< browse::XBrowseNode > co
}; };
{ {
// First try without Java interaction, to avoid warnings for non-JRE-dependent providers // First try without Java interaction, to avoid warnings for non-JRE-dependent providers
css::uno::ContextLayer layer( css::uno::ContextLayer layer(comphelper::NoEnableJavaInteractionContext());
new comphelper::NoEnableJavaInteractionContext(css::uno::getCurrentContext()));
langNode = tryFind(); langNode = tryFind();
} }
if (!langNode) if (!langNode)

View File

@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_COMPHELPER_DISABLEINTERACTIONHELPER_HXX
#define INCLUDED_COMPHELPER_DISABLEINTERACTIONHELPER_HXX
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/uno/XCurrentContext.hpp>
namespace comphelper
{
class NoEnableJavaInteractionContext final : public cppu::WeakImplHelper<css::uno::XCurrentContext>
{
public:
explicit NoEnableJavaInteractionContext(
css::uno::Reference<css::uno::XCurrentContext> const& xContext)
: mxContext(xContext)
{
}
NoEnableJavaInteractionContext(const NoEnableJavaInteractionContext&) = delete;
NoEnableJavaInteractionContext& operator=(const NoEnableJavaInteractionContext&) = delete;
private:
virtual ~NoEnableJavaInteractionContext() override {}
virtual css::uno::Any SAL_CALL getValueByName(OUString const& Name) override
{
if (Name == "DontEnableJava")
return css::uno::Any(true);
else if (mxContext.is())
return mxContext->getValueByName(Name);
else
return css::uno::Any();
}
css::uno::Reference<css::uno::XCurrentContext> mxContext;
};
} // namespace comphelper
#endif // INCLUDED_COMPHELPER_DISABLEINTERACTIONHELPER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
#define INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
#include <com/sun/star/uno/XCurrentContext.hpp>
#include <cppuhelper/implbase.hxx>
#include <uno/current_context.hxx>
namespace comphelper
{
// Used to flag some named value to be true for all code running in this context
class SetFlagContext final : public cppu::WeakImplHelper<css::uno::XCurrentContext>
{
public:
explicit SetFlagContext(const OUString& sName,
css::uno::Reference<css::uno::XCurrentContext> const& xContext)
: m_sName(sName)
, mxNextContext(xContext)
{
}
SetFlagContext(const SetFlagContext&) = delete;
SetFlagContext& operator=(const SetFlagContext&) = delete;
virtual css::uno::Any SAL_CALL getValueByName(OUString const& Name) override
{
if (Name == m_sName)
return css::uno::Any(true);
else if (mxNextContext.is())
return mxNextContext->getValueByName(Name);
else
return css::uno::Any();
}
private:
OUString m_sName;
css::uno::Reference<css::uno::XCurrentContext> mxNextContext;
};
// Returns a new context that reports the named value to be true
inline css::uno::Reference<css::uno::XCurrentContext> NewFlagContext(const OUString& sName)
{
return new SetFlagContext(sName, css::uno::getCurrentContext());
}
// A specialization for preventing "Java must be enabled" interaction
inline css::uno::Reference<css::uno::XCurrentContext> NoEnableJavaInteractionContext()
{
return NewFlagContext("DontEnableJava");
}
} // namespace comphelper
#endif // INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -18,7 +18,7 @@
*/ */
#include <comphelper/DisableInteractionHelper.hxx> #include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/documentinfo.hxx> #include <comphelper/documentinfo.hxx>
#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/implementationentry.hxx>
@ -26,7 +26,6 @@
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <tools/diagnose_ex.h> #include <tools/diagnose_ex.h>
#include <uno/current_context.hxx>
#include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/lang/EventObject.hpp> #include <com/sun/star/lang/EventObject.hpp>
@ -479,8 +478,7 @@ template <typename Proc> bool FindProviderAndApply(ProviderCache& rCache, Proc p
// This allows us to avoid useless user interaction in case when other provider // This allows us to avoid useless user interaction in case when other provider
// (not JVM) actually handles the operation. // (not JVM) actually handles the operation.
{ {
css::uno::ContextLayer layer( css::uno::ContextLayer layer(comphelper::NoEnableJavaInteractionContext());
new comphelper::NoEnableJavaInteractionContext(css::uno::getCurrentContext()));
bSuccess = pass(); bSuccess = pass();
} }
// 2. Now retry asking to enable JVM in case we didn't succeed first time // 2. Now retry asking to enable JVM in case we didn't succeed first time