Search in sources :

Example 1 with ImportedReactor

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);
}
Also used : Import(org.lflang.lf.Import) ImportedReactor(org.lflang.lf.ImportedReactor) EObject(org.eclipse.emf.ecore.EObject) Model(org.lflang.lf.Model) ArrayList(java.util.ArrayList)

Example 2 with ImportedReactor

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Instantiation(org.lflang.lf.Instantiation) ImportedReactor(org.lflang.lf.ImportedReactor) Reactor(org.lflang.lf.Reactor) ReactorDecl(org.lflang.lf.ReactorDecl)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)2 ImportedReactor (org.lflang.lf.ImportedReactor)2 ArrayList (java.util.ArrayList)1 Import (org.lflang.lf.Import)1 Instantiation (org.lflang.lf.Instantiation)1 Model (org.lflang.lf.Model)1 Reactor (org.lflang.lf.Reactor)1 ReactorDecl (org.lflang.lf.ReactorDecl)1