package jetbrains.mps.make.facet.constraints; /*Generated by MPS */ import jetbrains.mps.lang.scopes.runtime.SimpleScope; import org.jetbrains.mps.openapi.model.SNode; import org.jetbrains.mps.openapi.module.SModule; import jetbrains.mps.module.ReloadableModule; import jetbrains.mps.project.Solution; import jetbrains.mps.project.structure.modules.SolutionKind; import java.util.Set; import jetbrains.mps.internal.collections.runtime.SetSequence; import java.util.HashSet; import jetbrains.mps.internal.collections.runtime.CollectionSequence; import jetbrains.mps.project.dependency.GlobalModuleDependenciesManager; import org.jetbrains.mps.openapi.model.SModel; import jetbrains.mps.internal.collections.runtime.ITranslator2; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.internal.collections.runtime.ISelector; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; import jetbrains.mps.lang.core.behavior.INamedConcept__BehaviorDescriptor; public class FacetsScope extends SimpleScope { public FacetsScope(SNode contextNode) { super(getAvailableFacets(contextNode)); } /** * TODO reorganize facets in the project: we must not look at SolutionKind here * probably it makes sense to declare all facets only in languages */ private static boolean hackCondition(SModule module) { if (module instanceof ReloadableModule) { if (!((module instanceof Solution))) { return true; } return ((Solution) module).getKind() != SolutionKind.NONE; } return false; } public static Iterable<SNode> getAvailableFacets(SNode contextNode) { SModule contextModule = contextNode.getModel().getModule(); Set<SModule> contextModules = SetSequence.fromSet(new HashSet<SModule>()); for (SModule module : CollectionSequence.fromCollection(new GlobalModuleDependenciesManager(contextModule).getModules(GlobalModuleDependenciesManager.Deptype.VISIBLE))) { if (hackCondition(module)) { SetSequence.fromSet(contextModules).addElement(module); } } SetSequence.fromSet(contextModules).addElement(contextModule); // collect models Iterable<SModel> models = SetSequence.fromSet(contextModules).translate(new ITranslator2<SModule, SModel>() { public Iterable<SModel> translate(SModule it) { return it.getModels(); } }); // collect facets Iterable<SNode> facets = Sequence.fromIterable(models).where(new IWhereFilter<SModel>() { public boolean accept(SModel it) { return it != null; } }).translate(new ITranslator2<SModel, SNode>() { public Iterable<SNode> translate(SModel it) { return (Iterable<SNode>) it.getRootNodes(); } }).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return SNodeOperations.isInstanceOf(it, MetaAdapterFactory.getConcept(0x696c11654a59463bL, 0xbc5d902caab85dd0L, 0x5912a2ab1cd24c13L, "jetbrains.mps.make.facet.structure.FacetDeclaration")); } }).select(new ISelector<SNode, SNode>() { public SNode select(SNode it) { return SNodeOperations.cast(it, MetaAdapterFactory.getConcept(0x696c11654a59463bL, 0xbc5d902caab85dd0L, 0x5912a2ab1cd24c13L, "jetbrains.mps.make.facet.structure.FacetDeclaration")); } }); return facets; } @Nullable @Override public String getReferenceText(@NotNull SNode target) { return (String) INamedConcept__BehaviorDescriptor.getFqName_idhEwIO9y.invoke(SNodeOperations.cast(target, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, "jetbrains.mps.lang.structure.structure.AbstractConceptDeclaration"))); } }