package jetbrains.mps.baseLanguage.scopes; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SNode; import java.util.Map; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.baseLanguage.behavior.Type__BehaviorDescriptor; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; import org.jetbrains.annotations.Nullable; import java.util.Collections; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.internal.collections.runtime.SetSequence; import jetbrains.mps.internal.collections.runtime.ITranslator2; import jetbrains.mps.baseLanguage.behavior.Classifier__BehaviorDescriptor; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import java.util.Set; import org.jetbrains.annotations.NotNull; import jetbrains.mps.extapi.module.TransientSModule; import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes; import jetbrains.mps.internal.collections.runtime.MapSequence; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.HashSet; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import java.util.Iterator; import org.jetbrains.mps.openapi.module.SModule; import org.jetbrains.mps.openapi.model.SModel; public class ClassifierScopeUtils { private ClassifierScopeUtils() { } @Deprecated public static String createMethodParameterTypesString(SNode method, Map<SNode, SNode> typeByTypeVar) { // use MethodSignature instead StringBuilder result = new StringBuilder(); for (SNode parm : SLinkOperations.getChildren(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1feL, "parameter"))) { SNode type = SLinkOperations.getTarget(parm, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type")); type = GenericTypesUtil.getTypeWithResolvedTypeVars(type, typeByTypeVar); if (result.length() > 0) { result.append(','); } if (type != null) { result.append(Type__BehaviorDescriptor.getErasureSignature_idhEwIzNx.invoke(type)); } else { result.append(""); } } return result.toString(); } @Deprecated public static String getMethodSignatureForOverriding(SNode contextClassifier, SNode method) { // use MethodSignature instead return SPropertyOperations.getString(method, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) + "(" + createMethodParameterTypesString(method, resolveClassifierTypeVars(contextClassifier)) + ")"; } public static Map<SNode, SNode> resolveClassifierTypeVars(@Nullable SNode classifier) { if (classifier == null) { return Collections.emptyMap(); } return getClassifierAndSuperClassifiersData(classifier).typeByTypeVariable; } public static Iterable<SNode> getVisibleNestedClassConceptsIncludingInherited(@Nullable SNode type, final SNode contextNode) { Iterable<SNode> visibleInheritedNestedClassifiers = SNodeOperations.ofConcept(SetSequence.fromSet(ClassifierScopeUtils.getExtendedClassifiers(SLinkOperations.getTarget(SNodeOperations.cast(type, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType")), MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier")))).translate(new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(SNode it) { return (Iterable<SNode>) Classifier__BehaviorDescriptor.nestedClassifiers_id4_LVZ3pBjGQ.invoke(it); } }).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return VisibilityUtil.isVisible(contextNode, it); } }), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, "jetbrains.mps.baseLanguage.structure.ClassConcept")); return visibleInheritedNestedClassifiers; } public static Set<SNode> getExtendedClassifiers(@Nullable SNode classifier) { if (classifier == null) { return Collections.emptySet(); } return getClassifierAndSuperClassifiersData(classifier).classifiers; } public static boolean isHierarchyCyclic(@Nullable SNode classifier) { if (classifier == null) { return false; } return getClassifierAndSuperClassifiersData(classifier).isCyclic; } private static ClassifierScopeUtils.ClassifierAndSuperClassifiersData getClassifierAndSuperClassifiersData(@NotNull final SNode classifier) { if (check_uu0vlb_a0a0j(SNodeOperations.getModel(classifier)) instanceof TransientSModule) { return new ClassifierScopeUtils.ClassifierAndSuperClassifiersData(classifier); } else { return RepositoryStateCacheUtils.getFromCache(ClassifierScopeUtils.class, classifier, new _FunctionTypes._return_P0_E0<ClassifierScopeUtils.ClassifierAndSuperClassifiersData>() { public ClassifierScopeUtils.ClassifierAndSuperClassifiersData invoke() { return new ClassifierScopeUtils.ClassifierAndSuperClassifiersData(classifier); } }); } } private static class ClassifierAndSuperClassifiersData { /*package*/ final Set<SNode> classifiers; /*package*/ final Map<SNode, SNode> typeByTypeVariable; /*package*/ final boolean isCyclic; /*package*/ ClassifierAndSuperClassifiersData(SNode topClassifier) { typeByTypeVariable = MapSequence.fromMap(new HashMap<SNode, SNode>()); classifiers = SetSequence.fromSet(new LinkedHashSet<SNode>()); isCyclic = collectImplementedAndExtended(topClassifier, SetSequence.fromSet(new HashSet<SNode>()), null); } /** * * * @param classifier classifier * @param subClassifiers subClassifiers * @param typeParms typeParams * @return is hierarchy cyclic? */ private boolean collectImplementedAndExtended(SNode classifier, Set<SNode> subClassifiers, List<SNode> typeParms) { if (SetSequence.fromSet(subClassifiers).contains(classifier)) { return true; } if ((classifier == null) || SetSequence.fromSet(classifiers).contains(classifier)) { return false; } SetSequence.fromSet(classifiers).addElement(classifier); SetSequence.fromSet(subClassifiers).addElement(classifier); if (ListSequence.fromList(typeParms).isNotEmpty()) { Iterator<SNode> typeVars = ListSequence.fromList(SLinkOperations.getChildren(classifier, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x102463b447aL, 0x102463bb98eL, "typeVariableDeclaration"))).iterator(); for (SNode typeParm : typeParms) { if (!(typeVars.hasNext())) { break; } SNode typeVar = typeVars.next(); MapSequence.fromMap(typeByTypeVariable).put(typeVar, typeParm); } } for (SNode superType : Classifier__BehaviorDescriptor.getExtendedClassifierTypes_id1UeCwxlWKny.invoke(classifier)) { if (collectImplementedAndExtended(SLinkOperations.getTarget(superType, MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier")), subClassifiers, SLinkOperations.getChildren(superType, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x102419671abL, "parameter")))) { return true; } } SetSequence.fromSet(subClassifiers).removeElement(classifier); return false; } } private static SModule check_uu0vlb_a0a0j(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; } }