use of org.lflang.lf.ImportedReactor in project lingua-franca by lf-lang.
the class LFScopeProviderImpl method getScopeForReactorDecl.
/**
* @param obj Instantiation or Reactor that has a ReactorDecl to resolve.
* @param reference The reference to link to a ReactorDecl node.
*/
protected IScope getScopeForReactorDecl(EObject obj, EReference reference) {
// Find the local Model
Model model = null;
EObject container = obj;
while (model == null && container != null) {
container = container.eContainer();
if (container instanceof Model) {
model = (Model) container;
}
}
if (model == null) {
return Scopes.scopeFor(emptyList());
}
// Collect eligible candidates, all of which are local (i.e., not in other files).
var locals = new ArrayList<ReactorDecl>(model.getReactors());
// or directly to the reactor definition.
for (Import it : model.getImports()) {
for (ImportedReactor ir : it.getReactorClasses()) {
if (ir.getName() != null) {
locals.add(ir);
} else if (ir.getReactorClass() != null) {
locals.add(ir.getReactorClass());
}
}
}
return Scopes.scopeFor(locals);
}
use of org.lflang.lf.ImportedReactor in project lingua-franca by lf-lang.
the class LFValidator method isUnused.
/**
* Report whether a given imported reactor is used in this resource or not.
* @param reactor The imported reactor to check whether it is used.
*/
private boolean isUnused(ImportedReactor reactor) {
TreeIterator<EObject> instantiations = reactor.eResource().getAllContents();
TreeIterator<EObject> subclasses = reactor.eResource().getAllContents();
boolean instantiationsCheck = true;
while (instantiations.hasNext() && instantiationsCheck) {
EObject obj = instantiations.next();
if (!(obj instanceof Instantiation)) {
continue;
}
Instantiation inst = (Instantiation) obj;
instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass());
}
boolean subclassesCheck = true;
while (subclasses.hasNext() && subclassesCheck) {
EObject obj = subclasses.next();
if (!(obj instanceof Reactor)) {
continue;
}
Reactor subclass = (Reactor) obj;
for (ReactorDecl decl : subclass.getSuperClasses()) {
subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass());
}
}
return instantiationsCheck && subclassesCheck;
}
Aggregations