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

me.tomassetti.symbolsolver.model.resolution.SymbolReference Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package me.tomassetti.symbolsolver.model.resolution;

import me.tomassetti.symbolsolver.model.declarations.Declaration;
import me.tomassetti.symbolsolver.model.typesystem.TypeUsage;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author Federico Tomassetti
 */
public class SymbolReference {

    private Optional correspondingDeclaration;
    private Map typeParametersByName = new HashMap<>();

    private SymbolReference(Optional correspondingDeclaration) {
        this.correspondingDeclaration = correspondingDeclaration;
    }

    public static  SymbolReference solved(S2 symbolDeclaration) {
        return new SymbolReference(Optional.of(symbolDeclaration));
    }

    public static  SymbolReference unsolved(Class clazz) {
        return new SymbolReference(Optional.empty());
    }

    @Override
    public String toString() {
        return "SymbolReference{" +
                "correspondingDeclaration=" + correspondingDeclaration +
                '}';
    }

    public S getCorrespondingDeclaration() {
        if (!isSolved()) {
            throw new IllegalStateException();
        }
        return correspondingDeclaration.get();
    }

    public boolean isSolved() {
        return correspondingDeclaration.isPresent();
    }
}