kazuhira-r/velocity4s

Parentheses must be put in a method call

Closed this issue · 1 comments

parentheses So if unnecessary to call the val, and than may method call with no arguments also unnecessary parentheses?

example.

    val engine = ScalaVelocityEngine.create
    engine.addProperty(RuntimeConstants.RESOURCE_LOADER, "string")
    engine.addProperty("string.resource.loader.class", classOf[StringResourceLoader].getName)
    engine.init()

    val templateAsString = """|#foreach ($k in $map.keys())
                              |$map[$k]
                              |#end
                              |
                              |#foreach ($k in $map.keys)
                              |$map[$k]
                              |#end
                              |""".stripMargin
    val templateName = "template.vm"

    StringResourceLoader.getRepository.putStringResource(templateName, templateAsString)

    val context = new VelocityContext
    context.put("map", Map("key1" -> "value1", "key2" -> "value2"))

    val template = engine.getTemplate(templateName)

    val writer = new StringWriter
    template.merge(context, writer)
    println(writer)

result.

value1
value2


Foreach of the second has not been output.

This is a bug of ScalaMapGetExecutor probably.
I think if method of no arguments accessible was present in the property name when accessing a dot format to Map(ex. $map.method), that it may give priority to there.

For the behavior of def format without argument or val of Map not, check and add a test case separately.