All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aya.concrete.resolve.module.CachedModuleLoader Maven / Gradle / Ivy

There is a newer version: 0.33.0
Show newest version
// Copyright (c) 2020-2021 Yinsen (Tesla) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.module;

import kala.collection.immutable.ImmutableSeq;
import kala.collection.mutable.MutableMap;
import kala.collection.mutable.MutableTreeMap;
import org.aya.api.error.Reporter;
import org.aya.concrete.resolve.ResolveInfo;
import org.aya.concrete.stmt.QualifiedID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author re-xyr
 */
public class CachedModuleLoader implements ModuleLoader {
  private final @NotNull MutableMap<@NotNull String, ResolveInfo> cache = MutableTreeMap.of();
  public final @NotNull ML loader;

  @Override public @NotNull Reporter reporter() {
    return loader.reporter();
  }

  public CachedModuleLoader(@NotNull ML loader) {
    this.loader = loader;
  }

  @Override public @Nullable ResolveInfo
  load(@NotNull ImmutableSeq path, @NotNull ModuleLoader recurseLoader) {
    var qualified = QualifiedID.join(path);
    return cache.getOrPut(qualified, () -> loader.load(path, recurseLoader));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy