Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder-style method is used instead of getter #421

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ case class ObjectContext(obj: Any) extends Context {
val methods = objClass.getMethods find (method => {
val methodName = method.getName
val returnType = method.getReturnType
methodName == name ||
val hasParameters = method.getParameterCount > 0

!hasParameters && (methodName == name ||
methodName == getGetterName(name) ||
((returnType == java.lang.Boolean.TYPE ||
returnType == classOf[java.lang.Boolean]) &&
methodName == getBooleanGetterName(name))
methodName == getBooleanGetterName(name)))
})

methods.map(_.invoke(obj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ class InterpreterBeanExpressionTest

}

it should "ignore getter method with arguments as field" in {

class A(x: Int) {
def getResult(y: Int): Int = x + y
}

eval("a.result", Map("a" -> new A(2))) should be(
ValError("context contains no entry with key 'result'")
)
}

it should "ignore method with arguments as field (builder-style)" in {

class A(x: Int) {
def plus(y: Int): A = new A(x + y)
}

eval("a.plus", Map("a" -> new A(2))) should be(
ValError("context contains no entry with key 'plus'")
)
}

it should "invoke a method without arguments" in {

class A { def foo() = "foo" }
Expand Down