Skip to content

Commit

Permalink
Work around RU array, nested class limits
Browse files Browse the repository at this point in the history
ReflectedUniverse has the following limitations:
* vararg parameters only accept arrays
* can't construct arrays
* can't import nested classes with a .
* since .'s can't be used, the enclosing classname has to be used to
  reference a nested class

All four of these limitations were affecting the setting of the ImgMode
in DefaultDatasetOpener#open.

These issues have now been resolved by use of java.lang.reflect.Array
and properly structured import statements.
  • Loading branch information
hinerm committed Dec 1, 2014
1 parent ca59fe0 commit e11b772
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/net/imagej/DefaultDatasetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,19 @@ public Dataset open(final String source, final Object config)
ru.exec("config.imgOpenerSetComputeMinMax(false)");

// prefer planar array structure, for ImageJ1 and ImgSaver compatibility
ru.exec("import io.scif.config.SCIFIOConfig.ImgMode;");
ru.exec("config.imgOpenerSetImgModes(ImgMode.PLANAR);");

ru.exec("imgPluses = imageOpener.openImgs(source, config);");
return create((ImgPlus) ru.exec("imgPluses.get(0);"));
ru.exec("import io.scif.config.SCIFIOConfig$ImgMode");
//TODO
// we cannot construct new arrays manually since the ReflectedUniverse
// only looks for parenthesees. We should probably move this to a utility
// method of the RU if we're going to keep it around.
ru.exec("import java.lang.reflect.Array");
ru.exec("mode = SCIFIOConfig$ImgMode.PLANAR");
ru.exec("modeArray = Array.newInstance(SCIFIOConfig$ImgMode, 1)");
ru.exec("Array.set(modeArray, 0, mode)");
ru.exec("config.imgOpenerSetImgModes(modeArray)");

ru.exec("imgPluses = imageOpener.openImgs(source, config)");
return create((ImgPlus) ru.exec("imgPluses.get(0)"));
}
catch (final ReflectException exc) {
throw new IOException(exc);
Expand Down

0 comments on commit e11b772

Please sign in to comment.