/* -*- 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void printLicenseHeader(std::ostream& o)
{
o << "/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */\n" "/*\n" " * This file is part of the LibreOffice project.\n" " *\n" " * This Source Code Form is subject to the terms of the Mozilla Public\n" " * License, v. 2.0. If a copy of the MPL was not distributed with this\n" " * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n" " */\n\n";
}
void checkType(rtl::Reference< TypeManager > const & manager,
OUString const & name,
std::set< OUString >& interfaceTypes,
std::set< OUString >& serviceTypes,
AttributeInfo& properties)
{
rtl::Reference< unoidl::Entity > ent; switch (manager->getSort(name, &ent)) { case codemaker::UnoType::Sort::Interface: // com.sun.star.lang.XComponent should be also not in the list // but it will be used for checking the impl helper and will be // removed later if necessary. if ( name == "com.sun.star.lang.XTypeProvider" ||
name == "com.sun.star.uno.XWeak" ) return;
interfaceTypes.insert(name); break; case codemaker::UnoType::Sort::SingleInterfaceBasedService: if (serviceTypes.insert(name).second) {
rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2( dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
ent.get()));
assert(ent2.is()); if (interfaceTypes.insert(ent2->getBase()).second) { // check if constructors are specified, if yes automatically // support of XInitialization. We will take care of the default // constructor because in this case XInitialization is not // called. if (ent2->getConstructors().size() > 1 ||
(ent2->getConstructors().size() == 1 &&
!ent2->getConstructors()[0].defaultConstructor))
{
interfaceTypes.insert(u"com.sun.star.lang.XInitialization"_ustr);
}
}
} break; case codemaker::UnoType::Sort::AccumulationBasedService: if ( serviceTypes.insert(name).second ) {
rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2( dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
ent.get()));
assert(ent2.is()); for (constauto& rService : ent2->getDirectMandatoryBaseServices())
{
checkType(
manager, rService.name, interfaceTypes, serviceTypes, properties);
} for (constauto& rIface : ent2->getDirectMandatoryBaseInterfaces())
{
checkType(
manager, rIface.name, interfaceTypes, serviceTypes, properties);
} for (constauto& rProp : ent2->getDirectProperties())
{
properties.push_back(rProp);
}
} break; default: throw CannotDumpException( "unexpected entity \"" + name
+ "\" in call to skeletonmaker::checkType");
}
}
// if XComponent is directly specified, return true and remove it from the // supported interfaces list bool checkXComponentSupport(rtl::Reference< TypeManager > const & manager,
std::set< OUString >& interfaces)
{ if ( interfaces.empty() ) returnfalse;
for ( constauto& rIface : interfaces ) { if ( rIface == "com.sun.star.lang.XComponent" ) {
interfaces.erase(u"com.sun.star.lang.XComponent"_ustr); returntrue;
} if ( checkXComponentSupport(manager, rIface) ) returntrue;
}
// This function checks if the specified types for parameters and return // types are allowed add-in types, for more info see the com.sun.star.sheet.AddIn // service description staticbool checkAddinType(rtl::Reference< TypeManager > const & manager,
std::u16string_view type, bool & bLastAny, bool & bHasXPropertySet, bool bIsReturn)
{
assert(manager.is());
sal_Int32 rank;
codemaker::UnoType::Sort sort = manager->decompose(
type, true, nullptr, &rank, nullptr, nullptr);
if ( sort == codemaker::UnoType::Sort::Long ||
sort == codemaker::UnoType::Sort::Double ||
sort == codemaker::UnoType::Sort::String )
{ if ( rank == 0 || rank ==2 ) returntrue;
} if ( sort == codemaker::UnoType::Sort::Any )
{ if ( rank <= 2 ) { if ( rank ==1 ) { if ( bIsReturn ) returnfalse;
bLastAny = true;
}
returntrue;
}
} if ( sort == codemaker::UnoType::Sort::Interface )
{ if ( bIsReturn && type == u"com.sun.star.sheet.XVolatileResult" ) returntrue; if ( !bIsReturn && type == u"com.sun.star.table.XCellRange" ) returntrue; if ( !bIsReturn && type == u"com.sun.star.beans.XPropertySet" )
{ if ( bHasXPropertySet ) { returnfalse;
} else {
bHasXPropertySet = true; returntrue;
}
}
} returnfalse;
}
staticvoid checkAddInTypes(
rtl::Reference< TypeManager > const & manager, std::u16string_view name,
rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
{
assert(entity.is()); bool bLastAny = false; bool bHasXPropertySet = false; for (constauto& rMethod : entity->getDirectMethods())
{ if ( !checkAddinType(
manager, rMethod.returnType, bLastAny, bHasXPropertySet, true) )
{ throw CannotDumpException(
OUString::Concat("the return type of the calc add-in function '") + name
+ ":" + rMethod.name
+ "' is invalid. Please check your IDL definition.");
}
bHasXPropertySet = false; for (constauto& rParam : rMethod.parameters)
{
bLastAny = false; if ( !checkAddinType(manager, rParam.type,
bLastAny, bHasXPropertySet, false) ||
bLastAny )
{ throw CannotDumpException( "the type of the " + rParam.name
+ " parameter of the calc add-in function '" + name
+ ":" + rMethod.name + "' is invalid."
+ (bLastAny
? u" The type 'sequence' is allowed as last" " parameter only."_ustr
: OUString())
+ (bHasXPropertySet
? u" The type 'XPropertySet' is allowed only once."_ustr
: OUString())
+ " Please check your IDL definition.");
}
}
}
}
staticvoid generateFunctionParameterMap(std::ostream& o,
ProgramOptions const & options,
rtl::Reference< TypeManager > const & manager,
OUString const & name,
::codemaker::GeneratedTypeSet & generated, bool& bFirst)
{ if ( name == "com.sun.star.uno.XInterface" ||
name == "com.sun.star.lang.XLocalizable" ||
name == "com.sun.star.lang.XServiceInfo" || // the next three checks becomes obsolete when configuration is used
name == "com.sun.star.sheet.XAddIn" ||
name == "com.sun.star.sheet.XCompatibilityNames" ||
name == "com.sun.star.lang.XServiceName" )
{ return;
}
rtl::Reference< unoidl::Entity > ent;
codemaker::UnoType::Sort sort = manager->getSort(name, &ent); if (sort != codemaker::UnoType::Sort::Interface) { throw CannotDumpException( "unexpected entity \"" + name
+ "\" in call to skeletonmaker::generateFunctionParameterMap");
}
rtl::Reference< unoidl::InterfaceTypeEntity > ent2( dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
assert(ent2.is());
// check if the specified add-in functions supports valid types
checkAddInTypes(manager, name, ent2);
for (constauto& rBase : ent2->getDirectMandatoryBases())
{
generateFunctionParameterMap(
o, options, manager, rBase.name, generated, bFirst);
}
if ( generated.contains(u2b(name)) ) return; else
generated.add(u2b(name));
for (constauto& rMethod : ent2->getDirectMethods())
{ if ( bFirst ) { if (options.language == 2) {
o << " ParamMap fpm;\n";
} else {
o << " java.util.Hashtable< Integer, String > fpm = " "new java.util.Hashtable< Integer, String >();\n";
}
bFirst = false;
} else if ( options.language == 2 ) {
o << " fpm = ParamMap();\n";
} else {
o << " fpm = new java.util.Hashtable< " "Integer, String >();\n";
}
std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::size_type
n = 0; for (constauto& rParam : rMethod.parameters)
{ if ( options.language == 2 ) {
o << " fpm[" << n
<< "] = OUString(\""
<< rParam.name
<< "\");\n";
} else {
o << " fpm.put(" << n << ", \""
<< rParam.name
<< "\");\n";
}
++n;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.