Exemple #1
0
  private static PrecedenceUtil.Precedence getPriority(SNode expression) {
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0xfbdeb6fecfL,
            "jetbrains.mps.baseLanguage.structure.BinaryOperation"))) {
      switch (BehaviorReflection.invokeVirtualStatic(
          Integer.TYPE,
          SNodeOperations.asSConcept(
              SNodeOperations.castConcept(
                  expression,
                  MetaAdapterFactory.getConcept(
                      0xf3061a5392264cc5L,
                      0xa443f952ceaf5816L,
                      0xfbdeb6fecfL,
                      "jetbrains.mps.baseLanguage.structure.BinaryOperation"))),
          "virtual_getPriority_1262430001741497858",
          new Object[] {})) {
        case 2:
          // ||
          return PrecedenceUtil.Precedence.J_13;
        case 3:
          // &&
          return PrecedenceUtil.Precedence.J_12;
        case 4:
          // |
          return PrecedenceUtil.Precedence.J_11;
        case 5:
          // ^
          return PrecedenceUtil.Precedence.J_10;
        case 6:
          // &
          return PrecedenceUtil.Precedence.J_9;
        case 7:
          // ==, !=
          return PrecedenceUtil.Precedence.J_8;
        case 8:
          // <, <=, >, >=
          return PrecedenceUtil.Precedence.J_7;
        case 9:
          // >>, <<
          return PrecedenceUtil.Precedence.J_6;
        case 10:
          // +, -
          return PrecedenceUtil.Precedence.J_5;
        case 11:
          // *, /, %
          return PrecedenceUtil.Precedence.J_4;
        default:
      }
    }

    // TODO: not sure concerning ParenthesizedExpression priorities..
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0xfb4ed32b7fL,
            "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression"))) {
      return PrecedenceUtil.Precedence.PARENTHESES;
    }
    // TODO: m.b. we should make "Default" precenence higher then all the user extensions
    // TODO: will be recognized as high-priority expressions
    if (SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x11126b40c25L,
                "jetbrains.mps.baseLanguage.structure.ArrayAccessExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getInterfaceConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x11857355952L,
                "jetbrains.mps.baseLanguage.structure.IMethodCall"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xf8c77f1e98L,
                "jetbrains.mps.baseLanguage.structure.VariableReference"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x515d7a8d927e9fb3L,
                "jetbrains.mps.baseLanguage.structure.LocalPropertyReference"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0x8388864671ce4f1cL,
                0x9c53c54016f6ad4fL,
                0x116ea555a25L,
                "jetbrains.mps.baseLanguage.collections.structure.MapElement"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0x8388864671ce4f1cL,
                0x9c53c54016f6ad4fL,
                0x11d6213c318L,
                "jetbrains.mps.baseLanguage.collections.structure.ListElementAccessExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0x7866978ea0f04cc7L,
                0x81bc4d213d9375e1L,
                0x10975850da7L,
                "jetbrains.mps.lang.smodel.structure.SNodeTypeCastExpression"))) {
      return PrecedenceUtil.Precedence.ARRAY_OPARATIONS_AND_METHOD_CALLS;
    }
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0x116b46a08c4L,
            "jetbrains.mps.baseLanguage.structure.DotExpression"))) {
      return PrecedenceUtil.Precedence.DOT_EXPRESSION;
    }
    if (SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x11adecdb4f0L,
                "jetbrains.mps.baseLanguage.structure.PostfixIncrementExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x11aded05fe6L,
                "jetbrains.mps.baseLanguage.structure.PostfixDecrementExpression"))) {
      return PrecedenceUtil.Precedence.POSTFIX_EXPRESSIONS;
    }
    if (SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x120a46df580L,
                "jetbrains.mps.baseLanguage.structure.PrefixIncrementExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x120a472f0e8L,
                "jetbrains.mps.baseLanguage.structure.PrefixDecrementExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x6fea7de6103549b1L,
                "jetbrains.mps.baseLanguage.structure.UnaryMinus"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xfbcf6bd10dL,
                "jetbrains.mps.baseLanguage.structure.NotExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x11d6d026f5fL,
                "jetbrains.mps.baseLanguage.structure.BitwiseNotExpression"))) {
      return PrecedenceUtil.Precedence.J_2;
    }
    if (SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0xf940dabe4aL,
                "jetbrains.mps.baseLanguage.structure.CastExpression"))
        || SConceptOperations.isSubConceptOf(
            SNodeOperations.asSConcept(expression),
            MetaAdapterFactory.getConcept(
                0xf3061a5392264cc5L,
                0xa443f952ceaf5816L,
                0x10ab8473cc5L,
                "jetbrains.mps.baseLanguage.structure.GenericNewExpression"))) {
      return PrecedenceUtil.Precedence.J_3;
    }
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0xfbbff03700L,
            "jetbrains.mps.baseLanguage.structure.InstanceOfExpression"))) {
      return PrecedenceUtil.Precedence.J_7;
    }
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0x10ef01239c9L,
            "jetbrains.mps.baseLanguage.structure.TernaryOperatorExpression"))) {
      return PrecedenceUtil.Precedence.J_14;
    }
    if (SConceptOperations.isSubConceptOf(
        SNodeOperations.asSConcept(expression),
        MetaAdapterFactory.getConcept(
            0xf3061a5392264cc5L,
            0xa443f952ceaf5816L,
            0x11b0d00332cL,
            "jetbrains.mps.baseLanguage.structure.BaseAssignmentExpression"))) {
      return PrecedenceUtil.Precedence.J_15;
    }
    return PrecedenceUtil.Precedence.DEFAULT;
  }
