Skip to content

[WiP] Removed default registration of generic exception types #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ class CppGeneratorTest extends AbstractGeneratorTest
#include "modules/Infrastructure/ServiceHost/Demo/API/ServiceAPI/include/IKeyValueStore.h"

#include "modules/Commons/include/BeginCabInclude.h" // CAB -->
#include "Commons/Core/include/InvalidArgumentException.h"
#include "Commons/Core/include/String.h"
#include "Commons/Core/include/UnsupportedOperationException.h"
#include "Commons/CoreExtras/include/UUID.h"
#include "ServiceComm/API/include/IServiceFaultHandler.h"
#include "ServiceComm/Base/include/DefaultServiceFaultHandler.h"
Expand All @@ -103,12 +101,6 @@ class CppGeneratorTest extends AbstractGeneratorTest

void RegisterKeyValueStoreServiceFaults(BTC::ServiceComm::API::IServiceFaultHandlerManager& serviceFaultHandlerManager)
{

// most commonly used exception types
BTC::ServiceComm::Base::RegisterServiceFault<BTC::Commons::Core::InvalidArgumentException>(
serviceFaultHandlerManager, BTC::Commons::Core::String("BTC.Commons.Core.InvalidArgumentException"));
BTC::ServiceComm::Base::RegisterServiceFault<BTC::Commons::Core::UnsupportedOperationException>(
serviceFaultHandlerManager, BTC::Commons::Core::String("BTC.Commons.Core.UnsupportedOperationException"));
}
}}}}}}}
''')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ public class TypesCodec {
import com.btc.cab.servicecomm.api.IServiceFaultHandler;
import com.btc.cab.servicecomm.faulthandling.DefaultServiceFaultHandler;
import com.btc.cab.servicecomm.faulthandling.ErrorMessage;
import java.lang.IllegalArgumentException;
import java.lang.UnsupportedOperationException;
import java.lang.reflect.Constructor;
import java.util.Optional;
import org.apache.commons.collections4.BidiMap;
Expand All @@ -330,10 +328,6 @@ public class TypesCodec {

static
{

// most commonly used exception types
errorMap.put("BTC.Commons.Core.InvalidArgumentException", IllegalArgumentException.class);
errorMap.put("BTC.Commons.Core.UnsupportedOperationException", UnsupportedOperationException.class);
}

public static final IServiceFaultHandler createServiceFaultHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.btc.serviceidl.idl.AbstractTypeReference
import com.btc.serviceidl.idl.AliasDeclaration
import com.btc.serviceidl.idl.EnumDeclaration
import com.btc.serviceidl.idl.ExceptionDeclaration
import com.btc.serviceidl.idl.FunctionDeclaration
import com.btc.serviceidl.idl.IDLSpecification
import com.btc.serviceidl.idl.InterfaceDeclaration
import com.btc.serviceidl.idl.ModuleDeclaration
Expand Down Expand Up @@ -255,4 +256,11 @@ class GeneratorUtil
// (in the generator settings?)
idl.eResource.URI.lastSegment.replace(".idl", "") + if (artifactNature == ArtifactNature.DOTNET) ".NET" else ""
}

static def String getProtobufFunctionName(FunctionDeclaration object, ProtobufType protobufType)
{
val scopeDeterminant = object.scopeDeterminant
#[Names.plain(scopeDeterminant), protobufType.getName, Names.plain(object) + protobufType.getName].join("_")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class BasicCppGenerator

def CharSequence generateIncludes(boolean isHeader)
{
// TODO filter out self from includes (here, or already in the TypeResolver.resolve call?
val includes = typeResolver.includes
val result = new StringBuilder()

Expand All @@ -360,16 +361,16 @@ class BasicCppGenerator
throw new IllegalArgumentException("Unconfigured include groups: " + includes.keySet.join(", "))
}

result.append(
'''
«IF !isHeader && paramBundle.projectType == ProjectType.SERVER_RUNNER»
// TODO remove this (at least from here)
if (!isHeader && paramBundle.projectType == ProjectType.SERVER_RUNNER)
result.append(
'''

#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
«ENDIF»
''')
''')

return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ class CodecGenerator extends BasicCppGenerator
«val exceptionName = exception.getCommonExceptionName(qualifiedNameProvider)»
faultHandlers["«exceptionName»"] = [](«cabString» const& msg) { return «cabCreateUnique»<«exceptionType»>(msg); };
«ENDFOR»

// most commonly used exception types
«val defaultExceptions = typeResolver.defaultExceptionRegistration»
«FOR exception : defaultExceptions.keySet.sort»
faultHandlers["«exception»"] = [](«cabString» const& msg) { return «cabCreateUnique»<«defaultExceptions.get(exception)»>(msg); };
«ENDFOR»
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ class ProtobufUtil

val paramBundle = ParameterBundle.createBuilder(scopeDeterminant.moduleStack).with(ProjectType.PROTOBUF).build

// TODO this is cloned by java.ProtobufUtil(.getLocalName?)
val result = GeneratorUtil.getTransformedModuleName(paramBundle, ArtifactNature.CPP, TransformType.NAMESPACE) +
Constants.SEPARATOR_NAMESPACE + if (object instanceof InterfaceDeclaration)
Names.plain(object) + protobufType.getName
else if (object instanceof FunctionDeclaration)
Names.plain(scopeDeterminant) + "_" + protobufType.getName + "_" + Names.plain(object) +
protobufType.getName
getProtobufFunctionName(object, protobufType)
else
Names.plain(object)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ class ServiceAPIGenerator extends BasicCppGenerator {
«registerServiceFault»<«resolveExcName»>(
serviceFaultHandlerManager, «cabString»("«exception.getCommonExceptionName(qualifiedNameProvider)»"));
«ENDFOR»

// most commonly used exception types
«val defaultExceptions = typeResolver.defaultExceptionRegistration»
«FOR exception : defaultExceptions.keySet.sort»
«registerServiceFault»<«defaultExceptions.get(exception)»>(
serviceFaultHandlerManager, «cabString»("«exception»"));
«ENDFOR»
}
'''
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.btc.serviceidl.generator.cpp

