package jetbrains.mps.kernel.model;
/*Generated by MPS */
import jetbrains.mps.util.annotation.ToRemove;
import jetbrains.mps.smodel.Language;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import java.util.List;
import java.util.Set;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import java.util.LinkedHashSet;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.search.ConceptAndSuperConceptsScope;
import java.util.ArrayList;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.util.IterableUtil;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import org.jetbrains.mps.openapi.language.SEnumerationLiteral;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SEnumOperations;
import jetbrains.mps.smodel.adapter.MetaAdapterByDeclaration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.module.SModule;
import org.jetbrains.mps.openapi.model.SModel;
/**
*
* @deprecated use S-entities instead
*/
@Deprecated
@ToRemove(version = 3.5)
public class SModelUtil {
public static Language getDeclaringLanguage(final SNode concept) {
if (concept == null) {
return null;
}
return as_74see4_a0b0a(check_74see4_a0b0a(concept.getModel()), Language.class);
}
public static SNode getGenuineLinkDeclaration(SNode linkDeclaration) {
while (linkDeclaration != null && SLinkOperations.getTarget(linkDeclaration, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98051c244L, "specializedLink")) != null) {
linkDeclaration = SLinkOperations.getTarget(linkDeclaration, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98051c244L, "specializedLink"));
}
return linkDeclaration;
}
public static String getGenuineLinkRole(SNode linkDecl) {
SNode genLinkDecl = getGenuineLinkDeclaration(linkDecl);
if (genLinkDecl == null) {
return null;
}
return SPropertyOperations.getString(genLinkDecl, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role"));
}
public static List<SNode> getDirectSuperInterfacesAndTheirSupers(SNode concept) {
Set<SNode> result = SetSequence.fromSet(new LinkedHashSet<SNode>());
for (SNode superConcept : ListSequence.fromList(getDirectSuperConcepts(concept))) {
if (SNodeOperations.isInstanceOf(superConcept, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration")) && !(SetSequence.fromSet(result).contains(superConcept))) {
for (SNode node : ListSequence.fromList(new ConceptAndSuperConceptsScope(superConcept).getConcepts())) {
SetSequence.fromSet(result).addElement((SNode) node);
}
}
}
return ListSequence.fromListWithValues(new ArrayList<SNode>(), result);
}
@Deprecated
public static List<SNode> getDirectSuperConcepts(SNode concept) {
List<SNode> result = ListSequence.fromList(new ArrayList<SNode>());
if (SNodeOperations.isInstanceOf(concept, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, "jetbrains.mps.lang.structure.structure.ConceptDeclaration"))) {
SNode conceptDecl = (SNode) concept;
SNode extended = SLinkOperations.getTarget(conceptDecl, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0xf979be93cfL, "extends"));
if (extended != null) {
ListSequence.fromList(result).addElement(extended);
}
for (SNode ref : ListSequence.fromList(SLinkOperations.getChildren(conceptDecl, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0x110358d693eL, "implements")))) {
if (SLinkOperations.getTarget(ref, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x110356fc618L, 0x110356fe029L, "intfc")) != null) {
ListSequence.fromList(result).addElement(SLinkOperations.getTarget(ref, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x110356fc618L, 0x110356fe029L, "intfc")));
}
}
} else {
SNode intConceptDecl = (SNode) concept;
for (SNode ref : ListSequence.fromList(SLinkOperations.getChildren(intConceptDecl, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, 0x110356e9df4L, "extends")))) {
if (SLinkOperations.getTarget(ref, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x110356fc618L, 0x110356fe029L, "intfc")) != null) {
ListSequence.fromList(result).addElement(SLinkOperations.getTarget(ref, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x110356fc618L, 0x110356fe029L, "intfc")));
}
}
}
return result;
}
public static List<SAbstractConcept> getDirectSuperConcepts(SAbstractConcept concept) {
List<SAbstractConcept> result = new ArrayList<SAbstractConcept>();
if (concept instanceof SConcept) {
SConcept superConcept = ((SConcept) concept).getSuperConcept();
if (superConcept != null) {
result.add(superConcept);
}
result.addAll(IterableUtil.asCollection(((SConcept) concept).getSuperInterfaces()));
}
if (concept instanceof SInterfaceConcept) {
result.addAll(IterableUtil.asCollection(((SInterfaceConcept) concept).getSuperInterfaces()));
}
return result;
}
public static List<SAbstractConcept> getConceptAndAllSuperConcepts(SAbstractConcept concept) {
Set<SAbstractConcept> resultSet = new LinkedHashSet<SAbstractConcept>();
Set<SAbstractConcept> frontier = new LinkedHashSet<SAbstractConcept>();
frontier.add(concept);
while (resultSet.addAll(frontier)) {
Set<SAbstractConcept> newFrontier = new LinkedHashSet<SAbstractConcept>();
for (SAbstractConcept elem : SetSequence.fromSet(frontier)) {
newFrontier.addAll(getDirectSuperConcepts(elem));
}
frontier = newFrontier;
}
List<SAbstractConcept> result = new ArrayList<SAbstractConcept>(resultSet);
return result;
}
public static SEnumerationLiteral getGenuineLinkSourceCardinality(SNode linkDecl) {
return SEnumOperations.getMemberForValue(SPropertyOperations.getString_def(getGenuineLinkDeclaration(linkDecl), MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98054bb04L, "sourceCardinality"), "0..1"), 0xc72da2b97cce4447L, 0x8389f407dc1158b7L, "jetbrains.mps.lang.structure", 0xfc6f3944c2L, "Cardinality");
}
public static boolean isAcceptableTarget(SNode linkDeclaration, SNode referentNode) {
SAbstractConcept targetConcept = MetaAdapterByDeclaration.getConcept(SLinkOperations.getTarget(linkDeclaration, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98055fef0L, "target")));
return referentNode.getConcept().isSubConceptOf(targetConcept);
}
public static boolean isMultipleLinkDeclaration(@NotNull SNode linkDeclaration) {
return SPropertyOperations.hasValue(linkDeclaration, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98054bb04L, "sourceCardinality"), "0..n", "0..1") || SPropertyOperations.hasValue(linkDeclaration, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98054bb04L, "sourceCardinality"), "1..n", "0..1");
}
public static boolean isAggregation(@NotNull SNode linkDeclaration) {
return SPropertyOperations.hasValue(linkDeclaration, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf980556927L, "metaClass"), "aggregation", "reference");
}
public static SNode getLinkDeclarationTarget(SNode linkDeclaration) {
return SLinkOperations.getTarget(linkDeclaration, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98055fef0L, "target"));
}
public static SNode getLinkDeclarationSpecializedLink(SNode link) {
return SLinkOperations.getTarget(link, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98051c244L, "specializedLink"));
}
public static String getLinkDeclarationRole(SNode link) {
return SPropertyOperations.getString(link, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role"));
}
private static SModule check_74see4_a0b0a(SModel checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getModule();
}
return null;
}
private static <T> T as_74see4_a0b0a(Object o, Class<T> type) {
return (type.isInstance(o) ? (T) o : null);
}
}