« Return to Thread: [janino-dev] [jira] Created: (JANINO-91) Add support for returning tokens of whitespace

[janino-dev] [jira] Commented: (JANINO-91) Add support for returning tokens of whitespace

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View in Thread


    [ http://jira.codehaus.org/browse/JANINO-91?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=145630#action_145630 ]

Adam Heath commented on JANINO-91:
----------------------------------

But how do I then have static declarations?  I'd like to be able to create static helper methods, and static variables, inside the ScriptEvaluator.  Like this:

==
import java.util.HashMap;
import java.util.Map;

static final String CONSTANT_VALUE = "foobarbaz";
static Map toMap(Object[] args) {
    if (args.length % 2 != 0) throw new IllegalArgumentException("even number of args expected");
    Map result = new HashMap();
    for (int i = 0; i < args.length; ) {
        Object key = args[i++];
        Object value = args[i++];
        result.put(key, value);
    }
    return result;
}

webslinger.event("/Path/To/Event", toMap(new Object[] {"key", "value"}));
return null;
==

Additionally, the reason I needed the whitespace, is that when I parse the above, I remember the imports, find all leading static declarations, then save the rest; I then use string manipulation to insert the package and class name declarations, *without* changing any line numbers.  This latter is important, so that stack traces give correct line numbers, for debugging purposes.


> Add support for returning tokens of whitespace
> ----------------------------------------------
>
>                 Key: JANINO-91
>                 URL: http://jira.codehaus.org/browse/JANINO-91
>             Project: Janino
>          Issue Type: New Feature
>            Reporter: Adam Heath
>            Assignee: Arno Unkrig
>            Priority: Minor
>         Attachments: feature_swallowable_whitespace_comment_tokens.patch
>
>
> I have code that filters package/import stmts from source files, then wraps the remaining code in a class definition.  To keep line numbers identical after adding the class definition, I need to have comments and whitespace parsed an return to my application.  The attached patch does this.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: [janino-dev] [jira] Created: (JANINO-91) Add support for returning tokens of whitespace