package jetbrains.mps.lang.editor.constraints;

/*Generated by MPS */

import jetbrains.mps.smodel.runtime.base.BaseConstraintsDescriptor;
import java.util.Map;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import jetbrains.mps.smodel.runtime.ReferenceConstraintsDescriptor;
import jetbrains.mps.smodel.runtime.base.BaseReferenceConstraintsDescriptor;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.smodel.runtime.ReferenceScopeProvider;
import jetbrains.mps.smodel.runtime.base.BaseScopeProvider;
import org.jetbrains.mps.openapi.model.SNodeReference;
import jetbrains.mps.smodel.SNodePointer;
import jetbrains.mps.scope.Scope;
import jetbrains.mps.smodel.runtime.ReferenceConstraintsContext;
import java.util.List;
import org.jetbrains.mps.openapi.model.SModel;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.module.SRepository;
import jetbrains.mps.smodel.language.LanguageRegistry;
import jetbrains.mps.smodel.ModelDependencyResolver;
import jetbrains.mps.internal.collections.runtime.CollectionSequence;
import org.jetbrains.mps.openapi.language.SLanguage;
import jetbrains.mps.smodel.SLanguageHierarchy;
import org.jetbrains.mps.openapi.module.SModuleReference;
import org.jetbrains.mps.openapi.module.SModule;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SModuleOperations;
import jetbrains.mps.scope.ModelsScope;
import java.util.HashMap;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class AttributeStyleClassItem_Constraints extends BaseConstraintsDescriptor {
  public AttributeStyleClassItem_Constraints() {
    super(CONCEPTS.AttributeStyleClassItem$Ec);
  }

  @Override
  protected Map<SReferenceLink, ReferenceConstraintsDescriptor> getSpecifiedReferences() {
    BaseReferenceConstraintsDescriptor d0 = new BaseReferenceConstraintsDescriptor(LINKS.attribute$PnEb, this, true, false) {
      @Nullable
      @Override
      public ReferenceScopeProvider getScopeProvider() {
        return new BaseScopeProvider() {
          @Override
          public SNodeReference getSearchScopeValidatorNode() {
            return new SNodePointer("r:00000000-0000-4000-0000-011c89590298(jetbrains.mps.lang.editor.constraints)", "6836281137582785604");
          }
          @Override
          public Scope createScope(final ReferenceConstraintsContext _context) {
            List<SModel> models = ListSequence.fromList(new ArrayList<SModel>());
            SModel contextModel = SNodeOperations.getModel(_context.getContextNode());
            ListSequence.fromList(models).addElement(contextModel);
            final SRepository contextRepo = contextModel.getRepository();
            if (contextRepo != null) {
              final LanguageRegistry languageRegistry = LanguageRegistry.getInstance(contextRepo);
              ModelDependencyResolver mdr = new ModelDependencyResolver(languageRegistry, contextRepo);
              ListSequence.fromList(models).addSequence(CollectionSequence.fromCollection(mdr.directImports(contextModel)));
              ListSequence.fromList(models).addSequence(CollectionSequence.fromCollection(mdr.implicitImports(contextModel)));
              for (SLanguage l : new SLanguageHierarchy(languageRegistry, mdr.usedLanguages(contextModel)).getExtended()) {
                SModuleReference sourceModuleRef = l.getSourceModuleReference();
                if (sourceModuleRef == null) {
                  continue;
                }
                SModule sourceLang = sourceModuleRef.resolve(contextRepo);
                if (sourceLang == null) {
                  continue;
                }
                SModel editorAspectModel = SModuleOperations.getAspect(sourceLang, "editor");
                if (editorAspectModel == null) {
                  continue;
                }
                ListSequence.fromList(models).addElement(editorAspectModel);
              }
            }
            return new ModelsScope(models, false, CONCEPTS.StyleAttributeDeclaration$kv);
          }
        };
      }
    };
    Map<SReferenceLink, ReferenceConstraintsDescriptor> references = new HashMap<SReferenceLink, ReferenceConstraintsDescriptor>();
    references.put(d0.getReference(), d0);
    return references;
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept AttributeStyleClassItem$Ec = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x3744c0f9eae0a402L, "jetbrains.mps.lang.editor.structure.AttributeStyleClassItem");
    /*package*/ static final SConcept StyleAttributeDeclaration$kv = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x3744c0f9ea5367ebL, "jetbrains.mps.lang.editor.structure.StyleAttributeDeclaration");
  }

  private static final class LINKS {
    /*package*/ static final SReferenceLink attribute$PnEb = MetaAdapterFactory.getReferenceLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x3744c0f9eae0a402L, 0x3744c0f9eae0b8d3L, "attribute");
  }
}
