org.snapscript.tree.reference.GenericDeclaration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.reference;
import java.util.List;
import org.snapscript.core.Evaluation;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.constraint.GenericParameterConstraint;
import org.snapscript.core.module.Path;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.type.Type;
import org.snapscript.core.variable.Value;
public class GenericDeclaration {
private final GenericArgumentList list;
private final Evaluation type;
private final Path path;
private final int line;
public GenericDeclaration(Evaluation type, GenericArgumentList list, Path path, int line) {
this.type = type;
this.list = list;
this.path = path;
this.line = line;
}
public Constraint declare(Scope scope) throws Exception {
try {
Value value = type.evaluate(scope, null);
String name = value.getName(scope);
Type type = value.getValue();
if(list != null) {
List generics = list.create(scope);
if(!generics.isEmpty()) {
return new GenericParameterConstraint(type, generics, name);
}
}
return new GenericParameterConstraint(type, name);
}catch(Exception e) {
throw new InternalStateException("Invalid constraint in " + path + " at line " + line, e);
}
}
}