From: René J. <rvj...@xs...> - 2023-02-12 15:45:44
|
Hi Jeff, I checked in a working help stage. My conjecture: somehow we confused the compiler by naming both the class 'help' and the method 'help'. The latter returns a type Rexx. My first reflex was to call your class 'helo' and then it works when starting a pipe "helo crc | cons" but because 'helo' is not a good name for a help stage, I renamed it back, and changed the help() method on class stage and class crc to 'giveHelp'. Somehow someone took a shortcut somewhere. Line 50 must be from the generated stage source. Do we accept this or do we open an issue to go to the bottom? best regards, René. > On 12 Feb 2023, at 14:31, Jeff Hennick <Je...@Je...> wrote: > > René, > > Thank you. > > At the moment, I am still pursuing the previous way, but running into a problem. > > Your code worked for me. ONCE. Now it doesn't, in a way I do not understand. > > First, there were some exceptions that needed attention. These I now CATCH. > > So here first is my code, then the results. > > -- help.nrx NJPipe Stage > /* > * Copyright (C) 2023 Jeffrey Hennick, Jeff @ Jeff-H . com > * Distributed under the ICU 1.8.1 License with NO WARRANTIES of ANY kind. > * See LICENSE for the license and information on using, copying, modifying, > * and distributing this program. > */ > /* > */ > > options nostrictcase nostrictargs nostrictsignal > package org.netrexx.njpipes.stages > > import org.netrexx.njpipes.pipes. > > class help extends stage binary > > trace results > > method run() > > parse arg() stage_to_help . > if stage_to_help = '' then > say "Usage: HELP stage_name." > else if stage_to_help = 'HELP' then > say helphelp() > else do > stageClass = class.forName('org.netrexx.njpipes.stages.'stage_to_help) > helpMethod = stageClass.getMethod('help',null) > say helpMethod.invoke(stageClass,null) > catch java.lang.ClassNotFoundException > Emsg(11, "Stage" stage_to_help "was not found.") > catch java.lang.NoSuchMethodException > Emsg(11, "No Help was found for Stage" stage_to_help".") > catch java.lang.IllegalAccessException > Emsg(11, "Illegal Access.") > catch java.lang.reflect.InvocationTargetException > Emsg(11, "Reflection Invocation Target Error.") > end > > loop forever > aobj = peekto() > output(aobj) > readto() > catch StageError > end > > rc = mrc() > exit(rc*(rc<>12)) > > method helphelp() static > return - > "/** help\n" - > " \n" - > " >>--+-HELP--+--------+----------------------->< \n" - > " | +-string-+ \n" - > " \n" - > "*/\n" > > > > PS C:\Users\Jeff\Documents\nr\netrexx-code\examples\pipes> pipe "help find" > 50 +++ _s_1 = help() > +++ ^^^^ > +++ Error: Cannot convert value of type 'netrexx.lang.Rexx' for assignment t > o variable of type 'org.netrexx.njpipes.pipes.stage' > NetRexx portable processor 4.05-beta build 1,005-20230212-0754 > Copyright (c) RexxLA, 2011,2023. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program pebe3cec > === class pebe3cec === > constructor pebe3cec(Object) > overrides pipe() > method reset > function get(Object) > method setup(Object) > 50 +++ _s_1 = help() > +++ ^^^^ > +++ Error: Cannot convert value of type 'netrexx.lang.Rexx' for assignment t > o variable of type 'org.netrexx.njpipes.pipes.stage' > method config > method setup2 > method run > signals ThreadQ > overrides stage.run > function main(String[]) > signals ThreadQ > Compilation of 'pebe3cec' failed [one error] > Compilation failed. > PS C:\Users\Jeff\Documents\nr\netrexx-code\examples\pipes> > I don't know where the line "50" is. My 50 is a blank line, but the error message stays the same when I added blank lines above it. > > It does not matter what stage name I ask for the help. > > Trying from the "raw" PowerShell prompt or in NRWS; with and without quote marks, has made no difference. > > Thanks for any insight. > > Jeff > > On 2/11/2023 8:13 AM, René Jansen wrote: >> rerouted answer to pipelines list: >> >> Jeff, >> >> we have an INSIDE stage, so I would skip all quoting and continuing and pick the right lines out of a file with INSIDE - then you can use the class-level help() to call super.help(stage) and have that deliver the lines. >> (In there we can test the terminal for graphic ability and deliver the optimal graphics - more than one terminal can do SVG nowadays). >> >> best regards, >> >> René. >> >>> On 11 Feb 2023, at 13:34, Jeffrey Hennick <Je...@Je...> <mailto:Je...@Je...> wrote: >>> >>> Looks great. I'll explore it more later today. Then get to the stage files. Most of them have the railroad diagram in a comment, so it means moving that to the new help() method. I do wish NetRexx had a multi-line quote for this, but adding quote marks and a continuation character to each line should do the trick. (The help stage will need some special work so this method is not taken as a constructor.) >>> >>> Thanks! >>> >>> Jeff >>> >>> On 2/10/2023 4:50 PM, rvj...@xs... <mailto:rvj...@xs...> wrote: >>>> And you should use getMethod instead of getDeclaredMethod if you want to inherit the help() from stage - the superclass, for stages that don't have helping yet: >>>> >>>> parse arg stage_to_help >>>> stageClass = class.forName('org.netrexx.njpipes.stages.'stage_to_help) >>>> helpMethod = stageClass.getMethod('help',null) >>>> say helpMethod.invoke(stageClass,null) >>>> >>>> best regards, >>>> >>>> René. >>>>> On 10 Feb 2023, at 22:43, rvj...@xs... <mailto:rvj...@xs...> wrote: >>>>> >>>>> Hi Jeff, >>>>> >>>>> I think this is the best solution for the moment: We know that the stages package is available. We can load the stage class with the Java Reflection API, and then call (invoke) the help() method on it: >>>>> >>>>> ➜ test git:(master) ✗ cat loadhelp.nrx >>>>> parse arg stage_to_help >>>>> stageClass = class.forName('org.netrexx.njpipes.stages.'stage_to_help) >>>>> helpMethod = stageClass.getDeclaredMethod('help',null) >>>>> say helpMethod.invoke(stageClass,null) >>>>> >>>>> ➜ test git:(master) ✗ java loadhelp crc >>>>> The CRC stage computes a CRC-32 checksum over its input. >>>>> >>>>> So you pass in the (short) stage name, complete its name in the class.forName method, which leave a Class object in variable stageClass. We ask that Class object to return the help() method in the variable helpMethod. On that, we invoke it with no parameters, it returns the help message from the static help() method. >>>>> >>>>> best regards, >>>>> >>>>> René. >>>>> >>>>>> On 10 Feb 2023, at 16:14, rvj...@xs... <mailto:rvj...@xs...> wrote: >>>>>> >>>>>> and with that I mean the example below-below. >>>>>> >>>>>>> On 10 Feb 2023, at 16:08, rvj...@xs... <mailto:rvj...@xs...> wrote: >>>>>>> >>>>>>> Hi Jeff, >>>>>>> >>>>>>> I added a static help() method to pipes.stage . I also did override that method on the new crc stage; this just to show. >>>>>>> >>>>>>> Now about enumeration of the stages: we have several approaches. We could, at NetRexx build time, enumerate all the built-in stages into a structure. That might be the most efficient and straigtforward way. We could also do that dynamically; if the compiler can do it, we also could. This might be more involved and would take slightly longer. >>>>>>> >>>>>>> The example below does not work because you need to instantiate the stage before you can call methods on it. >>>>>>> >>>>>>> ➜ test git:(master) ✗ cat stagehelp.nrx >>>>>>> import org.netrexx.njpipes.stages. >>>>>>> x = find() >>>>>>> say x.help() >>>>>>> y = crc() >>>>>>> say y.help() >>>>>>> ➜ test git:(master) ✗ nrc stagehelp.nrx >>>>>>> NetRexx portable processor 4.05-beta build 372-20230210-1550 >>>>>>> Copyright (c) RexxLA, 2011,2023. All rights reserved. >>>>>>> Parts Copyright (c) IBM Corporation, 1995,2008. >>>>>>> Program stagehelp.nrx >>>>>>> Compilation of 'stagehelp.nrx' successful >>>>>>> ➜ test git:(master) ✗ java stagehelp >>>>>>> for this stage no help is available yet >>>>>>> The CRC stage computes a CRC-32 checksum over its input. >>>>>>> ➜ test git:(master) ✗ >>>>>>> >>>>>>> >>>>>>> best regards, >>>>>>> >>>>>>> René >>>>>>> >>>>>>>> On 10 Feb 2023, at 09:17, rvj...@xs... <mailto:rvj...@xs...> wrote: >>>>>>>> >>>>>>>> Hi Jeff, >>>>>>>> >>>>>>>> if you want each stage to have a help() method, you should add it to the stage class itself. On each subclass of stage (the stages) you can then override the help() method - in stage.help() itself, you can state there is no specific help yet or have some other generic message. >>>>>>>> >>>>>>>> If you want to call these from another class, you should have an instance of a stage and then call its help(). Using reflective loading, you should be able to load these from the jar. >>>>>>>> Java has no easier way to ‘give me all subclasses of a class.’ >>>>>>>> >>>>>>>> I’ll try to make an example as soon as the coffee starts working. >>>>>>>> >>>>>>>> best regards, >>>>>>>> >>>>>>>> René. >>>>>>>> >>>>>>>> >>>>>>>>> On 9 Feb 2023, at 21:20, Jeffrey Hennick <Je...@Je...> <mailto:Je...@Je...> wrote: >>>>>>>>> >>>>>>>>> I am attempting to make a HELP stage for pipelines. This would give info about any given stage. I would like, for ease of maintenance, store this help information in the stage's file, rather than a central "database." >>>>>>>>> >>>>>>>>> My naive approach is to add a help() method that returns a long string with the information to each stage source file. For testing I have such in the find.nrx, and it compiles nicely. >>>>>>>>> >>>>>>>>> I can call that method from within the find stage and it displays the information with, for now, say help(). >>>>>>>>> >>>>>>>>> What I have not been successful at is calling it from another class file, specifically help.nrx. >>>>>>>>> >>>>>>>>> Both stage files have these in the header section >>>>>>>>> >>>>>>>>> options nostrictcase nostrictargs nostrictsignal >>>>>>>>> package org.netrexx.njpipes.stages >>>>>>>>> >>>>>>>>> import org.netrexx.njpipes.pipes. >>>>>>>>> >>>>>>>>> class help [or find] extends stage binary >>>>>>>>> >>>>>>>>> method run() >>>>>>>>> >>>>>>>>> the help continues >>>>>>>>> >>>>>>>>> >>>>>>>>> parse arg() stage . >>>>>>>>> h = stage.help() >>>>>>>>> say h >>>>>>>>> >>>>>>>>> loop forever >>>>>>>>> aobj = peekto() >>>>>>>>> output(aobj) >>>>>>>>> readto() >>>>>>>>> catch StageError >>>>>>>>> end >>>>>>>>> >>>>>>>>> rc = mrc() >>>>>>>>> exit(rc*(rc<>12)) >>>>>>>>> >>>>>>>>> Whit this, when I compile, I get this error message: >>>>>>>>> >>>>>>>>> [buildnrc] Program help.nrx >>>>>>>>> [buildnrc] [C:\Users\Jeff\Documents\nr\netrexx-code\build\classes\org\netrexx\n >>>>>>>>> jpipes\stages\help.nrx 22 11 4] Error: The method 'help()' cannot be found in cl >>>>>>>>> ass 'netrexx.lang.Rexx' or a superclass >>>>>>>>> >>>>>>>>> BUILD FAILED >>>>>>>>> >>>>>>>>> What is the correct wording to call the help() method in the "stage" class, where in my test case stage is "find". I don't know how to make it clear the the "stage" in "stage.help()" is a variable. >>>>>>>>> >>>>>>>>> Thanks for any pointers -- or ideas to get around this. >>>>>>>>> >>>>>>>>> Jeff >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >>> _._,_._,_ >>> Groups.io Links: >>> You receive all messages sent to this group. >>> >>> View/Reply Online (#339) <https://groups.io/g/netrexx/message/339> | Reply To Group <mailto:ne...@gr...?subject=Re:%20Re%3A%20%5Bnetrexx%5D%20Calling%20a%20method%20in%20another%2C%20variable%2C%20class> | Reply To Sender <mailto:Je...@Je...?subject=Private:%20Re:%20Re%3A%20%5Bnetrexx%5D%20Calling%20a%20method%20in%20another%2C%20variable%2C%20class> | Mute This Topic <https://groups.io/mt/96861952/5057901> | New Topic <https://groups.io/g/netrexx/post> >>> Your Subscription <https://groups.io/g/netrexx/editsub/5057901> | Contact Group Owner <mailto:net...@gr...> | Unsubscribe <https://groups.io/g/netrexx/leave/10808172/5057901/1344565786/xyzzy> [pre...@re... <mailto:pre...@re...>] >>> >>> _._,_._,_ >> >> >> >> >> _______________________________________________ >> netrexx-pipelines mailing list >> net...@li... <mailto:net...@li...> >> https://lists.sourceforge.net/lists/listinfo/netrexx-pipelines > _______________________________________________ > netrexx-pipelines mailing list > net...@li... > https://lists.sourceforge.net/lists/listinfo/netrexx-pipelines |