summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2017-01-19 16:21:07 -0500
committerBernard Normier <bernard@zeroc.com>2017-01-19 16:21:07 -0500
commita7a1e11a3d1f32e71ea24596fec6645ecd669419 (patch)
treee8b365a2fb897023965b2a26f7385c56bfb7d242 /cpp/src
parentFixed cross-testing objective-c/python (diff)
downloadice-a7a1e11a3d1f32e71ea24596fec6645ecd669419.tar.bz2
ice-a7a1e11a3d1f32e71ea24596fec6645ecd669419.tar.xz
ice-a7a1e11a3d1f32e71ea24596fec6645ecd669419.zip
java:UserException metadata for both local and remote operations
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/JavaUtil.cpp12
-rw-r--r--cpp/src/slice2confluence/Gen.cpp8
-rw-r--r--cpp/src/slice2cpp/Gen.cpp12
-rw-r--r--cpp/src/slice2cs/CsUtil.cpp12
-rw-r--r--cpp/src/slice2java/Gen.cpp58
-rw-r--r--cpp/src/slice2java/Gen.h5
-rw-r--r--cpp/src/slice2java/GenCompat.cpp78
-rw-r--r--cpp/src/slice2java/GenCompat.h5
-rw-r--r--cpp/src/slice2objc/ObjCUtil.cpp13
9 files changed, 56 insertions, 147 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 7441b60aca4..3c6d0ece494 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -227,18 +227,6 @@ public:
virtual void visitOperation(const OperationPtr& p)
{
- if(p->hasMetaData("UserException"))
- {
- ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
- if(!cl->isLocal())
- {
- ostringstream os;
- os << "ignoring invalid metadata `UserException': directive applies only to local operations "
- << "but enclosing " << (cl->isInterface() ? "interface" : "class") << " `" << cl->name()
- << "' is not local";
- emitWarning(p->file(), p->line(), os.str());
- }
- }
StringList metaData = getMetaData(p);
TypePtr returnType = p->returnType();
if(!metaData.empty())
diff --git a/cpp/src/slice2confluence/Gen.cpp b/cpp/src/slice2confluence/Gen.cpp
index 44890c0d368..00bd746812d 100644
--- a/cpp/src/slice2confluence/Gen.cpp
+++ b/cpp/src/slice2confluence/Gen.cpp
@@ -707,14 +707,10 @@ Slice::GeneratorBase::printMetaData(const ContainedPtr& p, bool isUserImplemente
userImplementedOnly.push_back("cpp:const");
userImplementedOnly.push_back("cpp:ice_print");
userImplementedOnly.push_back("java:serialVersionUID");
+ userImplementedOnly.push_back("java:UserException");
userImplementedOnly.push_back("UserException");
- if (isUserImplemented)
- {
-
- }
-
- if (!metaData.empty())
+ if(!metaData.empty())
{
string outString = "";
StringList::const_iterator q = metaData.begin();
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 073ce41241d..49db4f74884 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -4609,18 +4609,6 @@ Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p)
ami = true;
}
- if(p->hasMetaData("UserException"))
- {
- if(!cl->isLocal())
- {
- ostringstream ostr;
- ostr << "ignoring invalid metadata `UserException': directive applies only to local operations "
- << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
- << "' is not local";
- emitWarning(p->file(), p->line(), ostr.str());
- }
- }
-
StringList metaData = p->getMetaData();
metaData.remove("cpp:const");
diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp
index d29d7546daf..f430dfd5f01 100644
--- a/cpp/src/slice2cs/CsUtil.cpp
+++ b/cpp/src/slice2cs/CsUtil.cpp
@@ -2400,18 +2400,6 @@ Slice::CsGenerator::MetaDataVisitor::visitStructEnd(const StructPtr&)
void
Slice::CsGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
- if(p->hasMetaData("UserException"))
- {
- ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
- if(!cl->isLocal())
- {
- ostringstream os;
- os << "ignoring invalid metadata `UserException': directive applies only to local operations "
- << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
- << "' is not local";
- emitWarning(p->file(), p->line(), os.str());
- }
- }
validate(p);
ParamDeclList params = p->parameters();
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index e9fac1fa5fb..6aee01c293b 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -1008,10 +1008,17 @@ Slice::JavaVisitor::writeMarshalServantResults(Output& out, const string& packag
}
void
-Slice::JavaVisitor::writeThrowsClause(const string& package, const ExceptionList& throws)
+Slice::JavaVisitor::writeThrowsClause(const string& package, const ExceptionList& throws, const OperationPtr& op)
{
Output& out = output();
- if(throws.size() > 0)
+
+ if(op && (op->hasMetaData("java:UserException") || op->hasMetaData("UserException")))
+ {
+ out.inc();
+ out << nl << "throws com.zeroc.Ice.UserException";
+ out.dec();
+ }
+ else if(throws.size() > 0)
{
out.inc();
out << nl << "throws ";
@@ -1137,14 +1144,14 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p)
{
out << nl << "java.util.concurrent.CompletionStage<" << getResultType(op, package, true, true) << "> "
<< op->name() << "Async" << spar << params << currentParam << epar;
- writeThrowsClause(package, throws);
+ writeThrowsClause(package, throws, op);
out << ';';
}
else
{
out << nl << getResultType(op, package, false, true) << ' ' << fixKwd(op->name()) << spar << params
<< currentParam << epar;
- writeThrowsClause(package, throws);
+ writeThrowsClause(package, throws, op);
out << ';';
}
}
@@ -1227,7 +1234,7 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p)
out << '_' << p->name() << "Disp";
}
out << " obj, final com.zeroc.IceInternal.Incoming inS, com.zeroc.Ice.Current current)";
- if(!op->throws().empty())
+ if(!op->throws().empty() || op->hasMetaData("java:UserException") || op->hasMetaData("UserException"))
{
out.inc();
out << nl << "throws com.zeroc.Ice.UserException";
@@ -2263,11 +2270,17 @@ Slice::JavaVisitor::writeServantDocComment(Output& out, const OperationPtr& p, c
out << nl << " * @return A completion stage that the servant will complete when the invocation completes.";
}
- // TBD: Check for UserException metadata
- for(map<string, string>::const_iterator i = dc->exceptions.begin(); i != dc->exceptions.end(); ++i)
+ if(p->hasMetaData("java:UserException") || p->hasMetaData("UserException"))
+ {
+ out << nl << " * @throws com.zeroc.Ice.UserException";
+ }
+ else
{
- out << nl << " * @throws " << fixKwd(i->first) << ' ';
- writeDocCommentLines(out, i->second);
+ for(map<string, string>::const_iterator i = dc->exceptions.begin(); i != dc->exceptions.end(); ++i)
+ {
+ out << nl << " * @throws " << fixKwd(i->first) << ' ';
+ writeDocCommentLines(out, i->second);
+ }
}
if(!dc->misc.empty())
@@ -2816,16 +2829,7 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p)
out << "public abstract ";
}
out << retS << ' ' << fixKwd(opname) << spar << params << epar;
- if(p->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws com.zeroc.Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, p);
out << ';';
//
@@ -5338,16 +5342,8 @@ Slice::Gen::ImplVisitor::writeOperation(Output& out, const string& package, cons
out << nl << "@Override";
out << nl << "public " << getResultType(op, package, false, false) << ' ' << fixKwd(opName) << spar << params
<< epar;
- if(op->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws com.zeroc.Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, op);
+
out << sb;
if(initResult(out, package, op))
{
@@ -5376,7 +5372,7 @@ Slice::Gen::ImplVisitor::writeOperation(Output& out, const string& package, cons
out << nl << "@Override";
out << nl << "public java.util.concurrent.CompletionStage<" << retS << "> " << opName << "Async" << spar
<< params << currentParam << epar;
- writeThrowsClause(package, throws);
+ writeThrowsClause(package, throws, op);
out << sb;
if(initResult(out, package, op))
{
@@ -5394,7 +5390,7 @@ Slice::Gen::ImplVisitor::writeOperation(Output& out, const string& package, cons
out << nl << "@Override";
out << nl << "public " << getResultType(op, package, false, true) << ' ' << fixKwd(opName) << spar << params
<< currentParam << epar;
- writeThrowsClause(package, throws);
+ writeThrowsClause(package, throws, op);
out << sb;
if(initResult(out, package, op))
{
diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h
index 5e6046bcd85..11c7d0f7e45 100644
--- a/cpp/src/slice2java/Gen.h
+++ b/cpp/src/slice2java/Gen.h
@@ -70,9 +70,10 @@ protected:
const std::string&);
//
- // Generate a throws clause containing only non-local exceptions.
+ // Generate a throws clause containing only checked exceptions.
+ // op is provided only when we want to check for the java:UserException metadata
//
- void writeThrowsClause(const std::string&, const ExceptionList&);
+ void writeThrowsClause(const std::string&, const ExceptionList&, const OperationPtr& op = 0);
//
// Generate code to compute a hash code for a type.
diff --git a/cpp/src/slice2java/GenCompat.cpp b/cpp/src/slice2java/GenCompat.cpp
index 9890c3c68f0..eb0a18ddc4c 100644
--- a/cpp/src/slice2java/GenCompat.cpp
+++ b/cpp/src/slice2java/GenCompat.cpp
@@ -797,10 +797,17 @@ Slice::JavaCompatVisitor::writeMarshalUnmarshalParams(Output& out, const string&
}
void
-Slice::JavaCompatVisitor::writeThrowsClause(const string& package, const ExceptionList& throws)
+Slice::JavaCompatVisitor::writeThrowsClause(const string& package, const ExceptionList& throws, const OperationPtr& op)
{
Output& out = output();
- if(throws.size() > 0)
+
+ if(op && (op->hasMetaData("java:UserException") || op->hasMetaData("UserException")))
+ {
+ out.inc();
+ out << nl << "throws Ice.UserException";
+ out.dec();
+ }
+ else if(throws.size() > 0)
{
out.inc();
out << nl << "throws ";
@@ -1224,16 +1231,8 @@ Slice::JavaCompatVisitor::writeDispatchAndMarshalling(Output& out, const ClassDe
<< typeToString(ret, TypeModeReturn, package, op->getMetaData(), true,
optionalMapping && op->returnIsOptional())
<< ' ' << opName << spar << params << epar;
- if(op->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, op);
+
out << sb << nl;
if(ret)
{
@@ -2519,16 +2518,7 @@ Slice::GenCompat::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurre
out << "Ice.Current " + currentParamName;
}
out << epar;
- if(op->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, op);
out << ';';
}
@@ -2738,16 +2728,8 @@ Slice::GenCompat::TypesVisitor::visitClassDefStart(const ClassDefPtr& p)
out << "public abstract ";
}
out << retS << ' ' << fixKwd(opname) << spar << params << epar;
- if(op->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, op);
+
out << ';';
//
@@ -5796,19 +5778,11 @@ Slice::GenCompat::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p)
}
out << epar;
- if((*r)->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws Ice.UserException";
- out.dec();
- }
- else
- {
- ExceptionList throws = (*r)->throws();
- throws.sort();
- throws.unique();
- writeThrowsClause(package, throws);
- }
+ ExceptionList throws = (*r)->throws();
+ throws.sort();
+ throws.unique();
+ writeThrowsClause(package, throws, *r);
+
out << sb;
out << nl;
if(ret && !hasAMD)
@@ -6054,7 +6028,7 @@ Slice::GenCompat::BaseImplVisitor::writeOperation(Output& out, const string& pac
#else
throws.sort(Slice::DerivedToBaseCompare());
#endif
- writeThrowsClause(package, throws);
+ writeThrowsClause(package, throws, op);
out << sb;
@@ -6116,17 +6090,7 @@ Slice::GenCompat::BaseImplVisitor::writeOperation(Output& out, const string& pac
ExceptionList throws = op->throws();
throws.sort();
throws.unique();
-
- if(op->hasMetaData("UserException"))
- {
- out.inc();
- out << nl << "throws Ice.UserException";
- out.dec();
- }
- else
- {
- writeThrowsClause(package, throws);
- }
+ writeThrowsClause(package, throws, op);
out << sb;
diff --git a/cpp/src/slice2java/GenCompat.h b/cpp/src/slice2java/GenCompat.h
index dde47bc772a..5f8ba85aa9d 100644
--- a/cpp/src/slice2java/GenCompat.h
+++ b/cpp/src/slice2java/GenCompat.h
@@ -64,9 +64,10 @@ protected:
const OperationPtr&, int&, bool, bool, bool, const std::string& = "", bool = false);
//
- // Generate a throws clause containing only non-local exceptions.
+ // Generate a throws clause containing only checked exceptions.
+ // op is provided only when we want to check for the java:UserException metadata
//
- void writeThrowsClause(const std::string&, const ExceptionList&);
+ void writeThrowsClause(const std::string&, const ExceptionList&, const OperationPtr& op = 0);
//
// Generate code to compute a hash code for a type.
diff --git a/cpp/src/slice2objc/ObjCUtil.cpp b/cpp/src/slice2objc/ObjCUtil.cpp
index 99f7f925098..92b4d1cc17f 100644
--- a/cpp/src/slice2objc/ObjCUtil.cpp
+++ b/cpp/src/slice2objc/ObjCUtil.cpp
@@ -1176,19 +1176,6 @@ Slice::ObjCGenerator::MetaDataVisitor::visitStructEnd(const StructPtr&)
void
Slice::ObjCGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
- if(p->hasMetaData("UserException"))
- {
- ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
- if(!cl->isLocal())
- {
- ostringstream os;
- os << "ignoring invalid metadata `UserException': directive applies only to local operations "
- << ": warning: metadata directive `UserException' applies only to local operations "
- << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
- << "' is not local";
- emitWarning(p->file(), p->line(), os.str());
- }
- }
validate(p);
}