![JAR search and dependency download from the Maven repository](/logo.png)
org.snapscript.tree.reference.ArrayReference 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 org.snapscript.core.Context;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.module.Module;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.type.Type;
import org.snapscript.core.type.TypeLoader;
import org.snapscript.core.variable.Value;
import org.snapscript.parse.StringToken;
public class ArrayReference extends ConstraintReference {
private final TypeReference reference;
private final StringToken[] bounds;
public ArrayReference(TypeReference reference, StringToken... bounds) {
this.reference = reference;
this.bounds = bounds;
}
@Override
protected ConstraintValue create(Scope scope) {
try {
Value value = reference.evaluate(scope, null);
Type entry = value.getValue();
Module module = entry.getModule();
Context context = module.getContext();
TypeLoader loader = context.getLoader();
String prefix = module.getName();
String name = entry.getName();
Type array = loader.resolveArrayType(prefix, name, bounds.length);
Constraint constraint = Constraint.getConstraint(array);
return new ConstraintValue(array, constraint);
} catch(Exception e) {
throw new InternalStateException("Invalid array constraint", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy