Re:equivalence of Reflection-Method Selector in AS-was Scripter
Re:equivalence of Reflection-Method Selector in AS-was Scripter
- Subject: Re:equivalence of Reflection-Method Selector in AS-was Scripter
- From: "Jason W. Bruce" <email@hidden>
- Date: Tue, 14 Nov 2000 00:33:17 -0600
Anthony, I took a stab at this, but couldn't figure out how to ask a script
to return its handlers. Though much less efficient, the script below will
display handlers in a script object which match an input string and then
execute the chosen handler using run script. Good luck on your project. I
am very interested in what you are working on and hope you share your
results.
Jason Bruce
_______________
script HandlerPicker
to beep2()
beep 2
end beep2
to beep3()
beep 3
end beep3
to beep4()
beep 4
end beep4
to sing()
beep 5
end sing
set handlerlist to {}
display dialog "Please Enter Search String" default answer ""
set searchstring to text returned of the result
repeat with loopvariable in {beep2, beep3, beep4, sing}
try
x of loopvariable
on error errorstring
if searchstring is in word 6 of errorstring then
set end of handlerlist to word 6 of errorstring
end if
end try
end repeat
choose from list handlerlist
set handlerchoice to the result
return handlerchoice
end script
tell HandlerPicker to run
set handlerchoice to the result
set newscriptobject to "script HandlerScript
to beep2()
beep 2
end beep2
to beep3()
beep 3
end beep3
to beep4()
beep 4
end beep4
to sing()
beep 5
end sing
end script" & "
tell HandlerScript to " & handlerchoice & "()"
run script newscriptobject
----------
>
Date: 11 Nov 2000 18:14:58 -0500
>
Subject: equivalence of Reflection-Method Selector in AS-was Scripter
>
(The Program)
>
From: "Anthony Adachi" <email@hidden>
>
To: email@hidden
>
>
I've been following this thread and the "Script libraries in Applescript"
>
in the MACSCRPT mailing list with great interest as I'm been trying to
>
translate an Open Source testing framework into AppleScript but I've run
>
into a couple of stumbling blocks.
>
>
This framework, JUnit (which is part of the xUnit family of testing
>
frameworks), allows one to make automated tests of Java code. JUnit is
>
itself based on, I believe it's called SUnit, which is for Smalltalk.
>
>
JUnit link: http://www.junit.org
>
xUnit downloads: http://www.XProgramming.com/software.htm
>
>
The major stumbling block I've run into is that JUnit partly relies on
>
"Reflection" to find out which test methods (i.e.-handlers) the coder
>
(i.e.-scripter) wants to run.
>
>
Apparently, Java and Smalltalk have a way to find out what messages an
>
object understands (i.e.-the methods contained in the object) through
>
"Reflection". Smalltalk has something called a "method selector" which
>
allows one to choose and invoke a particular method.
>
>
Is there a way to find out what handlers are available in a script object?
>
Or is there a way to select and call a handler in a script object based on
>
it's name. For example, make a list of handlers whose names start with
>
"test"? Or select and call a hanlder whose name is "test_equality"?
>
>
I'm trying to avoid having to create a Associated list or two syncronized
>
lists as in Richard 23's examples.
>
>
script myTestCase
>
>
on TestThis(theStr)
>
{TestThis:theStr}
>
end TestThis
>
>
on TestThat(theStr)
>
{TestThat:theStr}
>
end TestThat
>
>
on TestOther(theStr)
>
{TestOther:theStr}
>
end TestOther
>
>
property handler_nameList : {"[1] TestThis", "[2] TestThat", "[3]
>
TestOther"}
>
property handler_referenceList : {TestThis, TestThat, TestOther}
>
end script
>
>
Basically, I want to be able to build a list of avaliable handlers in an
>
object on the fly and allow one to choose which one to execute. Or have the
>
testing framework able to execute a specific handler given it's name in
>
string form. Or to execute all handlers whose name begin with a certain
>
prefix or suffix such as, "test".
>
>
By the way, I'm just beginning to learn Java so I'm not familare with the
>
langauge (which isn't exactly making my life easier as far as the
>
translation bit is concerned).
>
>
Thanks,
>
>
Anthony Adachi