Пример #1
0
 private boolean canExecute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   if (ListSequence.fromList(selectedNodes).count() != 1) {
     return false;
   }
   if (SNodeOperations.getAncestorWhereConceptInList(
           node,
           new String[] {
             "jetbrains.mps.lang.generator.structure.TemplateDeclaration",
             "jetbrains.mps.lang.generator.structure.InlineTemplateWithContext_RuleConsequence"
           },
           false,
           false)
       == null) {
     return false;
   }
   if (ListSequence.fromList(SNodeOperations.getAncestors(node, null, false))
       .where(
           new IWhereFilter<SNode>() {
             public boolean accept(SNode it) {
               return SNodeOperations.isAttribute(it);
             }
           })
       .isNotEmpty()) {
     return false;
   }
   if (QueriesUtil.isInsideTemplateFragment(node)) {
     return false;
   }
   return true;
 }
Пример #2
0
  private void _populateLocalVariablesFromList(
      SNode statementList, SNode beforeStatement, List<SNode> result) {
    for (SNode sNode :
        BehaviorReflection.invokeVirtual(
            (Class<List<SNode>>) ((Class) Object.class),
            statementList,
            "virtual_getLocalVariableElements_1238805763253",
            new Object[] {})) {
      // todo: bad code =(
      if (ListSequence.fromList(SNodeOperations.getAncestors(beforeStatement, null, false))
          .contains(sNode)) {
        break;
      }

      if (sNode == beforeStatement) {
        break;
      }
      if (!(SNodeOperations.isInstanceOf(
          sNode, "jetbrains.mps.baseLanguage.structure.ILocalVariableElement"))) {
        continue;
      }
      SNode declNode =
          BehaviorReflection.invokeVirtual(
              (Class<SNode>) ((Class) Object.class),
              sNode,
              "virtual_getLocalVariableDeclaration_1238803857389",
              new Object[] {});
      if (declNode != null) {
        result.add(declNode);
      }
    }
  }
Пример #3
0
 public static SNode getContextForInnerClass(
     TemplateQueryContext genContext, SNode node, boolean topmost) {
   SNode usage =
       genContext.getOutputNodeByInputNodeAndMappingLabel(
           SLinkOperations.getTarget(node, "inner", true), "classUsageExpr");
   if ((usage != null)) {
     if (SPropertyOperations.getBoolean(node, "nonStatic")) {
       return SNodeOperations.getAncestor(
           usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false);
     }
     if (topmost) {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false))
           .last();
     } else {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return BehaviorReflection.invokeVirtual(
                       Boolean.TYPE, it, "virtual_isStatic_7405920559687241224", new Object[] {});
                 }
               })
           .first();
     }
   } else {
     SNode outclass =
         genContext.getCopiedOutputNodeForInputNode(
             SNodeOperations.getAncestor(
                 node, "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false));
     if ((outclass != null)) {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   outclass, "jetbrains.mps.baseLanguage.structure.ClassConcept", true))
           .last();
     }
   }
   return null;
 }
    public List<?> createParameterObjects(
        SNode node, IOperationContext operationContext, EditorContext editorContext) {
      return ListSequence.fromList(
              SNodeOperations.getAncestors(
                  node, "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement", false))
          .translate(
              new ITranslator2<SNode, String>() {
                public Iterable<String> translate(final SNode it) {
                  return new Iterable<String>() {
                    public Iterator<String> iterator() {
                      return new YieldingIterator<String>() {
                        private int __CP__ = 0;

                        protected boolean moveToNext() {
                          __loop__:
                          do {
                            __switch__:
                            switch (this.__CP__) {
                              case -1:
                                assert false : "Internal error";
                                return false;
                              case 2:
                                if (!(SPropertyOperations.hasValue(it, "label", null))) {
                                  this.__CP__ = 3;
                                  break;
                                }
                                this.__CP__ = 1;
                                break;
                              case 4:
                                this.__CP__ = 1;
                                this.yield(SPropertyOperations.getString(it, "label"));
                                return true;
                              case 0:
                                this.__CP__ = 2;
                                break;
                              case 3:
                                this.__CP__ = 4;
                                break;
                              default:
                                break __loop__;
                            }
                          } while (true);
                          return false;
                        }
                      };
                    }
                  };
                }
              })
          .toListSequence();
    }
