Skip to content

Commit

Permalink
Lenses reserved word fix (#539)
Browse files Browse the repository at this point in the history
lenses generation now checks for reserved words
  • Loading branch information
deenar authored Oct 16, 2020
1 parent 02bacbc commit a1c99e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cli/src/main/scala/scalaxb/compiler/xsd/GenLens.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scalaxb.compiler.xsd

import scalaxb.compiler.Config
import scalaxb.compiler.{Config, ScalaNames}

trait GenLens { self: ContextProcessor =>
def buildImport: String
Expand Down Expand Up @@ -32,6 +32,8 @@ trait GenLens { self: ContextProcessor =>
* @param config
*/
class GenMonocleLens(var config: Config) extends GenLens with ContextProcessor {
lazy val scalaNames: ScalaNames = new ScalaNames {}
def escapeKeyWord(name: String) = if(scalaNames.isKeyword(name)) s"`$name`" else name

def buildImport: String = {
""
Expand All @@ -40,7 +42,7 @@ class GenMonocleLens(var config: Config) extends GenLens with ContextProcessor {
def buildDefLens(className : String, param: Params#Param) : String = {
s"def ${param.toParamName}: monocle.Lens[$className, ${param.typeName}] = " +
s"monocle.Lens[$className, ${param.typeName}](_.${param.toParamName})" +
s"((_${param.toParamName}: ${param.typeName}) => (${className.toLowerCase}: $className) => ${className.toLowerCase}.copy(${param.toParamName} = _${param.toParamName}))"
s"((_${param.toParamName}: ${param.typeName}) => (${escapeKeyWord(className.toLowerCase)}: $className) => ${escapeKeyWord(className.toLowerCase)}.copy(${param.toParamName} = _${param.toParamName}))"
}

def buildDefComposeLens(className : String, param: Params#Param) : String = {
Expand Down
6 changes: 6 additions & 0 deletions integration/src/test/resources/ipo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,10 @@
</extension>
</simpleContent>
</complexType>

<complexType name="Case">
<sequence>
<element type="string" name="Id"/>
</sequence>
</complexType>
</schema>

0 comments on commit a1c99e8

Please sign in to comment.