org.snapscript.tree.constraint.GenericParameterExtractor 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.constraint;
import static org.snapscript.core.scope.index.CaptureType.GENERICS;
import java.util.List;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.scope.index.CaptureScopeExtractor;
import org.snapscript.core.scope.index.Table;
public class GenericParameterExtractor {
private final CaptureScopeExtractor extractor;
private final GenericList generics;
public GenericParameterExtractor(GenericList generics) {
this.extractor = new CaptureScopeExtractor(GENERICS);
this.generics = generics;
}
public Scope extract(Scope local) throws Exception {
List constraints = generics.getGenerics(local);
Scope scope = extractor.extract(local);
Table table = scope.getTable();
int size = constraints.size();
for(int i = 0; i < size; i++) {
Constraint constraint = constraints.get(i);
table.addConstraint(i, constraint);
}
return scope;
}
}