Esempio n. 1
0
 public static SNode processLeftTransform(SNode sourceNode, SNode result) {
   SNode nodeToProcess = PrecedenceUtil.getTargetForLeftTransform(sourceNode, result);
   // since BinaryOperations are left-associative we should perform complex LT then
   // BinaryOperations is "rightExpression" child of another BinaryOperations with same priority
   if (SNodeOperations.isInstanceOf(
           SNodeOperations.getParent(nodeToProcess),
           MetaAdapterFactory.getConcept(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfbdeb6fecfL,
               "jetbrains.mps.baseLanguage.structure.BinaryOperation"))
       && SNodeOperations.getContainingLinkDeclaration(nodeToProcess)
           == SLinkOperations.findLinkDeclaration(
               MetaAdapterFactory.getContainmentLink(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xfbdeb6fecfL,
                   0xfbdeb7a11bL,
                   "rightExpression"))) {
     SNode parentBinaryOperation =
         SNodeOperations.cast(
             SNodeOperations.getParent(nodeToProcess),
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xfbdeb6fecfL,
                 "jetbrains.mps.baseLanguage.structure.BinaryOperation"));
     if (PrecedenceUtil.isSamePriority(parentBinaryOperation, result)) {
       SNodeOperations.replaceWithAnother(parentBinaryOperation, result);
       // <node>
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfbdeb6fecfL,
               0xfbdeb7a11bL,
               "rightExpression"),
           nodeToProcess);
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfbdeb6fecfL,
               0xfbdeb7a11cL,
               "leftExpression"),
           parentBinaryOperation);
       return result;
     }
   }
   SNodeOperations.replaceWithAnother(nodeToProcess, result);
   SLinkOperations.setTarget(
       result,
       MetaAdapterFactory.getContainmentLink(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0xfbdeb6fecfL,
           0xfbdeb7a11bL,
           "rightExpression"),
       nodeToProcess);
   PrecedenceUtil.parenthesiseIfNecessary(result);
   return result;
 }
Esempio n. 2
0
 public static boolean needsParensAroundNotExpression(SNode notExpression) {
   return !(((SLinkOperations.getTarget(
               notExpression,
               MetaAdapterFactory.getContainmentLink(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xfbcf6bd10dL,
                   0xfbcf6c30a4L,
                   "expression"))
           == null)
       || BehaviorReflection.invokeVirtual(
           Boolean.TYPE,
           SLinkOperations.getTarget(
               notExpression,
               MetaAdapterFactory.getContainmentLink(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xfbcf6bd10dL,
                   0xfbcf6c30a4L,
                   "expression")),
           "virtual_isCompileTimeConstant_1238860258777",
           new Object[] {})
       || (!(SNodeOperations.isInstanceOf(
               SLinkOperations.getTarget(
                   notExpression,
                   MetaAdapterFactory.getContainmentLink(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfbcf6bd10dL,
                       0xfbcf6c30a4L,
                       "expression")),
               MetaAdapterFactory.getConcept(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0x10ef01239c9L,
                   "jetbrains.mps.baseLanguage.structure.TernaryOperatorExpression")))
           && !(SNodeOperations.isInstanceOf(
               SLinkOperations.getTarget(
                   notExpression,
                   MetaAdapterFactory.getContainmentLink(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfbcf6bd10dL,
                       0xfbcf6c30a4L,
                       "expression")),
               MetaAdapterFactory.getConcept(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xfbdeb6fecfL,
                   "jetbrains.mps.baseLanguage.structure.BinaryOperation"))))
       || PrecedenceUtil.isHigherPriority(
           SLinkOperations.getTarget(
               notExpression,
               MetaAdapterFactory.getContainmentLink(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xfbcf6bd10dL,
                   0xfbcf6c30a4L,
                   "expression")),
           notExpression)));
 }
