Skip to content

Commit

Permalink
Add documentation support of lambda parameters and return value
Browse files Browse the repository at this point in the history
  • Loading branch information
limingchina committed Aug 4, 2023
1 parent 1c36362 commit 849865c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 10 deletions.
9 changes: 9 additions & 0 deletions functional-tests/functional/input/lime/CommentsLambda.lime
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test

class CommentsLambda {
// This is a comment for lambda
// @param[p0] This is the comment for the first parameter of the lambda.
// @param[p1] This is the comment for the second parameter of the lambda.
lambda MyCallback = (@Java("param1_name") Int?, @Java("param2_name") String)
-> /*Comment for return value*/ Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.SETTER_NA
import com.here.gluecodium.model.lime.LimeField
import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -84,6 +85,7 @@ internal class CppNameResolver(
is LimeType -> resolveTypeName(element, isFullName = false)
is LimeTypeRef -> resolveTypeRef(element)
is LimeReturnType -> resolveTypeRef(element.typeRef)
is LimeLambdaParameter -> resolveTypeRef(element.typeRef)
is LimeNamedElement -> nameCache.getName(element)
else -> throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.here.gluecodium.model.lime.LimeEnumerator
import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.IMPORT_PATH_NAME
import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -86,6 +87,7 @@ internal class DartNameResolver(
is LimeTypeAlias -> resolveName(element.typeRef)
is LimeType -> resolveTypeName(element)
is LimeNamedElement -> getPlatformName(element)
is LimeLambdaParameter -> resolveTypeRefName(element.typeRef)
else ->
throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeInterface
import com.here.gluecodium.model.lime.LimeLambda
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -75,6 +76,7 @@ internal class SwiftNameResolver(
is LimeTypeRef -> resolveTypeRefName(element)
is LimeReturnType -> resolveTypeRefName(element.typeRef)
is LimeNamedElement -> nameRules.getName(element)
is LimeLambdaParameter -> resolveTypeRefName(element.typeRef)
else -> throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
! License-Filename: LICENSE
!
!}}
{{>cpp/CppDocComment}}{{>cpp/CppAttributes}}
{{>cpp/CppFunctionDoc}}{{>cpp/CppAttributes}}
using {{resolveName}} = {{>cpp/CppLambdaType}};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
! License-Filename: LICENSE
!
!}}
{{>dart/DartDocumentation}}{{>dart/DartAttributes}}
{{>dart/DartFunctionDocs}}{{>dart/DartAttributes}}
typedef {{resolveName}} = {{>dart/DartLambdaType}};

// {{resolveName}} "private" section, not exported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
! License-Filename: LICENSE
!
!}}
{{>swift/SwiftComment}}{{>swift/SwiftAttributes}}
{{>swift/SwiftFunctionComment}}{{>swift/SwiftAttributes}}
{{#unless isInterface}}{{resolveName "visibility"}} {{/unless}}typealias {{resolveName}} = {{!!
}}({{#parameters}}{{#unless typeRef.isNullable}}{{#instanceOf typeRef.type.actualType "LimeLambda"}}@escaping {{/instanceOf}}{{/unless}}{{!!
}}{{resolveName typeRef}}{{#if iter.hasNext}}, {{/if}}{{/parameters}}) -> {{resolveName returnType}}
6 changes: 3 additions & 3 deletions lime-loader/src/main/antlr/LimeParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ parentTypes
function
: docComment* annotation* ('static' NewLine*)? 'fun' NewLine* simpleId NewLine*
'(' NewLine* (parameter (',' NewLine* parameter)*)? ')' NewLine*
returnType? throwsClause? NewLine*
':' returnType? throwsClause? NewLine*
;

constructor
Expand All @@ -74,7 +74,7 @@ parameter
;

returnType
: ':' NewLine* docComment* typeRef NewLine*
: NewLine* docComment* typeRef NewLine*
;

throwsClause
Expand Down Expand Up @@ -133,7 +133,7 @@ exception
lambda
: docComment* annotation* 'lambda' NewLine* simpleId NewLine* '=' NewLine*
'(' NewLine* (lambdaParameter (',' NewLine* lambdaParameter)*)? ')' NewLine*
'->' NewLine* typeRef NewLine+
'->' returnType
;

lambdaParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,19 @@ internal class AntlrLimeModelBuilder(
)
)
}
val returnType = ctx.returnType()
?.let {
LimeReturnType(
typeMapper.mapTypeRef(currentPath, it.typeRef()),
getComment("return", it.docComment(), it)
)
} ?: LimeReturnType.VOID
val limeElement = LimeLambda(
path = currentPath,
comment = parseStructuredComment(ctx.docComment(), ctx).description,
attributes = AntlrLimeConverter.convertAnnotations(currentPath, ctx.annotation()),
parameters = parameters,
returnType = LimeReturnType(
typeMapper.mapTypeRef(currentPath, ctx.typeRef()),
getComment("return", null, ctx)
)
returnType = returnType
)

storeResultAndPopStacks(limeElement)
Expand Down

0 comments on commit 849865c

Please sign in to comment.