Exemple #2
0
 @NotNull
 public static SNode getTargetForLeftTransform(
     @NotNull SNode contextNode, @NotNull SNode resultNode) {
   int resultingExpressionPriority =
       getPriority(SNodeOperations.getConceptDeclaration(resultNode)).ordinal();
   SNode targetNode = contextNode;
   for (SNode parentNode = SNodeOperations.getParent(targetNode);
       parentNode != null
           && SNodeOperations.isInstanceOf(
               parentNode,
               MetaAdapterFactory.getConcept(
                   0xf3061a5392264cc5L,
                   0xa443f952ceaf5816L,
                   0xf8c37f506fL,
                   "jetbrains.mps.baseLanguage.structure.Expression"))
           && getPriority(
                       SNodeOperations.castConcept(
                           SNodeOperations.getConceptDeclaration(parentNode),
                           MetaAdapterFactory.getConcept(
                               0xf3061a5392264cc5L,
                               0xa443f952ceaf5816L,
                               0xf8c37f506fL,
                               "jetbrains.mps.baseLanguage.structure.Expression")))
                   .ordinal()
               < resultingExpressionPriority;
       parentNode = SNodeOperations.getParent(targetNode)) {
     if (SNodeOperations.isInstanceOf(
             parentNode,
             MetaAdapterFactory.getInterfaceConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0x11857355952L,
                 "jetbrains.mps.baseLanguage.structure.IMethodCall"))
         || SNodeOperations.isInstanceOf(
             parentNode,
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xfb4ed32b7fL,
                 "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression"))) {
       // if parent expression is IMethodCall then targetNode is either actualArgument
       // or typeArgument (parameters of method call), so we should not go upper
       // same with ParenthesizedExpression
       break;
     }
     if (SNodeOperations.isInstanceOf(
             parentNode,
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xfbdeb6fecfL,
                 "jetbrains.mps.baseLanguage.structure.BinaryOperation"))
         && SNodeOperations.getContainingLinkDeclaration(targetNode)
             == SLinkOperations.findLinkDeclaration(
                 MetaAdapterFactory.getContainmentLink(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xfbdeb6fecfL,
                     0xfbdeb7a11bL,
                     "rightExpression"))) {
       // if parent expression is BinaryOperation having higher priority and target is rhigh child
       // of it
       // then we should rather transform current target and add additional parenthesis around
       // resulting expression
       break;
     }
     targetNode =
         SNodeOperations.cast(
             parentNode,
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xf8c37f506fL,
                 "jetbrains.mps.baseLanguage.structure.Expression"));
   }
   return targetNode;
 }