Skip to content
Permalink
Browse files

Quote illegal identifiers in generated Scala sources.

Fixes #1009
  • Loading branch information
szeiger committed Jan 23, 2015
1 parent 58c4ed5 commit 62d5e922806f46d7ffaba661df33b3b060b03f8e
@@ -212,6 +212,12 @@ trait StringGeneratorHelpers extends scala.slick.codegen.GeneratorHelpers[String
def docWithCode(doc: String, code:String): String = (if(doc != "") "/** "+doc.split("\n").mkString("\n * ")+" */\n" else "") + code
final def optionType(t: String) = s"Option[$t]"
def parseType(tpe: String): String = tpe
def termName( name: String ) = if(scalaKeywords.contains(name)) "`"+name+"`" else name
def typeName( name: String ) = if(scalaKeywords.contains(name)) "`"+name+"`" else name
def shouldQuoteIdentifier(s: String) = {
def isIdent =
if(s.isEmpty) false
else Character.isJavaIdentifierStart(s.head) && s.tail.forall(Character.isJavaIdentifierPart)
scalaKeywords.contains(s) || !isIdent
}
def termName( name: String ) = if(shouldQuoteIdentifier(name)) "`"+name+"`" else name
def typeName( name: String ) = if(shouldQuoteIdentifier(name)) "`"+name+"`" else name
}
@@ -176,9 +176,9 @@ lazy val database = Database.forURL(url=""\"$url""\",driver="$jdbcDriver",user="

class Tables(val profile: JdbcProfile){
import profile.api._
/** Tests single column table, scala keyword type name and all nullable columns table*/
/** Tests single column table, scala keyword type name, non-dentifier column name and all nullable columns table*/
class `null`(tag: Tag) extends Table[Option[String]](tag, "null") {
def name = column[Option[String]]("name")
def name = column[Option[String]]("na me")
def * = name
}
val `null` = TableQuery[`null`]

0 comments on commit 62d5e92

Please sign in to comment.
You can’t perform that action at this time.