diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/CHANGES | 40 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 49 |
2 files changed, 88 insertions, 1 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 769ac6db837..41bece6c30d 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -8,6 +8,46 @@ Changes since version 1.5.1 error and output streams of a process. Reimplemented IcePack's error/output redirection using these properties. +- For classes with operations, the code generator now generates + overloaded methods for each operation, one exactly as before, + and another one without the trailing Ice.Current parameter. + For example: + + // Slice + class Foo + { + void op(); + }; + + // Java + public abstract class Foo extends Ice.ObjectImpl + implements _FooOperations, _FooOperationsNC + { + public final void + op() + { + op(null); + } + } + + public interface _FooOperations + { + void op(Ice.Current __current); + } + + public interface _FooOperationsNC + { + void op(); + } + + This changes allows you to call an operation on a class without having + to supply a null dummy argument: + + Foo f = new FooI(); + f.op(null); // Previously, null had to be passed. This still works. + f.op(); // OK as of now. + + Changes since version 1.5.0 --------------------------- diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 45445c572f7..a5cba9738d0 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -491,7 +491,54 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p) throws.sort(Slice::DerivedToBaseCompare()); #endif - if(cl == p || cl->isInterface()) + // + // Only generate a "no current" version of the operation if it hasn't been done in a base + // class already, because the "no current" version is final. + // + bool generateOperation = cl == p; // Generate if the operation is defined in this class. + if(!generateOperation) + { + // + // The operation is not defined in this class. + // + ClassList bases = p->bases(); + if(!bases.empty()) + { + // + // Check if the operation is already implemented by a base class. + // + bool implementedByBase = false; + if(!bases.front()->isInterface()) + { + OperationList baseOps = bases.front()->allOperations(); + OperationList::const_iterator i; + for(i = baseOps.begin(); i != baseOps.end(); ++i) + { + if((*i)->name() == op->name()) + { + implementedByBase = true; + break; + } + } + if(i == baseOps.end()) + { + generateOperation = true; + } + } + if(!generateOperation && !implementedByBase) + { + // + // No base class defines the operation. Check if one of the + // interfaces defines it, in which case this class must provide it. + // + if(bases.front()->isInterface() || bases.size() > 1) + { + generateOperation = true; + } + } + } + } + if(generateOperation) { out << sp << nl << "public final " << typeToString(ret, TypeModeReturn, package) << nl << opName << spar << params << epar; |