![JAR search and dependency download from the Maven repository](/logo.png)
org.snapscript.tree.constraint.ArrayConstraint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.constraint;
import org.snapscript.core.Context;
import org.snapscript.core.Evaluation;
import org.snapscript.core.Module;
import org.snapscript.core.Scope;
import org.snapscript.core.Type;
import org.snapscript.core.TypeLoader;
import org.snapscript.core.Value;
import org.snapscript.core.ValueType;
import org.snapscript.parse.StringToken;
import org.snapscript.tree.reference.TypeReference;
public class ArrayConstraint implements Evaluation {
private final TypeReference reference;
private final StringToken[] bounds;
public ArrayConstraint(TypeReference reference, StringToken... bounds) {
this.reference = reference;
this.bounds = bounds;
}
@Override
public Value evaluate(Scope scope, Object left) throws Exception {
Value value = reference.evaluate(scope, null);
Type entry = value.getValue();
Type array = create(scope, entry);
return ValueType.getTransient(array);
}
private Type create(Scope scope, Type entry) throws Exception {
Module module = entry.getModule();
Context context = module.getContext();
TypeLoader loader = context.getLoader();
String prefix = module.getName();
String name = entry.getName();
return loader.resolveType(prefix, name, bounds.length);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy