Skip to content

Script values #163

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

Merged
merged 5 commits into from
May 1, 2015
Merged

Script values #163

merged 5 commits into from
May 1, 2015

Conversation

ctrueden
Copy link
Member

This branch makes default values work better:

  • It gives the ModuleItem a default value property which can be retrieved and (in the case of MutableModuleItem) set.
  • It uses that property for the default value, via a new DefaultValuePreprocessor. This eliminates the inconsistency between default value handling of primitives and their java.lang wrapper types.
  • It adds a value attribute to script parameter parsing, so that you can write e.g. @int(value=5) sigma to set a default value for script parameters. (Ideally, we'd support @int sigma = 5 too, but for the moment that would be more work, so we can punt for now.)

The ModuleItem#getDefaultValue() method returns the intended default
value for the item, or null if none such.

And the MutableModuleItem#setDefaultValue(T) method lets it be set.

Of course, as of this commit, nothing respects the setting yet.
When calling ModuleService#getDefaultValue(ModuleItem), if the
ModuleItem in question has an explict default value -- as obtained
from the new ModuleItem#getDefaultValue() accessor -- then that
value should take precedence over any other possibility.
@ctrueden ctrueden force-pushed the script-values branch 2 times, most recently from e0e4663 to d3f0040 Compare April 30, 2015 20:07
Unresolved module items should be assigned their default value,
as given by the ModuleService#getDefaultValue() method, before
anything else (even module initialization!) happens.
You can now write:

  @int(value = 5) sigma

And the sigma variable will have a default value of 5 the first time
the script is run.

Nicer would be:

  @int sigma = 5

But implementing that would be more involved, and so should probably
wait till script parameter parsing is truly fixed as described in #156.
@ctrueden
Copy link
Member Author

@hinerm Just looking for quick code review, then feel free to merge! In conjuction with scijava/scijava-ui-swing#11, this fixes default value handling as discussed recently on the mailing list.

hinerm added a commit that referenced this pull request May 1, 2015
Add default value support for module items and script parameters
@hinerm hinerm merged commit 6d4c785 into master May 1, 2015
@hinerm
Copy link
Member

hinerm commented May 1, 2015

Awesome @ctrueden ! 🐙

@ctrueden ctrueden deleted the script-values branch May 1, 2015 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants