REPL code review -- MemoryFileManager
Robert Field
robert.field at oracle.com
Mon Sep 21 15:11:05 UTC 2015
Fix pushed.
-Robert
On 09/19/15 14:38, Robert Field wrote:
>
> On 09/11/15 08:25, Maurizio Cimadamore wrote:
>>
>> * MemoryFileManager
>>
>> - Maybe the code of 'list' could be more optimized/lazy by
>> returning a compound iterator - i.e. an iterator that keeps scanning
>> the items in the first iterator and, when finished moves onto the
>> next iterator.
>
> How's this? It could be more or less lazy: "it" could be pre-filled,
> or "stdList" could be called at the last minute.
>
> @Override
> public Iterable<JavaFileObject> list(JavaFileManager.Location
> location,
> String packageName,
> Set<JavaFileObject.Kind> kinds,
> boolean recurse)
> throws IOException {
> Iterable<JavaFileObject> stdList =
> stdFileManager.list(location, packageName, kinds, recurse);
> if (location==CLASS_PATH && packageName.equals("REPL")) {
> // if the desired list is for our JShell package, lazily
> iterate over
> // first the standard list then any generated classes.
> return () -> new Iterator<JavaFileObject>() {
> boolean stdDone = false;
> Iterator<? extends JavaFileObject> it;
>
> @Override
> public boolean hasNext() {
> if (it == null) {
> it = stdList.iterator();
> }
> if (it.hasNext()) {
> return true;
> }
> if (stdDone) {
> return false;
> } else {
> stdDone = true;
> it = generatedClasses().iterator();
> return it.hasNext();
> }
> }
>
> @Override
> public JavaFileObject next() {
> if (!hasNext()) {
> throw new NoSuchElementException();
> }
> return it.next();
> }
>
> };
> } else {
> return stdList;
> }
> }
>
>>
>> - comments: is it normal to repeat all comments from the
>> JavaFileManager interface?
>
> I don't think it is normal.
>
> I've found it very useful to have them there both during
> implementation and maintenance. If you feel they should be removed, I
> will.
>
>>
>> - watch out for unused methods: dumpClasses, findGeneratedClass,
>> findGeneratedBytes, inferModuleName, listModueLocations (maybe this
>> stuff is for Jigsaw? If so, maybe add a comment)
>
> I've added comment (in my local repo).
>
> // For debugging dumps
> dumpClasses
>
> // For restoring process-local execution support
> findGeneratedClass, findGeneratedBytes
> and several others
>
> // Make compatible with Jigsaw
> inferModuleName, listModueLocations
>
> Thanks,
> Robert
>
More information about the kulla-dev
mailing list