Esempio n. 3
0
  public static SNode findDesiredInstanceOfExpressionRoot(SNode instanceOfExpression) {

    if ((SLinkOperations.getTarget(
                instanceOfExpression,
                MetaAdapterFactory.getContainmentLink(
                    0xf3061a5392264cc5L,
                    0xa443f952ceaf5816L,
                    0xfbbff03700L,
                    0xfbbff06218L,
                    "leftExpression"))
            == null)
        || (SNodeOperations.getParent(instanceOfExpression) == null)
        || !(SNodeOperations.isInstanceOf(
            SNodeOperations.getParent(instanceOfExpression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xfbdeb6fecfL,
                "jetbrains.mps.baseLanguage.structure.BinaryOperation")))
        || !(SNodeOperations.hasRole(
            instanceOfExpression,
            MetaAdapterFactory.getContainmentLink(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xfbdeb6fecfL,
                0xfbdeb7a11bL,
                "rightExpression")))
        || !(PrecedenceUtil.isHigherPriority(
            SNodeOperations.cast(
                SNodeOperations.getParent(instanceOfExpression),
                MetaAdapterFactory.getConcept(
                    0xf3061a5392264cc5L,
                    0xa443f952ceaf5816L,
                    0xf8c37f506fL,
                    "jetbrains.mps.baseLanguage.structure.Expression")),
            instanceOfExpression))) {
      return null;
    }
    SNode currentParent =
        SNodeOperations.cast(
            SNodeOperations.getParent(instanceOfExpression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xf8c37f506fL,
                "jetbrains.mps.baseLanguage.structure.Expression"));

    while ((SNodeOperations.getParent(currentParent) != null)
        && SNodeOperations.isInstanceOf(
            SNodeOperations.getParent(currentParent),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xfbdeb6fecfL,
                "jetbrains.mps.baseLanguage.structure.BinaryOperation"))
        && SNodeOperations.hasRole(
            currentParent,
            MetaAdapterFactory.getContainmentLink(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xfbdeb6fecfL,
                0xfbdeb7a11bL,
                "rightExpression"))
        && PrecedenceUtil.isHigherPriority(
            SNodeOperations.cast(
                SNodeOperations.getParent(currentParent),
                MetaAdapterFactory.getConcept(
                    0xf3061a5392264cc5L,
                    0xa443f952ceaf5816L,
                    0xf8c37f506fL,
                    "jetbrains.mps.baseLanguage.structure.Expression")),
            instanceOfExpression)) {
      currentParent =
          SNodeOperations.cast(
              SNodeOperations.getParent(currentParent),
              MetaAdapterFactory.getConcept(
                  0xf3061a5392264cc5L,
                  0xa443f952ceaf5816L,
                  0xf8c37f506fL,
                  "jetbrains.mps.baseLanguage.structure.Expression"));
    }
    return currentParent;
  }
Esempio n. 4
0
 public static SNode parenthesiseIfNecessary(@NotNull SNode contextNode) {
   if (SNodeOperations.isInstanceOf(
       SNodeOperations.getParent(contextNode),
       MetaAdapterFactory.getConcept(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0xfbdeb6fecfL,
           "jetbrains.mps.baseLanguage.structure.BinaryOperation"))) {
     SNode parentBinaryOperation =
         SNodeOperations.cast(
             SNodeOperations.getParent(contextNode),
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xfbdeb6fecfL,
                 "jetbrains.mps.baseLanguage.structure.BinaryOperation"));
     if (SNodeOperations.getContainingLinkDeclaration(contextNode)
             == SLinkOperations.findLinkDeclaration(
                 MetaAdapterFactory.getContainmentLink(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xfbdeb6fecfL,
                     0xfbdeb7a11bL,
                     "rightExpression"))
         && isHigherPriority(parentBinaryOperation, contextNode)) {
       SNode result =
           SNodeFactoryOperations.replaceWithNewChild(
               contextNode,
               SNodeFactoryOperations.asInstanceConcept(
                   MetaAdapterFactory.getConcept(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfb4ed32b7fL,
                       "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression")));
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfb4ed32b7fL,
               0xfb4ed32b80L,
               "expression"),
           contextNode);
       return result;
     }
   } else if (SNodeOperations.isInstanceOf(
       SNodeOperations.getParent(contextNode),
       MetaAdapterFactory.getConcept(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0xf940dabe4aL,
           "jetbrains.mps.baseLanguage.structure.CastExpression"))) {
     SNode parentCastExpression =
         SNodeOperations.cast(
             SNodeOperations.getParent(contextNode),
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xf940dabe4aL,
                 "jetbrains.mps.baseLanguage.structure.CastExpression"));
     if (PrecedenceUtil.needsParensAroundCastExpression(parentCastExpression)) {
       SNode result =
           SNodeFactoryOperations.replaceWithNewChild(
               contextNode,
               SNodeFactoryOperations.asInstanceConcept(
                   MetaAdapterFactory.getConcept(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfb4ed32b7fL,
                       "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression")));
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfb4ed32b7fL,
               0xfb4ed32b80L,
               "expression"),
           contextNode);
       return result;
     }
   }
   return contextNode;
 }