beanshell / beanshell

Beanshell scripting language
Apache License 2.0
815 stars 183 forks source link

What qualifies as a scripted object? #733

Open opeongo opened 1 year ago

opeongo commented 1 year ago

Scripted objects are method declarations that return a reference to a namespace. Typically they are coded as:

apple(String variety, int grade) {
    type = "apple";
    return this;
}

But what about method declaration that return a namespace reference indirectly. Do these also count as scripted objects?

apple(String variety, int grade) {
    type = "apple";
    return this;
}

apple(String variety) {
    return apple(variety, -1);
}

apple(String variety, String letterGrade) {
    if ("A".equalsIgnoreCase(letterGrade))
        return apple(variety, 1);
    else if ("B".equalsIgnoreCase(letterGrade))
        return apple(variety, 2);
    else
        return apple(variety, -1);
}

Do we need to adjust the code that detects if a method is a scripted object to detect all of these other cases?

nickl- commented 1 year ago

I would say no.

The first method apple1 is a scripted object, apple2 and apple3 only returns the object apple1, which doesn't give them object scope within themselves in return.

Interesting problem, forced me to think for a minute.

Closed: works as expected