ani-lang / anilang-core

Core functionality of Ani language.
Other
1 stars 0 forks source link

move to an interface #149

Open github-actions[bot] opened 1 year ago

github-actions[bot] commented 1 year ago

144

https://github.com/ani-lang/anilang-core/blob/454695ea22d89ffeb43149414a7444541b17a08b/anilang-context/src/main/java/com/anilang/context/impl/ProgramContext.java#L14


/*
 * Property of ani-lang project.
 */

package com.anilang.context.impl;

import com.anilang.context.AniContext;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public final class ProgramContext {
    // TODO move to an interface
    // #144

    private final Map<String, AniContext> map;
    private final Path root;

    public ProgramContext(final Path root) {
        this.root = root;
        map = new HashMap<>();
    }

    public AniContext context(final Path path) throws IOException {
        final String key = this.root.relativize(path).toString();
        if (this.map.containsKey(key)) {
            return this.map.get(key);
        }
        final BaseAniContext context = new BaseAniContext(key);
        this.map.put(key, context);
        return context;
    }

    public Map<String, AniContext> asMap() {
        return this.map;
    }
}