Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Follow naming convention for parameter names in method docstrings #352

Merged
merged 6 commits into from
Feb 22, 2018
Merged
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
2 changes: 1 addition & 1 deletion src/source/CppGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
// Methods
for (m <- i.methods) {
w.wl
writeDoc(w, m.doc)
writeMethodDoc(w, m, idCpp.local)
val ret = marshal.returnType(m.ret, methodNamesInScope)
val params = m.params.map(p => marshal.paramType(p.ty, methodNamesInScope) + " " + idCpp.local(p.ident))
if (m.static) {
Expand Down
4 changes: 2 additions & 2 deletions src/source/JavaGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
val throwException = spec.javaCppException.fold("")(" throws " + _)
for (m <- i.methods if !m.static) {
skipFirst { w.wl }
writeDoc(w, m.doc)
writeMethodDoc(w, m, idJava.local)
val ret = marshal.returnType(m.ret)
val params = m.params.map(p => {
val nullityAnnotation = marshal.nullityAnnotation(p.ty).map(_ + " ").getOrElse("")
Expand All @@ -158,7 +158,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
}
for (m <- i.methods if m.static) {
skipFirst { w.wl }
writeDoc(w, m.doc)
writeMethodDoc(w, m, idJava.local)
val ret = marshal.returnType(m.ret)
val params = m.params.map(p => {
val nullityAnnotation = marshal.nullityAnnotation(p.ty).map(_ + " ").getOrElse("")
Expand Down
2 changes: 1 addition & 1 deletion src/source/ObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) {
if (i.ext.objc) w.wl(s"@protocol $self") else w.wl(s"@interface $self : NSObject")
for (m <- i.methods) {
w.wl
writeDoc(w, m.doc)
writeMethodDoc(w, m, idObjc.local)
writeObjcFuncDecl(m, w)
w.wl(";")
}
Expand Down
10 changes: 10 additions & 0 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import djinni.syntax.Error
import djinni.writer.IndentWriter
import scala.language.implicitConversions
import scala.collection.mutable
import scala.util.matching.Regex

package object generatorTools {

Expand Down Expand Up @@ -415,6 +416,15 @@ abstract class Generator(spec: Spec)

// --------------------------------------------------------------------------

def writeMethodDoc(w: IndentWriter, method: Interface.Method, ident: IdentConverter) {
val paramReplacements = method.params.map(p => (s"\\b${Regex.quote(p.ident.name)}\\b", s"${ident(p.ident.name)}"))
val newDoc = Doc(method.doc.lines.map(l => {
paramReplacements.foldLeft(l)((line, rep) =>
line.replaceAll(rep._1, rep._2))
}))
writeDoc(w, newDoc)
}

def writeDoc(w: IndentWriter, doc: Doc) {
doc.lines.length match {
case 0 =>
Expand Down
3 changes: 3 additions & 0 deletions test-suite/djinni/varnames.djinni
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ _varname_record_ = record {
}

_varname_interface_ = interface +c {
# We should also rewrite parameter names in docstrings.
# _r_arg_ should be rewritten.
# _i_arg_ should not.
_rmethod_(_r_arg_: _varname_record_): _varname_record_;
_imethod_(_i_arg_: _varname_interface_): _varname_interface_;
}
5 changes: 5 additions & 0 deletions test-suite/generated-src/cpp/_varname_interface_.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class VarnameInterface {
public:
virtual ~VarnameInterface() {}

/**
* We should also rewrite parameter names in docstrings.
* _r_arg_ should be rewritten.
* _i_arg_ should not.
*/
virtual VarnameRecord _rmethod_(const VarnameRecord & _r_arg_) = 0;

virtual std::shared_ptr<VarnameInterface> _imethod_(const std::shared_ptr<VarnameInterface> & _i_arg_) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import javax.annotation.Nonnull;

public abstract class VarnameInterface {
/**
* We should also rewrite parameter names in docstrings.
* RArg should be rewritten.
* _i_arg_ should not.
*/
@Nonnull
public abstract VarnameRecord Rmethod(@Nonnull VarnameRecord RArg);

Expand Down
5 changes: 5 additions & 0 deletions test-suite/generated-src/objc/DBVarnameInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

@interface DBVarnameInterface : NSObject

/**
* We should also rewrite parameter names in docstrings.
* RArg should be rewritten.
* _i_arg_ should not.
*/
- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)RArg;

- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)IArg;
Expand Down