import com.btc.serviceidl.generator.common.GuidMapper
import com.btc.serviceidl.idl.StructDeclaration
import com.btc.serviceidl.util.Constants
import java.util.Map

class TypeResolverExtensions {
static def String makeEventGUIDImplementations(extension TypeResolver typeResolver,
Expand All @@ -27,14 +25,4 @@ class TypeResolverExtensions {
'''
}

static def Map<String, String> getDefaultExceptionRegistration(extension TypeResolver typeResolver)
{
// TODO these must not be registered, the default must be empty
#{
Constants.INVALID_ARGUMENT_EXCEPTION_FAULT_HANDLER -> resolveSymbol("BTC::Commons::Core::InvalidArgumentException")
,Constants.UNSUPPORTED_OPERATION_EXCEPTION_FAULT_HANDLER -> resolveSymbol("BTC::Commons::Core::UnsupportedOperationException")
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class ServiceFaultHandlingGenerator extends GeneratorBase

static «className»()
{
// most commonly used exception types
errorMap["«Constants.INVALID_ARGUMENT_EXCEPTION_FAULT_HANDLER»"] = typeof(«resolve("System.ArgumentException").fullyQualifiedName»);
errorMap["«Constants.UNSUPPORTED_OPERATION_EXCEPTION_FAULT_HANDLER»"] = typeof(«resolve("System.NotSupportedException").fullyQualifiedName»);

«FOR e : raisedExceptions.sortBy[name] SEPARATOR System.lineSeparator»
errorMap["«e.getCommonExceptionName(qualifiedNameProvider)»"] = typeof(«resolve(e)»);
«ENDFOR»
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class TypeResolver

def ResolvedName resolve(String name)
{
val effectiveName = resolveException(name) ?: name
val fullyQualifiedName = QualifiedName.create(
effectiveName.split(Pattern.quote(Constants.SEPARATOR_PACKAGE)))
val effectiveName = name
val fullyQualifiedName = QualifiedName.create(effectiveName.split(Pattern.quote(Constants.SEPARATOR_PACKAGE)))
val namespace = fullyQualifiedName.skipLast(1).toString

if (namespace.startsWith("System"))
Expand Down Expand Up @@ -148,19 +147,6 @@ class TypeResolver
return new ResolvedName(result, TransformType.PACKAGE, FULLY_QUALIFIED)
}

private static def String resolveException(String name)
{
// temporarily some special handling for exceptions, because not all
// C++ CAB exceptions are supported by the .NET CAB
switch (name)
{
case "BTC.Commons.Core.InvalidArgumentException":
return "System.ArgumentException"
default:
return null
}
}

private def boolean isSameProject(QualifiedName referencedPackage)
{
GeneratorUtil.getTransformedModuleName(parameterBundle, ArtifactNature.DOTNET, TransformType.PACKAGE) ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class BasicJavaSourceGenerator

def dispatch String toText(ExceptionDeclaration element)
{
typeResolver.resolveException(qualifiedNameProvider.getFullyQualifiedName(element).toString) ?:
'''«typeResolver.resolve(element)»'''
'''«typeResolver.resolve(element)»'''
}

def dispatch String toText(SequenceDeclaration item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class ProtobufUtil
val scopeDeterminant = object.scopeDeterminant

if (object instanceof FunctionDeclaration && Util.ensurePresentOrThrow(optProtobufType))
Names.plain(scopeDeterminant) + "_" + optProtobufType.get.getName + "_" + Names.plain(object) +
optProtobufType.get.getName
getProtobufFunctionName(object as FunctionDeclaration, optProtobufType.get)
else
(if (scopeDeterminant instanceof ModuleDeclaration)
Constants.FILE_NAME_TYPES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class ServiceFaultHandlerFactoryGenerator

// TODO except for the static initializer, this can be extracted into a reusable class, which can be provided
// from com.btc.cab.servicecomm
// TODO InvalidArgumentException and UnsupportedOperationException should not be added to the error map, only
// service-specific subtypes
'''
public class «className»
{
Expand All @@ -61,10 +59,6 @@ class ServiceFaultHandlerFactoryGenerator
«FOR exception : exceptions.sortBy[name]»
errorMap.put("«Util.getCommonExceptionName(exception, basicJavaSourceGenerator.qualifiedNameProvider)»", «getClassOrObject(typeResolver.resolve(exception))»);
«ENDFOR»

// most commonly used exception types
errorMap.put("«Constants.INVALID_ARGUMENT_EXCEPTION_FAULT_HANDLER»", «getClassOrObject(typeResolver.resolve("java.lang.IllegalArgumentException"))»);
errorMap.put("«Constants.UNSUPPORTED_OPERATION_EXCEPTION_FAULT_HANDLER»", «getClassOrObject(typeResolver.resolve("java.lang.UnsupportedOperationException"))»);
}

public static final «typeResolver.resolve(JavaClassNames.SERVICE_FAULT_HANDLER)» createServiceFaultHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ class TypeResolver
{
var name = qualifiedNameProvider.getFullyQualifiedName(element)

// try to resolve CAB-related pseudo-exceptions
if (element.isException)
{
val exceptionName = resolveException(name.toString)
if (exceptionName !== null)
return new ResolvedName(exceptionName, TransformType.PACKAGE, fullyQualified)
}

if (name === null)
{
if (element instanceof AbstractType)
Expand Down Expand Up @@ -157,20 +149,6 @@ class TypeResolver
return new ResolvedName(fullyQualifiedName, TransformType.PACKAGE, fullyQualified)
}

def String resolveException(String name)
{
// temporarily some special handling for exceptions, because not all
// C++ CAB exceptions are supported by the Java CAB
switch (name)
{
case "BTC.Commons.Core.InvalidArgumentException":
// TODO shouldn't this use resolve("java.util.IllegalArgumentException")?
"IllegalArgumentException"
default:
null
}
}

private static def String getObservableName(EventDeclaration event)
{
if (event.name === null)
Expand Down
5 changes: 0 additions & 5 deletions com.btc.serviceidl/src/com/btc/serviceidl/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public interface Constants {
public static final String FILE_NAME_ODB_COMMON = "common";
public static final String FILE_NAME_ODB_TRAITS = "traits";

// GUID for default exception registration thrown by not implemented methods
public static final String UNSUPPORTED_OPERATION_EXCEPTION_FAULT_HANDLER = "BTC.Commons.Core.UnsupportedOperationException";

public static final String INVALID_ARGUMENT_EXCEPTION_FAULT_HANDLER = "BTC.Commons.Core.InvalidArgumentException";

public static final int DEFAULT_PORT = 5555;

public static final String AUTO_GENERATED_METHOD_STUB_MESSAGE = "Auto-generated method stub is not implemented!";
Expand Down