Пример #5
0
 private void runUpdateTask(
     final _FunctionTypes._void_P0_E0 task, SNode currentNode, final SModelEvent event) {
   myEventConsumingMapping.addEvent(event);
   final List<SNodeId> ancestors =
       ListSequence.fromList(SNodeOperations.getAncestors(currentNode, null, true))
           .select(
               new ISelector<SNode, SNodeId>() {
                 public SNodeId select(SNode a) {
                   return a.getNodeId();
                 }
               })
           .toListSequence();
   myQueue.runTask(
       new Runnable() {
         public void run() {
           if (myDifference.getChangeSet() == null) {
             update(true);
           } else {
             if (ListSequence.fromList(ancestors)
                 .any(
                     new IWhereFilter<SNodeId>() {
                       public boolean accept(SNodeId a) {
                         return myAddedNodesToChanges.containsKey(a);
                       }
                     })) {
               // ignore
             } else {
               if (myEventConsumingMapping.removeEvent(event)) {
                 myDifference.getBroadcaster().changeUpdateStarted();
                 ModelAccess.instance()
                     .runReadAction(
                         new Runnable() {
                           public void run() {
                             synchronized (ChangesTracking.this) {
                               if (!(myDisposed)) {
                                 task.invoke();
                               }
                             }
                           }
                         });
                 myDifference.getBroadcaster().changeUpdateFinished();
               }
             }
           }
         }
       });
 }
Пример #6
0
 private void execute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   // do not hang <TF> on other attributes
   SNode applyToNode =
       ListSequence.fromList(SNodeOperations.getAncestors(node, null, true))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return !(SNodeOperations.isAttribute(it));
                 }
               })
           .first();
   QueriesUtil.createTemplateFragment(applyToNode);
 }
Пример #7
0
  public static Scope getClassesForStaticFieldReference(
      @NotNull SNode contextNode, @NotNull IScope scope) {
    final Set<SNode> enclosingClassifierAncestors = SetSequence.fromSet(new HashSet<SNode>());
    SetSequence.fromSet(enclosingClassifierAncestors)
        .addSequence(
            ListSequence.fromList(
                SNodeOperations.getAncestors(
                    contextNode, "jetbrains.mps.baseLanguage.structure.Classifier", false)));

    return new FilteringScope(getVisibleClassifiersScope(contextNode, true)) {
      @Override
      public boolean isExcluded(SNode node) {
        if (SetSequence.fromSet(enclosingClassifierAncestors).contains(node)) {
          return false;
        }

        SNode classifier =
            SNodeOperations.cast(node, "jetbrains.mps.baseLanguage.structure.Classifier");
        if (!(Classifier_Behavior.call_isStatic_521412098689998668(classifier))) {
          return true;
        }

        List<SNode> ancestors = SNodeOperations.getAncestors(classifier, null, true);
        // Filtering out Classifiers located in third-party containers (not Classifiers)
        // and having no common Classifier container with enclosing node.
        // Useful for Classifiers contained in EditorTestCases
        // ("result" should not be able to access classifiers from "nodeToEdit")...
        // todo: VOODOO PEOPLE MAGIC PEOPLE
        return ListSequence.fromList(ancestors)
                .where(
                    new IWhereFilter<SNode>() {
                      public boolean accept(SNode it) {
                        return !(SNodeOperations.isInstanceOf(
                            it, "jetbrains.mps.baseLanguage.structure.Classifier"));
                      }
                    })
                .isNotEmpty()
            && ListSequence.fromList(ancestors)
                .intersect(SetSequence.fromSet(enclosingClassifierAncestors))
                .isEmpty();
      }
    };
  }
Пример #8
0
  public static SNode getEnclosing_TemplateFragment(SNode node) {
    //  find first ancestor (inclusive) which has a template fragment attribute
    Iterable<SNode> TFs =
        ListSequence.fromList(SNodeOperations.getAncestors(node, null, true))
            .translate(
                new ITranslator2<SNode, SNode>() {
                  public Iterable<SNode> translate(final SNode it) {
                    return new Iterable<SNode>() {
                      public Iterator<SNode> iterator() {
                        return new YieldingIterator<SNode>() {
                          private int __CP__ = 0;
                          private SNode _5_TF;

                          protected boolean moveToNext() {
                            __loop__:
                            do {
                              __switch__:
                              switch (this.__CP__) {
                                case -1:
                                  assert false : "Internal error";
                                  return false;
                                case 6:
                                  if (_5_TF != null) {
                                    this.__CP__ = 7;
                                    break;
                                  }
                                  this.__CP__ = 3;
                                  break;
                                case 3:
                                  if (false) {
                                    this.__CP__ = 2;
                                    break;
                                  }
                                  this.__CP__ = 1;
                                  break;
                                case 8:
                                  this.__CP__ = 9;
                                  this.yield(_5_TF);
                                  return true;
                                case 0:
                                  this.__CP__ = 2;
                                  break;
                                case 2:
                                  this._5_TF =
                                      AttributeOperations.getAttribute(
                                          ((SNode) it),
                                          new IAttributeDescriptor.NodeAttribute(
                                              SConceptOperations.findConceptDeclaration(
                                                  "jetbrains.mps.lang.generator.structure.TemplateFragment")));
                                  this.__CP__ = 6;
                                  break;
                                case 7:
                                  this.__CP__ = 8;
                                  break;
                                case 9:
                                  throw new StopIteratingException();
                                default:
                                  break __loop__;
                              }
                            } while (true);
                            return false;
                          }
                        };
                      }
                    };
                  }
                });
    return Sequence.fromIterable(TFs).first();
  }