Beispiel #1
0
 public static SNode getBinaryOperationType(SNode leftType, SNode rightType, boolean mayBeString) {
   List<SNode> leastCommonSupertypes =
       SubtypingUtil.leastCommonSuperTypes(Arrays.asList(leftType, rightType), null);
   if (mayBeString) {
     SModel javaLangJavaStubModelDescriptor =
         SModelRepository.getInstance()
             .getModelDescriptor(SModelReference.fromString("java.lang@java_stub"));
     assert javaLangJavaStubModelDescriptor != null;
     SModel javaLang = javaLangJavaStubModelDescriptor.getSModel();
     SNode stringClass = SModelOperations.getRootByName(javaLang, "String");
     if (SNodeOperations.isInstanceOf(
                 leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass
         || SNodeOperations.isInstanceOf(
                 rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass) {
       SNode classifierType =
           SConceptOperations.createNewNode(
               "jetbrains.mps.baseLanguage.structure.ClassifierType", null);
       SLinkOperations.setTarget(
           classifierType,
           "classifier",
           SNodeOperations.cast(stringClass, "jetbrains.mps.baseLanguage.structure.Classifier"),
           false);
       return classifierType;
     }
   }
   if (leastCommonSupertypes.isEmpty()) {
     SNode runtimeErrorType =
         SConceptOperations.createNewNode(
             "jetbrains.mps.lang.typesystem.structure.RuntimeErrorType", null);
     SPropertyOperations.set(runtimeErrorType, "errorText", "incompatible types");
     return runtimeErrorType;
   }
   SNode type = leastCommonSupertypes.iterator().next();
   {
     IMatchingPattern pattern_j6k1pf_e0c =
         HUtil.createMatchingPatternByConceptFQName(
             "jetbrains.mps.baseLanguage.structure.PrimitiveType");
     SNode coercedNode_j6k1pf_e0c =
         TypeChecker.getInstance().getRuntimeSupport().coerce_(type, pattern_j6k1pf_e0c);
     if (coercedNode_j6k1pf_e0c != null) {
       return coercedNode_j6k1pf_e0c;
     } else {
       return type;
     }
   }
 }