use of com.ge.research.osate.verdict.dsl.verdict.Forall in project VERDICT by ge-high-assurance.
the class ThreatModelUtil method getScope.
/**
* Get all variables in scope for an expression.
*
* Searches up the AST for variable introductions, starting from the
* immediate parent of obj.
*
* Note that if scoping a quantification, you cannot pass the object
* directly because this might include the newly-introduced variable
* in its own scope! See getContainerForClasses() for obtaining the
* correct parent to use for scoping.
*
* @param obj the context for which to find scope.
* @param indexProvider the index provider, may be obtained from Guice
* @return the list of variables that are in scope
*/
public static List<VerdictVariable> getScope(EObject obj, ResourceDescriptionsProvider indexProvider) {
// Get type information
LinkedHashMap<String, VerdictType> types = getTypes(obj, indexProvider);
List<VerdictVariable> vars = new ArrayList<>();
// Traverse upward until we find the enclosing threat model
while (!(obj instanceof ThreatModel || obj == null)) {
obj = obj.eContainer();
if (obj instanceof ThreatModel) {
// Threat model introduces a system
ThreatModel threatModel = (ThreatModel) obj;
vars.add(VerdictVariableImpl.fromIntro(threatModel.getIntro(), types));
} else if (obj instanceof Forall) {
// Forall introduces a variable
Forall forall = (Forall) obj;
vars.add(VerdictVariableImpl.fromIntro(forall.getIntro(), types));
} else if (obj instanceof Exists) {
// Exists introduces a variable
Exists exists = (Exists) obj;
vars.add(VerdictVariableImpl.fromIntro(exists.getIntro(), types));
}
}
return vars;
}
Aggregations