diff --git a/functional-tests/functional/input/lime/CommentsLambda.lime b/functional-tests/functional/input/lime/CommentsLambda.lime new file mode 100644 index 0000000000..afa3192d37 --- /dev/null +++ b/functional-tests/functional/input/lime/CommentsLambda.lime @@ -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 +} diff --git a/gluecodium/src/main/java/com/here/gluecodium/generator/cpp/CppNameResolver.kt b/gluecodium/src/main/java/com/here/gluecodium/generator/cpp/CppNameResolver.kt index eaee2f5ab1..20adf28e15 100644 --- a/gluecodium/src/main/java/com/here/gluecodium/generator/cpp/CppNameResolver.kt +++ b/gluecodium/src/main/java/com/here/gluecodium/generator/cpp/CppNameResolver.kt @@ -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 @@ -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}") } diff --git a/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartNameResolver.kt b/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartNameResolver.kt index c1e490269d..a71aec4dfd 100644 --- a/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartNameResolver.kt +++ b/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartNameResolver.kt @@ -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 @@ -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}") } diff --git a/gluecodium/src/main/java/com/here/gluecodium/generator/swift/SwiftNameResolver.kt b/gluecodium/src/main/java/com/here/gluecodium/generator/swift/SwiftNameResolver.kt index 0c1aa7dea1..85f6315c1d 100644 --- a/gluecodium/src/main/java/com/here/gluecodium/generator/swift/SwiftNameResolver.kt +++ b/gluecodium/src/main/java/com/here/gluecodium/generator/swift/SwiftNameResolver.kt @@ -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 @@ -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}") } diff --git a/gluecodium/src/main/resources/templates/cpp/CppLambda.mustache b/gluecodium/src/main/resources/templates/cpp/CppLambda.mustache index 450199d2ee..192e4565ef 100644 --- a/gluecodium/src/main/resources/templates/cpp/CppLambda.mustache +++ b/gluecodium/src/main/resources/templates/cpp/CppLambda.mustache @@ -18,5 +18,5 @@ ! License-Filename: LICENSE ! !}} -{{>cpp/CppDocComment}}{{>cpp/CppAttributes}} +{{>cpp/CppFunctionDoc}}{{>cpp/CppAttributes}} using {{resolveName}} = {{>cpp/CppLambdaType}}; diff --git a/gluecodium/src/main/resources/templates/dart/DartLambda.mustache b/gluecodium/src/main/resources/templates/dart/DartLambda.mustache index bc7cf5ef01..b4fea57a86 100644 --- a/gluecodium/src/main/resources/templates/dart/DartLambda.mustache +++ b/gluecodium/src/main/resources/templates/dart/DartLambda.mustache @@ -18,7 +18,7 @@ ! License-Filename: LICENSE ! !}} -{{>dart/DartDocumentation}}{{>dart/DartAttributes}} +{{>dart/DartFunctionDocs}}{{>dart/DartAttributes}} typedef {{resolveName}} = {{>dart/DartLambdaType}}; // {{resolveName}} "private" section, not exported. diff --git a/gluecodium/src/main/resources/templates/swift/SwiftLambdaDefinition.mustache b/gluecodium/src/main/resources/templates/swift/SwiftLambdaDefinition.mustache index d35c2f3915..3a15886e9b 100644 --- a/gluecodium/src/main/resources/templates/swift/SwiftLambdaDefinition.mustache +++ b/gluecodium/src/main/resources/templates/swift/SwiftLambdaDefinition.mustache @@ -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}} diff --git a/lime-loader/src/main/antlr/LimeParser.g4 b/lime-loader/src/main/antlr/LimeParser.g4 index f14f977263..10183f8d0c 100644 --- a/lime-loader/src/main/antlr/LimeParser.g4 +++ b/lime-loader/src/main/antlr/LimeParser.g4 @@ -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 @@ -74,7 +74,7 @@ parameter ; returnType - : ':' NewLine* docComment* typeRef NewLine* + : NewLine* docComment* typeRef NewLine* ; throwsClause @@ -133,7 +133,7 @@ exception lambda : docComment* annotation* 'lambda' NewLine* simpleId NewLine* '=' NewLine* '(' NewLine* (lambdaParameter (',' NewLine* lambdaParameter)*)? ')' NewLine* - '->' NewLine* typeRef NewLine+ + '->' returnType ; lambdaParameter diff --git a/lime-loader/src/main/java/com/here/gluecodium/loader/AntlrLimeModelBuilder.kt b/lime-loader/src/main/java/com/here/gluecodium/loader/AntlrLimeModelBuilder.kt index 75d70ef1dc..f9430ba439 100644 --- a/lime-loader/src/main/java/com/here/gluecodium/loader/AntlrLimeModelBuilder.kt +++ b/lime-loader/src/main/java/com/here/gluecodium/loader/AntlrLimeModelBuilder.kt @@ -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)